sbt <shibt...@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'?

Yes, although it would only work for 2.6 and 2.7.

codecs.encode() seems to be available back to 2.4 and codecs.latin_1_encode() 
back to at least 2.0.  They also produce more compact pickles, particularly 
codecs.latin_1_encode().

>>> class Bytes(bytes):
...     def __reduce__(self):
...         return latin_1_encode, (latin_1_decode(self),)
...
[70922 refs]
>>> pickletools.dis(pickle.dumps(Bytes(b'abc'), 2))
    0: \x80 PROTO      2
    2: c    GLOBAL     '_codecs latin_1_encode'
   26: q    BINPUT     0
   28: X    BINUNICODE 'abc'
   36: q    BINPUT     1
   38: K    BININT1    3
   40: \x86 TUPLE2
   41: q    BINPUT     2
   43: \x85 TUPLE1
   44: q    BINPUT     3
   46: R    REDUCE
   47: q    BINPUT     4
   49: .    STOP
highest protocol among opcodes = 2

Only worry is that codecs.latin_1_encode.__module__ is '_codecs', and _codecs 
is undocumented.

----------

_______________________________________
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

Reply via email to