Encoding error in output of `pwclient info`
Closed this issue · 3 comments
When interacting with the patchwork instance on http://patchwork.ozlabs.org/project/linux-pwm/list/
using pwclient 1.3.0 I get:
$ pwclient info 1483752
Information for patch id 1483752
--------------------------------
- archived : False
- commit_ref :
- date : 2021-05-25 20:31:56
- delegate : None
- delegate_id : 0
- filename : pwm-crc-Simplify-using-devm_pwmchip_add
- hash : 49644ef2e5a02b4e009a3ae9a7a706e74e2791d2
- id : 1483752
- msgid : <20210525203156.969295-1-u.kleine-koenig@pengutronix.de>
- name : pwm: crc: Simplify using devm_pwmchip_add()
- project : Linux PWM development
- project_id : 38
- state : New
- state_id : 1
- submitter : Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
- submitter_id : 1476
The ö in my name in the submitter
line is misencoded. As the name looks fine when looking at
http://patchwork.ozlabs.org/project/linux-pwm/list/?submitter=1476 I assume the problem is in pwclient. (But I didn't check).
IIRC, this is an issue with the XML-RPC API on the server, not the client. This API is deprecated in favour of the REST API so we aren't fixing bugs with this, I'm afraid
I don't agree this is a problem with the API on the server but a problem how
the data is interpreted in pwclient.
According to
https://github.com/getpatchwork/patchwork/blob/stable/3.0/patchwork/views/xmlrpc.py#L249
the submitter is an utf-8 encoded entity.
On the client side this this ends up being an object of type xmlrpc.client.Binary
:
$ python3
...
>>> import xmlrpc.client
>>> rpc = xmlrpc.client.ServerProxy('https://patchwork.ozlabs.org/xmlrpc/')
>>> p1483752 = rpc.patch_get(1483752)
>>> p1483752['submitter']
<xmlrpc.client.Binary object at 0x7fd2bf4a89d0>
The __str__
method of xmlrpc.client.Binary
however hard codes latin-1 as
encoding. Today this is wrong for most uses, and the code also questions the
encoding choice in a comment. (See
https://github.com/python/cpython/blob/3.9/Lib/xmlrpc/client.py#L405)
So relying on __str__
(which action_info()
does by using %s
for the value) is
not robust at best and something like
diff --git a/pwclient/patches.py b/pwclient/patches.py
index d21d9feb880d..4a6535c955a4 100644
--- a/pwclient/patches.py
+++ b/pwclient/patches.py
@@ -161,6 +161,8 @@ def action_info(rpc, patch_id):
print(s)
print('-' * len(s))
for key, value in sorted(patch.items()):
+ if type(value) == xmlrpclib.Binary:
+ value = str(value.data, 'utf-8')
print("- %- 14s: %s" % (key, value))
fixes the problem for me.
Okay. Would it be possible to submit a PR with this fix. I can merge that and cut a new release.