homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author meador.inge
Recipients alexandre.vassalotti, irmen, meador.inge, pitrou, sbt
Date 2011年12月10日.23:15:11
SpamBayes Score 3.5812906e-08
Marked as misclassified No
Message-id <1323558913.36.0.203896654475.issue13505@psf.upfronthosting.co.za>
In-reply-to
Content
I don't really know that much about pickle, but Antoine mentioned that 'bytearray'
works fine going from 3.2 to 2.7. Given that, can't we just compose 'bytes' with
'bytearray'? Something like:
Python 3.3.0a0 (default:aab45b904141+, Dec 10 2011, 13:34:41)
[GCC 4.6.2 20111027 (Red Hat 4.6.2-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
...
>>> class Bytes(bytes):
... def __reduce__(self):
... return bytes, (bytearray(self),)
... 
>>> pickletools.dis(pickle.dumps(Bytes(b'abc'), protocol=2))
 0: \x80 PROTO 2
 2: c GLOBAL '__builtin__ bytes'
 21: q BINPUT 0
 23: c GLOBAL '__builtin__ bytearray'
 46: q BINPUT 1
 48: X BINUNICODE 'abc'
 56: q BINPUT 2
 58: X BINUNICODE 'latin-1'
 70: q BINPUT 3
 72: \x86 TUPLE2
 73: q BINPUT 4
 75: R REDUCE
 76: q BINPUT 5
 78: \x85 TUPLE1
 79: q BINPUT 6
 81: R REDUCE
 82: q BINPUT 7
 84: . STOP
highest protocol among opcodes = 2
>>> pickle.dumps(Bytes(b'abc'), protocol=2)
b'\x80\x02c__builtin__\nbytes\nq\x00c__builtin__\nbytearray\nq\x01X\x03\x00\x00\x00abcq\x02X\x07\x00\x00\x00latin-1q\x03\x86q\x04Rq\x05\x85q\x06Rq\x07.'
[meadori@motherbrain cpython]$ python
Python 2.7.2 (default, Oct 27 2011, 01:40:22) 
[GCC 4.6.1 20111003 (Red Hat 4.6.1-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
...
>>> pickle.loads(b'\x80\x02c__builtin__\nbytes\nq\x00c__builtin__\nbytearray\nq\x01X\x03\x00\x00\x00abcq\x02X\x07\x00\x00\x00latin-1q\x03\x86q\x04Rq\x05\x85q\x06Rq\x07.')
'abc'
If this method is OK, then the patch is pretty simple. See attached.
History
Date User Action Args
2011年12月10日 23:15:13meador.ingesetrecipients: + meador.inge, irmen, pitrou, alexandre.vassalotti, sbt
2011年12月10日 23:15:13meador.ingesetmessageid: <1323558913.36.0.203896654475.issue13505@psf.upfronthosting.co.za>
2011年12月10日 23:15:12meador.ingelinkissue13505 messages
2011年12月10日 23:15:12meador.ingecreate

AltStyle によって変換されたページ (->オリジナル) /