Comment 1 for bug 1227035

Revision history for this message
Julian Edwards (julian-edwards) wrote :

Gavin suggested that we need to handle yaml escaping properly in templates:

-----

We could/ought to add the following escape function to the templates:

    from StringIO import StringIO
    import yaml

    def quote_yaml(thing):
        buf = StringIO()
        dumper = yaml.SafeDumper(buf, encoding=None)
        try:
            dumper.open()
            if isinstance(thing, unicode):
                # Force double-quote style for unicode strings.
                dumper.write_double_quoted(string)
            else:
                dumper.represent(thing)
            dumper.close()
        finally:
            dumper.dispose()
        return buf.getvalue()