Message149232
| Author |
sbt |
| Recipients |
alexandre.vassalotti, irmen, meador.inge, pitrou, sbt |
| Date |
2011年12月11日.18:17:53 |
| SpamBayes Score |
1.2738578e-06 |
| Marked as misclassified |
No |
| Message-id |
<1323627474.18.0.266166234145.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'?
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. |
|