You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by GitBox <gi...@apache.org> on 2020/08/12 19:08:04 UTC

[GitHub] [qpid-proton] astitcher commented on a change in pull request #256: PROTON-2237: Correct checking of Proton message property keys

astitcher commented on a change in pull request #256:
URL: https://github.com/apache/qpid-proton/pull/256#discussion_r469470459



##########
File path: python/proton/_message.py
##########
@@ -90,13 +90,18 @@ def _check(self, err):
 
     def _check_property_keys(self):

Review comment:
       It would be really helpful here to explain what the AMQP limitations on property keys are. I can't figure out from reading this code what the actual point of the code is.

##########
File path: python/proton/_message.py
##########
@@ -90,13 +90,18 @@ def _check(self, err):
 
     def _check_property_keys(self):
         for k in self.properties.keys():
-            if isinstance(k, unicode):
-                # py2 unicode, py3 str (via hack definition)
+            # Check for string types. (py2: unicode, py3: str via type hack above)
+            # or string subclasses. Exclude string subclasses symbol and char.
+            if isinstance(k, unicode) and not (type(k) is symbol or type(k) is char):
+                # Convert string subclasses to string
+                if not type(k) is unicode:
+                    self.properties[unicode(k)] = self.properties.pop(k)
                 continue

Review comment:
       But if the above code is actually necessary for some reason, then this line is no longer necessary. As in context it is just another way of saying 'pass'

##########
File path: python/proton/_message.py
##########
@@ -90,13 +90,18 @@ def _check(self, err):
 
     def _check_property_keys(self):
         for k in self.properties.keys():
-            if isinstance(k, unicode):
-                # py2 unicode, py3 str (via hack definition)
+            # Check for string types. (py2: unicode, py3: str via type hack above)
+            # or string subclasses. Exclude string subclasses symbol and char.
+            if isinstance(k, unicode) and not (type(k) is symbol or type(k) is char):
+                # Convert string subclasses to string
+                if not type(k) is unicode:
+                    self.properties[unicode(k)] = self.properties.pop(k)

Review comment:
       Why is this even necessary? It's already a (perhaps subclass of) unicode. won't encode just work directly?

##########
File path: python/proton/_message.py
##########
@@ -90,13 +90,18 @@ def _check(self, err):
 
     def _check_property_keys(self):
         for k in self.properties.keys():
-            if isinstance(k, unicode):
-                # py2 unicode, py3 str (via hack definition)
+            # Check for string types. (py2: unicode, py3: str via type hack above)
+            # or string subclasses. Exclude string subclasses symbol and char.
+            if isinstance(k, unicode) and not (type(k) is symbol or type(k) is char):
+                # Convert string subclasses to string
+                if not type(k) is unicode:
+                    self.properties[unicode(k)] = self.properties.pop(k)
                 continue
-            # If key is binary then change to string
-            elif isinstance(k, str):
-                # py2 str
-                self.properties[k.encode('utf-8')] = self.properties.pop(k)
+            # 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

Review comment:
       I don't think converting py3 bytes is acceptable as binary is not a good key (or is it?) it looks like in the previous code it would have triggered an error - only py2 binary would have been converted.

##########
File path: python/proton/_message.py
##########
@@ -90,13 +90,18 @@ def _check(self, err):
 
     def _check_property_keys(self):
         for k in self.properties.keys():
-            if isinstance(k, unicode):
-                # py2 unicode, py3 str (via hack definition)
+            # Check for string types. (py2: unicode, py3: str via type hack above)
+            # or string subclasses. Exclude string subclasses symbol and char.
+            if isinstance(k, unicode) and not (type(k) is symbol or type(k) is char):
+                # Convert string subclasses to string
+                if not type(k) is unicode:
+                    self.properties[unicode(k)] = self.properties.pop(k)
                 continue
-            # If key is binary then change to string
-            elif isinstance(k, str):
-                # py2 str
-                self.properties[k.encode('utf-8')] = self.properties.pop(k)
+            # 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) and not (type(k) is decimal128):

Review comment:
       I think you can leave this test as 'str' as it was before - it only covers the py2 str (binary) case as py3 str is already covered above in unicode, I guess you still need the decimal128 case still though.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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