Meador Inge <mead...@gmail.com> added the comment: 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. ---------- keywords: +patch Added file: http://bugs.python.org/file23907/issue13505-0.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue13505> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com