mirror of
https://github.com/python/cpython.git
synced 2025-08-22 01:35:16 +00:00
Issue #17711: Fixed unpickling by the persistent ID with protocol 0.
Original patch by Alexandre Vassalotti.
This commit is contained in:
parent
6fd76bceda
commit
dec25afab1
5 changed files with 89 additions and 22 deletions
|
@ -529,7 +529,11 @@ class _Pickler:
|
|||
self.save(pid, save_persistent_id=False)
|
||||
self.write(BINPERSID)
|
||||
else:
|
||||
self.write(PERSID + str(pid).encode("ascii") + b'\n')
|
||||
try:
|
||||
self.write(PERSID + str(pid).encode("ascii") + b'\n')
|
||||
except UnicodeEncodeError:
|
||||
raise PicklingError(
|
||||
"persistent IDs in protocol 0 must be ASCII strings")
|
||||
|
||||
def save_reduce(self, func, args, state=None, listitems=None,
|
||||
dictitems=None, obj=None):
|
||||
|
@ -1075,7 +1079,11 @@ class _Unpickler:
|
|||
dispatch[FRAME[0]] = load_frame
|
||||
|
||||
def load_persid(self):
|
||||
pid = self.readline()[:-1].decode("ascii")
|
||||
try:
|
||||
pid = self.readline()[:-1].decode("ascii")
|
||||
except UnicodeDecodeError:
|
||||
raise UnpicklingError(
|
||||
"persistent IDs in protocol 0 must be ASCII strings")
|
||||
self.append(self.persistent_load(pid))
|
||||
dispatch[PERSID[0]] = load_persid
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue