diff options
author | Alexandre Vassalotti <alexandre@peadrop.com> | 2011-12-13 18:08:09 (GMT) |
---|---|---|
committer | Alexandre Vassalotti <alexandre@peadrop.com> | 2011-12-13 18:08:09 (GMT) |
commit | 3bfc65a25ba2e010ef12db0cff006c2cbbeb18f9 (patch) | |
tree | 48d1cd0accf5405ab51196dee2f68551fd9e9175 /Lib/pickle.py | |
parent | 7b7e39a61f0c784252f94eeaae8ee44a44968a6f (diff) | |
download | cpython-3bfc65a25ba2e010ef12db0cff006c2cbbeb18f9.zip cpython-3bfc65a25ba2e010ef12db0cff006c2cbbeb18f9.tar.gz cpython-3bfc65a25ba2e010ef12db0cff006c2cbbeb18f9.tar.bz2 |
Issue #13505: Make pickling of bytes object compatible with Python 2.
Initial patch by sbt.
Diffstat (limited to 'Lib/pickle.py')
-rw-r--r-- | Lib/pickle.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/pickle.py b/Lib/pickle.py index 1f45f37..d10ac776 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -487,7 +487,11 @@ class _Pickler: def save_bytes(self, obj, pack=struct.pack): if self.proto < 3: - self.save_reduce(bytes, (list(obj),), obj=obj) + if len(obj) == 0: + self.save_reduce(bytes, (), obj=obj) + else: + self.save_reduce(codecs.encode, + (str(obj, 'latin1'), 'latin1'), obj=obj) return n = len(obj) if n < 256: |