diff options
author | Alexander Wauck <awauck@codeweavers.com> | 2015-03-31 12:44:09 -0500 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2015-04-01 13:39:03 +0200 |
commit | e919337980c45fb4bc907cf40cdd106fb8f32d92 (patch) | |
tree | 066ce443b361eff8533f717c5c0b134187c08321 /spice_codegen.py | |
parent | 77ce36426f26cd3dcf8bb06a0511f365c74003dc (diff) |
Make spice_codegen.py work on both Python 2 and 3
This is a new version of my previous patch that does not include six.py.
It's still kind of big, but at least it's all spice-common changes now.
There are also a few other fixes that Christophe brought to my attention.
Note that six now needs to be installed on the system (python-six on
Fedora and Debian, six on PyPI).
This *should* be enough to make spice_codegen.py work on both Python 2
and Python 3. The major changes are as follows:
* cStringIO.StringIO -> io.StringIO
* str vs. unicode updates (io.StringIO doesn't like str)
* integer division
* foo.has_key(bar) -> bar in foo
* import internal_thing -> from . import internal_thing
* removed from __future__ import with_statement
(might break Python 2.5?)
* changed some lambdas to list comprehensions (done by 2to3)
* cast some_dict.keys() to list where needed (e.g. for sorting)
* use normal type names with isinstance instead of types.WhateverType
Signed-off-by: Alexander Wauck <awauck@codeweavers.com>
Diffstat (limited to 'spice_codegen.py')
-rwxr-xr-x | spice_codegen.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/spice_codegen.py b/spice_codegen.py index c8376cc..16ad478 100755 --- a/spice_codegen.py +++ b/spice_codegen.py @@ -9,6 +9,7 @@ from python_modules import ptypes from python_modules import codegen from python_modules import demarshal from python_modules import marshal +import six def write_channel_enums(writer, channel, client, describe): messages = filter(lambda m : m.channel == channel, \ @@ -257,15 +258,18 @@ if options.keep_identical_file: f.close() if content == old_content: - print "No changes to %s" % dest_file + six.print_("No changes to %s" % dest_file) sys.exit(0) except IOError: pass f = open(dest_file, 'wb') -f.write(content) +if six.PY2: + f.write(content) +else: + f.write(bytes(content, 'UTF-8')) f.close() -print "Wrote %s" % dest_file +six.print_("Wrote %s" % dest_file) sys.exit(0) |