[Twisted-Python] [Twisted] #7598: Port twisted.spread.pb to Python3

Glyph Lefkowitz glyph at twistedmatrix.com
Tue Aug 2 14:55:42 MDT 2016


> On Aug 2, 2016, at 4:38 AM, Wolfgang Rohdewald <wolfgang.kde at rohdewald.de <mailto:wolfgang.kde at rohdewald.de>> wrote:
> 
> Am Dienstag, 2. August 2016, 03:39:58 CEST schrieb Glyph Lefkowitz:
>>  Probably we should up-convert from bytes automatically in the places
>> where we know python will be using the values as identifiers, including
>> callRemote and the keys in a __dict__.
> 
> Attached is some grep for my port showing where I had co convert.
> 
> grep -ri -e '\(network\|native\)'
> 
> 
> 
>> This is unfortunately very tricky to know though, if we support
>> serializing both bytes and strings :-\.
> 
> Why? The wire protocol does not change. PY3 bytes are already
> compatible, and PY3 strings are serialized as unicode objects.

The protocol does change though.  ['foo'] in jelly means "bytes".  ['unicode', 'foo'] means "text".  You can fix some problems with this; obviously if you see a ['dictionary', [['unicode', 'foo'], ['unicode', 'bar']]] come in over the wire, and then get sent to setCopyableState, we can translate 'foo' back to a native 'str' in the python 2 implementation.  But what to do with 'bar'?  It will remain text.  If you extend that, and consider that your application code might have a value floating around in a variable which later gets used for a key in **kwargs or something, there's no way we can know as we're deserializing that you're going to do that, so your application is going to need to account for it manually.

Ultimately that's not a bug we can fix, so we won't.  But it's still unfortunate.

-glyph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160802/84739989/attachment-0002.html>


More information about the Twisted-Python mailing list