You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kp...@apache.org on 2020/08/12 14:53:38 UTC

[qpid-proton] branch python-check-property-keys updated (6eac210 -> 08db56e)

This is an automated email from the ASF dual-hosted git repository.

kpvdr pushed a change to branch python-check-property-keys
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git.


    from 6eac210  PROTON-2237: Changed logic of key check so that subclasses of string *except* proton.symbol and proton.char will be encoded as strings
     new 4e19c7c  PROTON-2237: Added unit tests to check illegal key types are detected and handled, also subclasses of string type keys are converted to type string
     new 08db56e  PROTON-2237: Finalized handling property keys, added tests for these cases.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 python/proton/_message.py            |  6 ++--
 python/tests/proton_tests/message.py | 67 ++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 3 deletions(-)


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


[qpid-proton] 01/02: PROTON-2237: Added unit tests to check illegal key types are detected and handled, also subclasses of string type keys are converted to type string

Posted by kp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kpvdr pushed a commit to branch python-check-property-keys
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 4e19c7ce9c18304d793719d493ce602a6755e271
Author: Kim van der Riet <kp...@apache.org>
AuthorDate: Tue Aug 11 17:11:15 2020 -0400

    PROTON-2237: Added unit tests to check illegal key types are detected and handled, also subclasses of string type keys are converted to type string
---
 python/tests/proton_tests/message.py | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/python/tests/proton_tests/message.py b/python/tests/proton_tests/message.py
index 04413ee..d819096 100644
--- a/python/tests/proton_tests/message.py
+++ b/python/tests/proton_tests/message.py
@@ -107,6 +107,11 @@ class AccessorsTest(Test):
   def testReplyToGroupId(self):
     self._test_str("reply_to_group_id")
 
+try:
+    unicode()
+except NameError:
+    unicode = str
+
 class CodecTest(Test):
 
   def testProperties(self):
@@ -119,6 +124,43 @@ class CodecTest(Test):
 
     assert msg2.properties['key'] == 'value', msg2.properties['key']
 
+  class MyStringSubclass(unicode):
+    def __repr__(self):
+      return 'MyStringSubclass(%s)' % unicode.__repr__(self)
+
+  def testStringSubclassPropertyKey(self):
+    self.msg.properties = {CodecTest.MyStringSubclass('abc'): 123}
+    data = self.msg.encode()
+
+    msg2 = Message()
+    msg2.decode(data)
+
+    assert msg2.properties == self.msg.properties
+
+  def testNonStringPropertyKey(self):
+    self.msg.properties = {123: 'abc'}
+    try:
+       self.msg.encode()
+    except MessageException:
+      return
+    assert True, '%s: non-string key' % self.msg
+
+  def testSymbolPropertyKey(self):
+    self.msg.properties = {symbol('abc'): 'def'}
+    try:
+       self.msg.encode()
+    except MessageException:
+      return
+    assert True, '%s: symbol key' % self.msg
+
+  def testCharPropertyKey(self):
+    self.msg.properties = {char('a'): 'bcd'}
+    try:
+       self.msg.encode()
+    except MessageException:
+      return
+    assert True, '%s: char key' % self.msg
+
   def testAnnotationsSymbolicAndUlongKey(self, a={symbol('one'): 1, 'two': 2, ulong(3): 'three'}):
     self.msg.annotations = a
     data = self.msg.encode()


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


[qpid-proton] 02/02: PROTON-2237: Finalized handling property keys, added tests for these cases.

Posted by kp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kpvdr pushed a commit to branch python-check-property-keys
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 08db56e14045896057c483592d0230890643cace
Author: Kim van der Riet <kp...@apache.org>
AuthorDate: Wed Aug 12 10:53:21 2020 -0400

    PROTON-2237: Finalized handling property keys, added tests for these cases.
---
 python/proton/_message.py            |  6 ++--
 python/tests/proton_tests/message.py | 63 +++++++++++++++++++++++++-----------
 2 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/python/proton/_message.py b/python/proton/_message.py
index 16556be..cdaaf2f 100644
--- a/python/proton/_message.py
+++ b/python/proton/_message.py
@@ -34,7 +34,7 @@ from cproton import PN_DEFAULT_PRIORITY, PN_OVERFLOW, pn_error_text, pn_message,
 
 from . import _compat
 from ._common import isinteger, millis2secs, secs2millis, unicode2utf8, utf82unicode
-from ._data import char, Data, symbol, ulong, AnnotationDict
+from ._data import char, Data, decimal128, symbol, ulong, AnnotationDict
 from ._endpoints import Link
 from ._exceptions import EXCEPTIONS, MessageException
 
@@ -97,10 +97,10 @@ class Message(object):
                 if not type(k) is unicode:
                     self.properties[unicode(k)] = self.properties.pop(k)
                 continue
-            # If key is binary then change to string
+            # If key is binary then change to string. Exclude bytes subclass decimal128.
             # Mostly for py2 users who encode strings without using the u'' prefix
             # but py3 bytes() type will be converted also
-            elif isinstance(k, bytes):
+            elif isinstance(k, bytes) and not (type(k) is decimal128):
                 self.properties[k.decode('utf-8')] = self.properties.pop(k)
             else:
                 raise MessageException('Application property key is not string type: key=%s %s' % (str(k), type(k)))
diff --git a/python/tests/proton_tests/message.py b/python/tests/proton_tests/message.py
index d819096..4363168 100644
--- a/python/tests/proton_tests/message.py
+++ b/python/tests/proton_tests/message.py
@@ -108,6 +108,10 @@ class AccessorsTest(Test):
     self._test_str("reply_to_group_id")
 
 try:
+    long()
+except NameError:
+    long = int
+try:
     unicode()
 except NameError:
     unicode = str
@@ -129,7 +133,7 @@ class CodecTest(Test):
       return 'MyStringSubclass(%s)' % unicode.__repr__(self)
 
   def testStringSubclassPropertyKey(self):
-    self.msg.properties = {CodecTest.MyStringSubclass('abc'): 123}
+    self.msg.properties = {'abc': 123, CodecTest.MyStringSubclass('def'): 456}
     data = self.msg.encode()
 
     msg2 = Message()
@@ -137,29 +141,50 @@ class CodecTest(Test):
 
     assert msg2.properties == self.msg.properties
 
-  def testNonStringPropertyKey(self):
-    self.msg.properties = {123: 'abc'}
-    try:
-       self.msg.encode()
-    except MessageException:
-      return
-    assert True, '%s: non-string key' % self.msg
+  def testBinaryPropertyKey(self):
+    self.msg.properties = {'abc': 123, b'def': 456}
+    data = self.msg.encode()
 
-  def testSymbolPropertyKey(self):
-    self.msg.properties = {symbol('abc'): 'def'}
+    msg2 = Message()
+    msg2.decode(data)
+
+    assert msg2.properties == self.msg.properties
+
+  def _testNonStringPropertyKey(self, k):
+    self.msg.properties = {k: 'abc'}
     try:
-       self.msg.encode()
+        self.msg.encode()
     except MessageException:
-      return
-    assert True, '%s: symbol key' % self.msg
+        return
+    self.fail('Non-string property key: %s, key type: %s' % (self.msg, type(k)))
+
+  def testNonSequencePropertyKeys(self):
+    # AMQP non-string types
+    self._testNonStringPropertyKey(None)
+    self._testNonStringPropertyKey(True)
+    self._testNonStringPropertyKey(byte(1))
+    self._testNonStringPropertyKey(ubyte(2))
+    self._testNonStringPropertyKey(short(3))
+    self._testNonStringPropertyKey(ushort(4))
+    self._testNonStringPropertyKey(int32(5))
+    self._testNonStringPropertyKey(uint(6))
+    self._testNonStringPropertyKey(long(7))
+    self._testNonStringPropertyKey(ulong(8))
+    self._testNonStringPropertyKey(float32(9.0))
+    self._testNonStringPropertyKey(10.0)
+    self._testNonStringPropertyKey(decimal32(11))
+    self._testNonStringPropertyKey(decimal64(12))
+    self._testNonStringPropertyKey(timestamp(1234567890))
+    self._testNonStringPropertyKey(uuid4())
 
   def testCharPropertyKey(self):
-    self.msg.properties = {char('a'): 'bcd'}
-    try:
-       self.msg.encode()
-    except MessageException:
-      return
-    assert True, '%s: char key' % self.msg
+    self._testNonStringPropertyKey(char('A'))
+
+  def testDecimal128PropertyKey(self):
+    self._testNonStringPropertyKey(decimal128(b'12345'))
+
+  def testSymbolPropertyKey(self):
+    self._testNonStringPropertyKey(symbol('abcdef'))
 
   def testAnnotationsSymbolicAndUlongKey(self, a={symbol('one'): 1, 'two': 2, ulong(3): 'three'}):
     self.msg.annotations = a


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