def generate_string(converter, input, format = 'xml'): """ Like generate(), but reads the input from a string instead of from a file. @type converter: compiler.Context @param converter: The compiled converter. @type input: str @param input: The string to convert. @type format: str @param format: The output format. @rtype: str @return: The resulting output. """ builder = generator.new(format) if builder is None: raise TypeError('invalid output format ' + repr(format)) converter.parse_string(input, builder) return builder.serialize()
def generate_string_to_file(converter, input, output_file, format = 'xml'): builder = generator.new(format) if builder is None: raise TypeError('invalid output format ' + repr(format)) converter.parse_string(input, builder) builder.serialize_to_file(output_file)