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 2019/04/15 21:00:40 UTC
[qpid-proton] branch master updated: PROTON-2034: Python client
converts binary selector strings to unicode before sending to server
This is an automated email from the ASF dual-hosted git repository.
kpvdr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/master by this push:
new d42b738 PROTON-2034: Python client converts binary selector strings to unicode before sending to server
d42b738 is described below
commit d42b738283508c8fefc7ca55efdba02ea65c5e79
Author: Kim van der Riet <kv...@localhost.localdomain>
AuthorDate: Mon Apr 15 17:00:24 2019 -0400
PROTON-2034: Python client converts binary selector strings to unicode before sending to server
---
python/proton/_common.py | 4 ++++
python/proton/_reactor.py | 2 +-
python/tests/proton_tests/reactor.py | 21 ++++++++++++++++-----
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/python/proton/_common.py b/python/proton/_common.py
index d64f408..38cdfcf 100644
--- a/python/proton/_common.py
+++ b/python/proton/_common.py
@@ -88,3 +88,7 @@ def utf82unicode(string):
# py2 str (via hack definition), py3 bytes
return string.decode('utf8')
raise TypeError("Unrecognized string type")
+
+def isutf8(string):
+ """Test if a string is unicode"""
+ return isinstance(string, unicode) # py2 unicode, py3 str (via hack definition)
diff --git a/python/proton/_reactor.py b/python/proton/_reactor.py
index e1ddae3..60a1a2c 100644
--- a/python/proton/_reactor.py
+++ b/python/proton/_reactor.py
@@ -600,7 +600,7 @@ class Selector(Filter):
"""
def __init__(self, value, name='selector'):
- super(Selector, self).__init__({symbol(name): Described(symbol('apache.org:selector-filter:string'), value)})
+ super(Selector, self).__init__({symbol(name): Described(symbol('apache.org:selector-filter:string'), utf82unicode(value))})
class DurableSubscription(ReceiverOption):
diff --git a/python/tests/proton_tests/reactor.py b/python/tests/proton_tests/reactor.py
index 0e80e49..2483e0f 100644
--- a/python/tests/proton_tests/reactor.py
+++ b/python/tests/proton_tests/reactor.py
@@ -21,9 +21,11 @@ from __future__ import absolute_import
import time
-from proton.reactor import Container, ApplicationEvent, EventInjector
+from proton.reactor import Container, ApplicationEvent, EventInjector, Selector
from proton.handlers import Handshaker, MessagingHandler
from proton import Handler, Url
+from proton._data import symbol
+from proton._common import isutf8
from .common import Test, SkipTest, TestServer, free_tcp_port, ensureCanTestExtendedSASL
@@ -305,11 +307,11 @@ class ApplicationEventTest(Test):
def setUp(self):
import os
if not hasattr(os, 'pipe'):
- # KAG: seems like Jython doesn't have an os.pipe() method
- raise SkipTest()
+ # KAG: seems like Jython doesn't have an os.pipe() method
+ raise SkipTest()
if os.name=="nt":
- # Correct implementation on Windows is complicated
- raise SkipTest("PROTON-1071")
+ # Correct implementation on Windows is complicated
+ raise SkipTest("PROTON-1071")
self.server = ApplicationEventTest.MyTestServer()
self.server.reactor.handler.add(ApplicationEventTest.MyHandler(self))
self.event_injector = EventInjector()
@@ -499,3 +501,12 @@ class ContainerTest(Test):
virtual_host="")
container.run()
assert server_handler.peer_hostname is None, server_handler.peer_hostname
+
+class SelectorTest(Test):
+ """Test the Selector"""
+
+ def test_unicode_selector(self):
+ assert(isutf8(Selector(u"Hello").filter_set[symbol('selector')].value))
+
+ def test_non_unicode_selector(self):
+ assert(isutf8(Selector(b"Hello").filter_set[symbol('selector')].value))
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org