[RFC PATCH] pwclient: Force xmlrpc client to return unicode strings
Stephen Finucane
stephen at that.guru
Tue May 23 22:44:57 AEST 2017
On Tue, 2017-05-23 at 14:29 +0200, Robin Jarry wrote:
> Hi Stephen,
>
> 2017-05-23, Stephen Finucane:
> > Thanks for doing this, Robin :) The patch looks pretty good as-is.
> > However, based on what you've said, all this hassle traces back to
> > the
> > the '_stringify' function [1]. I wonder if we could simplify things
> > by
> > merely monkey patching that function instead? Something like the
> > below
> > _could_ do the job, I'd imagine?
> >
> > if sys.version_info[0] < 3:
> > def _stringify(string):
> > return string
> >
> > xmlrpclib._stringify = _stringify
>
> To be honest, I didn't think about doing this. It seems simpler, but
> this may cause side-effects since _stringify is used at least in one
> other place where
>
> https://github.com/python/cpython/blob/2.7/Lib/xmlrpclib.py#L899
>
> However, python also seems not to care about unicode VS bytes when
> looking up dictionary keys:
>
> $ python
> Python 2.7.9 (default, Jun 29 2016, 13:08:31)
> ...
> >>> d['x'] = 2
> >>> d[u'x']
> 2
> >>> d[b'x']
> 2
>
> >
> > Other than the fact that we're messing with private methods (we're
> > consenting adults here), does this looks sensible? Any thoughts on
> > how this compares?
>
> So your suggestion is OK :) I let you choose which solution you
> prefer, I'll be glad to rework the patch accordingly.
Given that less lines of code means less chance of bugs, we might as
well go for the shorter solution. If you can submit that patch, I'd be
happy to merge it and include it in v2.0.0 rc3/final.
> > PS: I noticed this didn't get picked up by Patchwork. I wonder why?
>
> Do you mean on the server side? _stringify is only used when
> unmarshalling and I guess that it does not cause problems (maybe
> there are safeguards in django to be smart with unicode/bytes on
> python2).
I meant this actual patch/message itself. It's not listed on
patchwork.ozlabs.org/project/patchwork/list/.
Stephen
More information about the Patchwork
mailing list