pwclient: do proper utf-8 encoding of all RPC responses

Message ID 20170313211910.1212-1-arnout@mind.be
State Rejected
Headers show

Commit Message

Arnout Vandecappelle March 13, 2017, 9:19 p.m.
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
Note that I haven't properly tested the change in the delegate printing,
because the ozlabs patchwork instance seems to barf on delegate requests.
I did, however, test that the bit that I modified still works correctly.
---
 patchwork/bin/pwclient | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Stephen Finucane March 21, 2017, 9:29 p.m. | #1
On Mon, 2017-03-13 at 22:19 +0100, Arnout Vandecappelle
(Essensium/Mind) wrote:
> Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>

This needed to a bit of work to apply to upstream, but it breaks on
Python 3 where 'unicode' isn't a defined symbol. Defining 'unicode =
str' results in all files being printed with a 'b' prefix, as expected
given that they're binary strings.

I think this will need a little more work before we can merge it.

Stephen

> ---
> Note that I haven't properly tested the change in the delegate
> printing,
> because the ozlabs patchwork instance seems to barf on delegate
> requests.
> I did, however, test that the bit that I modified still works
> correctly.

Patch

diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index 8d1f476..3a8b2d1 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -157,7 +157,9 @@  def list_patches(patches, format_str=None):
         print("%-7s %-12s %s" % ("ID", "State", "Name"))
         print("%-7s %-12s %s" % ("--", "-----", "----"))
         for patch in patches:
-            print("%-7d %-12s %s" % (patch['id'], patch['state'], patch['name']))
+            print("%-7d %-12s %s" % (patch['id'], \
+                 unicode(patch['state']).encode("utf-8"), \
+                 unicode(patch['name']).encode("utf-8")))
 
 def action_list(rpc, filter, submitter_str, delegate_str, format_str=None):
     filter.resolve_ids(rpc)
@@ -188,7 +190,8 @@  def action_list(rpc, filter, submitter_str, delegate_str, format_str=None):
             for id in ids:
                 person = rpc.person_get(id)
                 print "Patches delegated to %s <%s>:" % \
-                        (person['name'], person['email'])
+                        (unicode(person['name']).encode("utf-8"), \
+                         unicode(person['email']).encode("utf-8"))
                 f = filter
                 f.add("delegate_id", id)
                 patches = rpc.patch_list(f.d)
@@ -204,8 +207,8 @@  def action_projects(rpc):
     print("%-5s %-24s %s" % ("--", "----", "-----------"))
     for project in projects:
         print("%-5d %-24s %s" % (project['id'], \
-                project['linkname'], \
-                project['name']))
+                unicode(project['linkname']).encode("utf-8"), \
+                unicode(project['name']).encode("utf-8")))
 
 def action_states(rpc):
     states = rpc.state_list("", 0)
@@ -264,7 +267,7 @@  def action_apply(rpc, patch_id, apply_cmd=None):
       print "Applying patch #%d using %s" % (
           patch_id, repr(' '.join(apply_cmd)))
 
-    print "Description: %s" % patch['name']
+    print "Description: %s" % unicode(patch['name']).encode("utf-8")
     s = rpc.patch_get_mbox(patch_id)
     if len(s) > 0:
         proc = subprocess.Popen(apply_cmd, stdin = subprocess.PIPE)