mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #13505: Make pickling of bytes object compatible with Python 2.
Initial patch by sbt.
This commit is contained in:
parent
7b7e39a61f
commit
3bfc65a25b
5 changed files with 94 additions and 57 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue