From 5e3b234c30de9115845e41f1150d8729bc44d52e Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 23 May 2017 15:24:07 +0200 Subject: [PATCH] pwclient: Force xmlrpc client to return unicode strings On python 2, the reference implementation of the XML-RPC unmarshaller decodes strings to unicode with the selected encoding (utf-8 by default) but it tries to re-encode the unicode strings to ascii bytes before returning the values. If it fails, it leaves the value as unicode. See these links for more details: https://hg.python.org/cpython/file/2.7/Lib/xmlrpclib.py#l878 https://hg.python.org/cpython/file/2.7/Lib/xmlrpclib.py#l180 https://hg.python.org/cpython/file/3.6/Lib/xmlrpc/client.py#l753 Monkey-patch the internal xmlrpclib._stringify() function only on python 2 to force it to preserve unicode strings. This allows to have similar behaviour in both python 2 and python 3. Signed-off-by: Robin Jarry Signed-off-by: Stephen Finucane --- patchwork/bin/pwclient | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient index 5fcb0844..ceccbf3f 100755 --- a/patchwork/bin/pwclient +++ b/patchwork/bin/pwclient @@ -97,6 +97,13 @@ class Filter(object): return str(self.d) +if sys.version_info[0] < 3: + # the python 2.7 reference implementation tries to re-encode to + # ascii bytes here but leaves unicode if it fails. Do not try to + # re-encode to ascii byte string to have a more predictive behavior. + xmlrpclib._stringify = lambda s: s + + class Transport(xmlrpclib.SafeTransport): def __init__(self, url): -- 2.47.3