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/01/07 23:29:21 UTC

[11/15] qpid-proton git commit: PROTON-1061: [Python Binding] Add support for all AMQP 1.0 types

PROTON-1061: [Python Binding] Add support for all AMQP 1.0 types


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

Branch: refs/heads/go1
Commit: 97f93b9d4657de620818dd170f438245dc8d846e
Parents: e52fd50
Author: Kim van der Riet <kp...@apache.org>
Authored: Thu Jan 7 11:06:08 2016 -0500
Committer: Kim van der Riet <kp...@apache.org>
Committed: Thu Jan 7 11:06:08 2016 -0500

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py | 109 +++++++++++++++++++----
 tests/python/proton_tests/codec.py          |  18 ++--
 2 files changed, 102 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/97f93b9d/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 d6106d1..5720e1c 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -1292,6 +1292,56 @@ class char(unicode):
   def __repr__(self):
     return "char(%s)" % unicode.__repr__(self)
 
+class byte(int):
+
+  def __repr__(self):
+    return "byte(%s)" % int.__repr__(self)
+
+class short(int):
+
+  def __repr__(self):
+    return "short(%s)" % int.__repr__(self)
+
+class int32(int):
+
+  def __repr__(self):
+      return "int32(%s)" % int.__repr__(self)
+
+class ubyte(int):
+
+  def __repr__(self):
+    return "ubyte(%s)" % int.__repr__(self)
+
+class ushort(int):
+
+  def __repr__(self):
+    return "ushort(%s)" % int.__repr__(self)
+
+class uint(long):
+
+  def __repr__(self):
+      return "uint(%s)" % long.__repr__(self)
+
+class float32(float):
+
+  def __repr__(self):
+    return "float32(%s)" % float.__repr__(self)
+
+class decimal32(int):
+
+  def __repr__(self):
+    return "decimal32(%s)" % int.__repr__(self)
+
+class decimal64(long):
+
+  def __repr__(self):
+    return "decimal64(%s)" % long.__repr__(self)
+
+class decimal128(bytes):
+
+  def __repr__(self):
+    return "decimal128(%s)" % bytes.__repr__(self)
+
 class Described(object):
 
   def __init__(self, descriptor, value):
@@ -1904,42 +1954,42 @@ class Data:
     If the current node is an unsigned byte, returns its value,
     returns 0 otherwise.
     """
-    return pn_data_get_ubyte(self._data)
+    return ubyte(pn_data_get_ubyte(self._data))
 
   def get_byte(self):
     """
     If the current node is a signed byte, returns its value, returns 0
     otherwise.
     """
-    return pn_data_get_byte(self._data)
+    return byte(pn_data_get_byte(self._data))
 
   def get_ushort(self):
     """
     If the current node is an unsigned short, returns its value,
     returns 0 otherwise.
     """
-    return pn_data_get_ushort(self._data)
+    return ushort(pn_data_get_ushort(self._data))
 
   def get_short(self):
     """
     If the current node is a signed short, returns its value, returns
     0 otherwise.
     """
-    return pn_data_get_short(self._data)
+    return short(pn_data_get_short(self._data))
 
   def get_uint(self):
     """
     If the current node is an unsigned int, returns its value, returns
     0 otherwise.
     """
-    return pn_data_get_uint(self._data)
+    return uint(pn_data_get_uint(self._data))
 
   def get_int(self):
     """
     If the current node is a signed int, returns its value, returns 0
     otherwise.
     """
-    return int(pn_data_get_int(self._data))
+    return int32(pn_data_get_int(self._data))
 
   def get_char(self):
     """
@@ -1974,7 +2024,7 @@ class Data:
     If the current node is a float, returns its value, raises 0
     otherwise.
     """
-    return pn_data_get_float(self._data)
+    return float32(pn_data_get_float(self._data))
 
   def get_double(self):
     """
@@ -1989,7 +2039,7 @@ class Data:
     If the current node is a decimal32, returns its value, returns 0
     otherwise.
     """
-    return pn_data_get_decimal32(self._data)
+    return decimal32(pn_data_get_decimal32(self._data))
 
   # XXX: need to convert
   def get_decimal64(self):
@@ -1997,7 +2047,7 @@ class Data:
     If the current node is a decimal64, returns its value, returns 0
     otherwise.
     """
-    return pn_data_get_decimal64(self._data)
+    return decimal64(pn_data_get_decimal64(self._data))
 
   # XXX: need to convert
   def get_decimal128(self):
@@ -2005,7 +2055,7 @@ class Data:
     If the current node is a decimal128, returns its value, returns 0
     otherwise.
     """
-    return pn_data_get_decimal128(self._data)
+    return decimal128(pn_data_get_decimal128(self._data))
 
   def get_uuid(self):
     """
@@ -2157,18 +2207,29 @@ class Data:
   put_mappings = {
     None.__class__: lambda s, _: s.put_null(),
     bool: put_bool,
-    dict: put_dict,
-    list: put_sequence,
-    tuple: put_sequence,
-    unicode: put_string,
-    bytes: put_binary,
-    symbol: put_symbol,
+    ubyte: put_ubyte,
+    ushort: put_ushort,
+    uint: put_uint,
+    ulong: put_ulong,
+    byte: put_byte,
+    short: put_short,
+    int32: put_int,
+    int: put_long,
     long: put_long,
+    float32: put_float,
+    float: put_double,
+    decimal32: put_decimal32,
+    decimal64: put_decimal64,
+    decimal128: put_decimal128,
     char: put_char,
-    ulong: put_ulong,
     timestamp: put_timestamp,
-    float: put_double,
     uuid.UUID: put_uuid,
+    bytes: put_binary,
+    unicode: put_string,
+    symbol: put_symbol,
+    list: put_sequence,
+    tuple: put_sequence,
+    dict: put_dict,
     Described: put_py_described,
     Array: put_py_array
     }
@@ -4132,5 +4193,15 @@ __all__ = [
            "dispatch",
            "symbol",
            "timestamp",
-           "ulong"
+           "ulong",
+           "byte",
+           "short",
+           "int32",
+           "ubyte",
+           "ushort",
+           "uint",
+           "float32",
+           "decimal32",
+           "decimal64",
+           "decimal128"
            ]

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/97f93b9d/tests/python/proton_tests/codec.py
----------------------------------------------------------------------
diff --git a/tests/python/proton_tests/codec.py b/tests/python/proton_tests/codec.py
index 19792df..9f246bf 100644
--- a/tests/python/proton_tests/codec.py
+++ b/tests/python/proton_tests/codec.py
@@ -136,6 +136,8 @@ class DataTest(Test):
   INT_TYPES = {
     "byte": (8, True),
     "ubyte": (8, False),
+    "short": (16, True),
+    "ushort": (16, False),
     "int": (32, True),
     "uint": (32, False),
     "long": (64, True),
@@ -203,6 +205,8 @@ class DataTest(Test):
 
   def testByteArray(self): self._test_int_array("byte")
   def testUbyteArray(self): self._test_int_array("ubyte")
+  def testShortArray(self): self._test_int_array("short")
+  def testUshortArray(self): self._test_int_array("ushort")
   def testIntArray(self): self._test_int_array("int")
   def testUintArray(self): self._test_int_array("uint")
   def testLongArray(self): self._test_int_array("long")
@@ -256,6 +260,8 @@ class DataTest(Test):
 
   def testByte(self): self._test_int("byte")
   def testUbyte(self): self._test_int("ubyte")
+  def testShort(self): self._test_int("short")
+  def testUshort(self): self._test("ushort")
   def testInt(self): self._test_int("int")
   def testUint(self): self._test_int("uint")
   def testLong(self): self._test_int("long")
@@ -279,25 +285,25 @@ class DataTest(Test):
                str2bin("of" "b\x00inary"))
 
   def testSymbol(self):
-    self._test("symbol", "this is a symbol test", "bleh", "blah")
+    self._test("symbol", symbol("this is a symbol test"), symbol("bleh"), symbol("blah"))
 
   def testTimestamp(self):
-    self._test("timestamp", 0, 12345, 1000000)
+    self._test("timestamp", timestamp(0), timestamp(12345), timestamp(1000000))
 
   def testChar(self):
-    self._test("char", 'a', 'b', 'c', unichar(0x20AC))
+    self._test("char", char('a'), char('b'), char('c'), char(unichar(0x20AC)))
 
   def testUUID(self):
     self._test("uuid", uuid4(), uuid4(), uuid4())
 
   def testDecimal32(self):
-    self._test("decimal32", 0, 1, 2, 3, 4, 2**30)
+    self._test("decimal32", decimal32(0), decimal32(1), decimal32(2), decimal32(3), decimal32(4), decimal32(2**30))
 
   def testDecimal64(self):
-    self._test("decimal64", 0, 1, 2, 3, 4, 2**60)
+    self._test("decimal64", decimal64(0), decimal64(1), decimal64(2), decimal64(3), decimal64(4), decimal64(2**60))
 
   def testDecimal128(self):
-    self._test("decimal128", str2bin("fdsaasdf;lkjjkl;"), str2bin("x"*16))
+    self._test("decimal128", decimal128(str2bin("fdsaasdf;lkjjkl;")), decimal128(str2bin("x"*16)))
 
   def testCopy(self):
     self.data.put_described()


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