From ba52c4cae204c4fc7104b14ac446d4d5a65a26f8 Mon Sep 17 00:00:00 2001 From: Alexander Wauck Date: Tue, 31 Mar 2015 12:44:09 -0500 Subject: 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 --- python_modules/marshal.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'python_modules/marshal.py') diff --git a/python_modules/marshal.py b/python_modules/marshal.py index 1eda1ba..b77b910 100644 --- a/python_modules/marshal.py +++ b/python_modules/marshal.py @@ -1,6 +1,6 @@ -from __future__ import with_statement -import ptypes -import codegen + +from . import ptypes +from . import codegen def write_includes(writer): writer.header.writeln("#include ") @@ -112,7 +112,7 @@ def write_marshal_ptr_function(writer, target_type, is_helper=True): names = target_type.get_pointer_names(False) names_args = "" if len(names) > 0: - n = map(lambda name: ", SpiceMarshaller **%s_out" % name, names) + n = [", SpiceMarshaller **%s_out" % name for name in names] names_args = "".join(n) header = writer.header @@ -345,7 +345,7 @@ def write_message_marshaller(writer, message, is_server, private): names = message.get_pointer_names(False) names_args = "" if len(names) > 0: - n = map(lambda name: ", SpiceMarshaller **%s_out" % name, names) + n = [", SpiceMarshaller **%s_out" % name for name in names] names_args = "".join(n) if not private: @@ -383,9 +383,9 @@ def write_protocol_marshaller(writer, proto, is_server, private_marshallers): for m in channel.client_messages: message = m.message_type f = write_message_marshaller(writer, message, is_server, private_marshallers) - if channel.has_attr("ifdef") and not functions.has_key(f): + if channel.has_attr("ifdef") and f not in functions: functions[f] = channel.attributes["ifdef"][0] - elif message.has_attr("ifdef") and not functions.has_key(f): + elif message.has_attr("ifdef") and f not in functions: functions[f] = message.attributes["ifdef"][0] else: functions[f] = True @@ -393,9 +393,9 @@ def write_protocol_marshaller(writer, proto, is_server, private_marshallers): for m in channel.server_messages: message = m.message_type f = write_message_marshaller(writer, message, is_server, private_marshallers) - if channel.has_attr("ifdef") and not functions.has_key(f): + if channel.has_attr("ifdef") and f not in functions: functions[f] = channel.attributes["ifdef"][0] - elif message.has_attr("ifdef") and not functions.has_key(f): + elif message.has_attr("ifdef") and f not in functions: functions[f] = message.attributes["ifdef"][0] else: functions[f] = True -- cgit