You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2016/10/19 19:24:08 UTC

qpid-proton git commit: PROTON-1325: Python mapping for 'buffer' and/or 'memoryview'

Repository: qpid-proton
Updated Branches:
  refs/heads/master 956827559 -> 6dabb379b


PROTON-1325: Python mapping for 'buffer' and/or 'memoryview'

Use whichever is available, memoryview is 3.x and some later 2.x, buffer is
older 2.x. Some have both.


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

Branch: refs/heads/master
Commit: 6dabb379bf029950ce96966a305cf6b0bc344448
Parents: 9568275
Author: Alan Conway <ac...@redhat.com>
Authored: Wed Oct 19 13:20:48 2016 -0400
Committer: Alan Conway <ac...@redhat.com>
Committed: Wed Oct 19 15:23:52 2016 -0400

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py |  8 +++++--
 tests/python/proton_tests/codec.py          | 27 +++++++++++++++++-------
 2 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6dabb379/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index 1478d38..516daf1 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -2229,14 +2229,18 @@ class Data:
     list: put_sequence,
     tuple: put_sequence,
     dict: put_dict,
-    buffer: put_binary,
     Described: put_py_described,
     Array: put_py_array
     }
   # for python 3.x, long is merely an alias for int, but for python 2.x
   # we need to add an explicit int since it is a different type
   if int not in put_mappings:
-      put_mappings[int] = put_int
+    put_mappings[int] = put_int
+  # For python 3.x use 'memoryview', for <=2.5 use 'buffer'. Python >=2.6 has both.
+  if getattr(__builtins__, 'memoryview', None):
+    put_mappings[memoryview] = put_binary
+  if getattr(__builtins__, 'buffer', None):
+    put_mappings[buffer] = put_binary
 
   get_mappings = {
     NULL: lambda s: None,

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/6dabb379/tests/python/proton_tests/codec.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/codec.py b/tests/python/proton_tests/codec.py
index b7bb04d..4d3d906 100644
--- a/tests/python/proton_tests/codec.py
+++ b/tests/python/proton_tests/codec.py
@@ -357,14 +357,25 @@ class DataTest(Test):
     copy = data.get_object()
     assert copy == obj, (copy, obj)
 
-  def testBuffer(self):
-    self.data.put_object(buffer("foo"))
-    data = Data()
-    data.decode(self.data.encode())
-    data.rewind()
-    assert data.next()
-    assert data.type() == Data.BINARY
-    assert data.get_object() == "foo"
+  if getattr(__builtins__, 'buffer', None):
+    def testBuffer(self):
+      self.data.put_object(buffer("foo"))
+      data = Data()
+      data.decode(self.data.encode())
+      data.rewind()
+      assert data.next()
+      assert data.type() == Data.BINARY
+      assert data.get_object() == "foo"
+
+  if getattr(__builtins__, 'memoryview', None):
+    def testBuffer(self):
+      self.data.put_object(memoryview("foo"))
+      data = Data()
+      data.decode(self.data.encode())
+      data.rewind()
+      assert data.next()
+      assert data.type() == Data.BINARY
+      assert data.get_object() == "foo"
 
   def testLookup(self):
     obj = {symbol("key"): str2unicode("value"),


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