def dump_yaml(data):
     import io
     from yaml import Dumper
     stream = io.StringIO()
     dumper = Dumper(stream)
     try:
         dumper.open()
         dumper.represent(data)
         dumper.close()
     finally:
         dumper.dispose()
     return stream.getvalue()
def print_yaml(disasm, stream=sys.stdout):
    from yaml import Dumper
    dumper = Dumper(stream)

    # Force a Git-friendly output format:
    # https://stackoverflow.com/a/8641732
    def strdump(dumper, data):
        return dumper.represent_scalar('tag:yaml.org,2002:str',
                                       data,
                                       style='|')

    dumper.add_representer(str, strdump)

    dumper.open()
    dumper.represent(disasm)
    dumper.close()