diff options
author | Simon Feltman <sfeltman@src.gnome.org> | 2014-04-28 23:35:41 -0700 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2015-09-29 23:16:32 -0400 |
commit | 0211bda3da384818c0f99b5a468022c7529fed7e (patch) | |
tree | 4bcdc08fa0c6898d8a9411a73f370254d562eac5 /giscanner/scannermain.py | |
parent | 374e7e8c62358225be65e4b33dc591003550ab50 (diff) | |
download | gobject-introspection-0211bda3da384818c0f99b5a468022c7529fed7e.tar.gz |
giscanner: Use StringIO instead of cStringIO in Python 2
Replace usage of the Python 2 cStringIO module with StringIO and
conditionally use io.StringIO for Python 3. This is needed to build
up a unicode version of the XML since cStringIO does not support
unicode. Add XMLWriter.get_encoded_xml() which returns a utf-8 encoded
bytes object of the XML data.
Open files for reading/writing in binary mode since we explicitly
encode and decode as utf-8.
https://bugzilla.gnome.org/show_bug.cgi?id=679438
Diffstat (limited to 'giscanner/scannermain.py')
-rwxr-xr-x | giscanner/scannermain.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index 4d2fcbf7..b1b0ff6c 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -255,7 +255,7 @@ def passthrough_gir(path, f): parser.parse(path) writer = GIRWriter(parser.get_namespace()) - f.write(writer.get_xml()) + f.write(writer.get_encoded_xml()) def test_codegen(optstring, @@ -444,15 +444,16 @@ def create_source_scanner(options, args): def write_output(data, options): + """Write encoded XML 'data' to the filename specified in 'options'.""" if options.output == "-": output = sys.stdout elif options.reparse_validate_gir: main_f, main_f_name = tempfile.mkstemp(suffix='.gir') - with os.fdopen(main_f, 'w') as main_f: + with os.fdopen(main_f, 'wb') as main_f: main_f.write(data) temp_f, temp_f_name = tempfile.mkstemp(suffix='.gir') - with os.fdopen(temp_f, 'w') as temp_f: + with os.fdopen(temp_f, 'wb') as temp_f: passthrough_gir(main_f_name, temp_f) if not utils.files_are_identical(main_f_name, temp_f_name): _error("Failed to re-parse gir file; scanned='%s' passthrough='%s'" % ( @@ -468,7 +469,7 @@ def write_output(data, options): return 0 else: try: - output = open(options.output, "w") + output = open(options.output, 'wb') except IOError as e: _error("opening output for writing: %s" % (e.strerror, )) @@ -564,7 +565,7 @@ def scanner_main(args): transformer.namespace.c_includes = options.c_includes transformer.namespace.exported_packages = exported_packages writer = Writer(transformer.namespace) - data = writer.get_xml() + data = writer.get_encoded_xml() write_output(data, options) |