qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject [1/5] qpid-proton git commit: PROTON-490: futurize proton-c
Date Wed, 22 Apr 2015 15:00:31 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/kgiusti-python3 903c72469 -> e87a6d313


PROTON-490: futurize proton-c


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/677729af
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/677729af
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/677729af

Branch: refs/heads/kgiusti-python3
Commit: 677729af4f4eea3076bfe493ad217b65aa125178
Parents: 81085e3
Author: Ken Giusti <kgiusti@apache.org>
Authored: Thu Apr 16 14:13:54 2015 -0400
Committer: Ken Giusti <kgiusti@apache.org>
Committed: Mon Apr 20 12:45:16 2015 -0400

----------------------------------------------------------------------
 proton-c/mllib/__init__.py        | 10 +++-
 proton-c/mllib/dom.py             |  5 +-
 proton-c/mllib/parsers.py         |  3 +-
 proton-c/mllib/transforms.py      |  3 +-
 proton-c/src/codec/encodings.h.py | 17 ++++---
 proton-c/src/protocol.h.py        | 91 +++++++++++++++++-----------------
 6 files changed, 70 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/677729af/proton-c/mllib/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/__init__.py b/proton-c/mllib/__init__.py
index 9aa1e56..c6fccf1 100644
--- a/proton-c/mllib/__init__.py
+++ b/proton-c/mllib/__init__.py
@@ -22,16 +22,22 @@ This module provides document parsing and transformation utilities for
 both SGML and XML.
 """
 
-import os, dom, transforms, parsers, sys
+from __future__ import absolute_import
+
+import os, sys
 import xml.sax, types
 from xml.sax.handler import ErrorHandler
 from xml.sax.xmlreader import InputSource
 from cStringIO import StringIO
 
+from . import dom
+from . import transforms
+from . import parsers
+
 def transform(node, *args):
   result = node
   for t in args:
-    if isinstance(t, types.ClassType):
+    if isinstance(t, type):
       t = t()
     result = result.dispatch(t)
   return result

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/677729af/proton-c/mllib/dom.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/dom.py b/proton-c/mllib/dom.py
index 486f708..4cbac26 100644
--- a/proton-c/mllib/dom.py
+++ b/proton-c/mllib/dom.py
@@ -24,8 +24,8 @@ Simple DOM for both SGML and XML documents.
 from __future__ import division
 from __future__ import generators
 from __future__ import nested_scopes
+from __future__ import absolute_import
 
-import transforms
 
 class Container:
 
@@ -109,6 +109,7 @@ class Node(Container, Component, Dispatcher):
       return nd
 
   def text(self):
+    from . import transforms
     return self.dispatch(transforms.Text())
 
   def tag(self, name, *attrs, **kwargs):
@@ -238,7 +239,7 @@ class Flatten(View):
     sources = [iter(self.source)]
     while sources:
       try:
-        nd = sources[-1].next()
+        nd = next(sources[-1])
         if isinstance(nd, Tree):
           sources.append(iter(nd.children))
         else:

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/677729af/proton-c/mllib/parsers.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/parsers.py b/proton-c/mllib/parsers.py
index 3e7cc10..e71018d 100644
--- a/proton-c/mllib/parsers.py
+++ b/proton-c/mllib/parsers.py
@@ -20,9 +20,10 @@
 """
 Parsers for SGML and XML to dom.
 """
+from __future__ import absolute_import
 
 import sgmllib, xml.sax.handler
-from dom import *
+from .dom import *
 
 class Parser:
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/677729af/proton-c/mllib/transforms.py
----------------------------------------------------------------------
diff --git a/proton-c/mllib/transforms.py b/proton-c/mllib/transforms.py
index 69d9912..383add3 100644
--- a/proton-c/mllib/transforms.py
+++ b/proton-c/mllib/transforms.py
@@ -20,8 +20,9 @@
 """
 Useful transforms for dom objects.
 """
+from __future__ import absolute_import
 
-import dom
+from . import dom
 from cStringIO import StringIO
 
 class Visitor:

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/677729af/proton-c/src/codec/encodings.h.py
----------------------------------------------------------------------
diff --git a/proton-c/src/codec/encodings.h.py b/proton-c/src/codec/encodings.h.py
index 71fb9ea..9f08c6c 100755
--- a/proton-c/src/codec/encodings.h.py
+++ b/proton-c/src/codec/encodings.h.py
@@ -18,16 +18,17 @@
 # under the License.
 #
 
+from __future__ import print_function
 import mllib, optparse, os, sys
 
 xml = os.path.join(os.path.dirname(__file__), "types.xml")
 doc = mllib.xml_parse(xml)
 
-print "/* generated from %s */" % xml
-print "#ifndef _PROTON_ENCODINGS_H"
-print "#define _PROTON_ENCODINGS_H 1"
-print
-print "#define PNE_DESCRIPTOR          (0x00)"
+print("/* generated from %s */" % xml)
+print("#ifndef _PROTON_ENCODINGS_H")
+print("#define _PROTON_ENCODINGS_H 1")
+print()
+print("#define PNE_DESCRIPTOR          (0x00)")
 
 for enc in doc.query["amqp/section/type/encoding"]:
   name = enc["@name"] or enc.parent["@name"]
@@ -35,7 +36,7 @@ for enc in doc.query["amqp/section/type/encoding"]:
   if name == "ieee-754":
     name = enc.parent["@name"]
   cname = "PNE_" + name.replace("-", "_").upper()
-  print "#define %s%s(%s)" % (cname, " "*(20-len(cname)), enc["@code"])
+  print("#define %s%s(%s)" % (cname, " "*(20-len(cname)), enc["@code"]))
 
-print
-print "#endif /* encodings.h */"
+print()
+print("#endif /* encodings.h */")

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/677729af/proton-c/src/protocol.h.py
----------------------------------------------------------------------
diff --git a/proton-c/src/protocol.h.py b/proton-c/src/protocol.h.py
index 76a2391..bbc0dfe 100644
--- a/proton-c/src/protocol.h.py
+++ b/proton-c/src/protocol.h.py
@@ -18,20 +18,21 @@
 # under the License.
 #
 
+from __future__ import print_function
 from protocol import *
 
-print "/* generated */"
-print "#ifndef _PROTON_PROTOCOL_H"
-print "#define _PROTON_PROTOCOL_H 1"
-print
-print "#include \"proton/type_compat.h\""
+print("/* generated */")
+print("#ifndef _PROTON_PROTOCOL_H")
+print("#define _PROTON_PROTOCOL_H 1")
+print()
+print("#include \"proton/type_compat.h\"")
 
 fields = {}
 
 for type in TYPES:
   fidx = 0
   for f in type.query["field"]:
-    print "#define %s_%s (%s)" % (field_kw(type), field_kw(f), fidx)
+    print("#define %s_%s (%s)" % (field_kw(type), field_kw(f), fidx))
     fidx += 1
 
 idx = 0
@@ -39,14 +40,14 @@ idx = 0
 for type in TYPES:
   desc = type["descriptor"]
   name = type["@name"].upper().replace("-", "_")
-  print "#define %s_SYM (\"%s\")" % (name, desc["@name"])
+  print("#define %s_SYM (\"%s\")" % (name, desc["@name"]))
   hi, lo = [int(x, 0) for x in desc["@code"].split(":")]
   code = (hi << 32) + lo
-  print "#define %s ((uint64_t) %s)" % (name, code)
+  print("#define %s ((uint64_t) %s)" % (name, code))
   fields[code] = (type["@name"], [f["@name"] for f in type.query["field"]])
   idx += 1
 
-print """
+print("""
 #include <stddef.h>
 
 typedef struct {
@@ -61,43 +62,43 @@ extern const uint16_t FIELD_NAME[];
 extern const uint16_t FIELD_FIELDS[];
 extern const unsigned char FIELD_MIN;
 extern const unsigned char FIELD_MAX;
-"""
+""")
 
-print "#ifdef DEFINE_FIELDS"
+print("#ifdef DEFINE_FIELDS")
 
-print 'struct FIELD_STRINGS {'
-print '  const char FIELD_STRINGS_NULL[sizeof("")];'
+print('struct FIELD_STRINGS {')
+print('  const char FIELD_STRINGS_NULL[sizeof("")];')
 strings = set()
 for name, fnames in fields.values():
     strings.add(name)
     strings.update(fnames)
 for str in strings:
     istr = str.replace("-", "_");
-    print '  const char FIELD_STRINGS_%s[sizeof("%s")];' % (istr, str)
-print "};"
-print
-print 'const struct FIELD_STRINGS FIELD_STRINGS = {'
-print '  "",'
+    print('  const char FIELD_STRINGS_%s[sizeof("%s")];' % (istr, str))
+print("};")
+print()
+print('const struct FIELD_STRINGS FIELD_STRINGS = {')
+print('  "",')
 for str in strings:
-    print '  "%s",'% str
-print "};"
-print 'const char * const FIELD_STRINGPOOL = (const char * const) &FIELD_STRINGS;'
-print
-print "/* This is an array of offsets into FIELD_STRINGPOOL */"
-print "const uint16_t FIELD_NAME[] = {"
-print "  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),"
+    print('  "%s",'% str)
+print("};")
+print('const char * const FIELD_STRINGPOOL = (const char * const) &FIELD_STRINGS;')
+print()
+print("/* This is an array of offsets into FIELD_STRINGPOOL */")
+print("const uint16_t FIELD_NAME[] = {")
+print("  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),")
 index = 1
 for i in range(256):
   if i in fields:
     name, fnames = fields[i]
     iname = name.replace("-", "_");
-    print '  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d */' % (iname, index)
+    print('  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d */' % (iname, index))
     index += 1
-print "};"
+print("};")
 
-print "/* This is an array of offsets into FIELD_STRINGPOOL */"
-print "const uint16_t FIELD_FIELDS[] = {"
-print "  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),"
+print("/* This is an array of offsets into FIELD_STRINGPOOL */")
+print("const uint16_t FIELD_FIELDS[] = {")
+print("  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_NULL),")
 index = 1
 for i in range(256):
   if i in fields:
@@ -105,11 +106,11 @@ for i in range(256):
     if fnames:
       for f in fnames:
         ifname = f.replace("-", "_");
-        print '  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d (%s) */' % (ifname,
index, name)
+        print('  offsetof(struct FIELD_STRINGS, FIELD_STRINGS_%s), /* %d (%s) */' % (ifname,
index, name))
         index += 1
-print "};"
+print("};")
 
-print "const pn_fields_t FIELDS[] = {"
+print("const pn_fields_t FIELDS[] = {")
 
 name_count = 1
 field_count = 1
@@ -124,21 +125,21 @@ for i in range(field_min, field_max+1):
   if i in fields:
     name, fnames = fields[i]
     if fnames:
-      print '  {%d, %d, %d}, /* %d (%s) */' % (name_count, field_count, len(fnames), i, name)
+      print('  {%d, %d, %d}, /* %d (%s) */' % (name_count, field_count, len(fnames), i, name))
       field_count += len(fnames)
     else:
-      print '  {%d, 0, 0}, /* %d (%s) */' % (name_count, i, name)
+      print('  {%d, 0, 0}, /* %d (%s) */' % (name_count, i, name))
     name_count += 1
     if i>field_max: field_max = i
     if i<field_min: field_min = i
   else:
-    print '  {0, 0, 0}, /* %d */' % i
-
-print "};"
-print
-print 'const unsigned char FIELD_MIN = %d;' % field_min
-print 'const unsigned char FIELD_MAX = %d;' % field_max
-print
-print "#endif"
-print
-print "#endif /* protocol.h */"
+    print('  {0, 0, 0}, /* %d */' % i)
+
+print("};")
+print()
+print('const unsigned char FIELD_MIN = %d;' % field_min)
+print('const unsigned char FIELD_MAX = %d;' % field_max)
+print()
+print("#endif")
+print()
+print("#endif /* protocol.h */")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message