diff mbox

Fix pwclient get on Python 2

Message ID 20170522114143.12745-1-dja@axtens.net
State Rejected
Headers show

Commit Message

Daniel Axtens May 22, 2017, 11:41 a.m. UTC
Forcibly convert to unicode on Python 2 only.

This makes 'pwclient get' work on both Python 2 and Python 3.

Signed-off-by: Daniel Axtens <dja@axtens.net>
---
 patchwork/bin/pwclient | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Daniel Axtens May 22, 2017, 11:57 a.m. UTC | #1
Hi,

So I only saw Robin's one after I sent this - Stephen, up to you what
you want to pick.

In the long run we probably want to port this to REST and drop XMLRPC.

Regards,
Daniel

Daniel Axtens <dja@axtens.net> writes:

> Forcibly convert to unicode on Python 2 only.
>
> This makes 'pwclient get' work on both Python 2 and Python 3.
>
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
>  patchwork/bin/pwclient | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
> index 5fcb0844b923..8c26fdb6d876 100755
> --- a/patchwork/bin/pwclient
> +++ b/patchwork/bin/pwclient
> @@ -303,6 +303,11 @@ def action_get(rpc, patch_id):
>          fname = "%s.%d" % (base_fname, i)
>          i += 1
>  
> +    try:
> +        s = unicode(s)
> +    except NameError:
> +        pass
> +
>      with io.open(fname, 'w', encoding='utf-8') as f:
>          f.write(s)
>          print('Saved patch to %s' % fname)
> -- 
> 2.11.0
diff mbox

Patch

diff --git a/patchwork/bin/pwclient b/patchwork/bin/pwclient
index 5fcb0844b923..8c26fdb6d876 100755
--- a/patchwork/bin/pwclient
+++ b/patchwork/bin/pwclient
@@ -303,6 +303,11 @@  def action_get(rpc, patch_id):
         fname = "%s.%d" % (base_fname, i)
         i += 1
 
+    try:
+        s = unicode(s)
+    except NameError:
+        pass
+
     with io.open(fname, 'w', encoding='utf-8') as f:
         f.write(s)
         print('Saved patch to %s' % fname)