Message72850
The pickle system has an undocumented but very useful feature. When the
first element of the tuple returned by __reduce__ is a function named
__newobj__, a special obcode is generated. __newobj__ doesn't need to be
registered as safe for unpickling, too.
From pickle.py:
# use the more efficient NEWOBJ opcode, while still
# allowing protocol 0 and 1 to work normally. For this to
# work, the function returned by __reduce__ should be
# called __newobj__, and its first argument should be a
# new-style class. The implementation for __newobj__
# should be as follows, although pickle has no way to
# verify this:
#
# def __newobj__(cls, *args):
# return cls.__new__(cls, *args)
#
# Protocols 0 and 1 will pickle a reference to __newobj__,
# while protocol 2 (and above) will pickle a reference to
# cls, the remaining args tuple, and the NEWOBJ code,
# which calls cls.__new__(cls, *args) at unpickling time
# (see load_newobj below). If __reduce__ returns a
# three-tuple, the state from the third tuple item will be
# pickled regardless of the protocol, calling __setstate__
# at unpickling time (see load_build below).
#
# Note that no standard __newobj__ implementation exists;
# you have to provide your own. This is to enforce
# compatibility with Python 2.2 (pickles written using
# protocol 0 or 1 in Python 2.3 should be unpicklable by
# Python 2.2). |
|
Date |
User |
Action |
Args |
2008-09-09 12:13:14 | christian.heimes | set | recipients:
+ christian.heimes, georg.brandl |
2008-09-09 12:13:14 | christian.heimes | set | messageid: <1220962394.03.0.479554047795.issue3816@psf.upfronthosting.co.za> |
2008-09-09 12:13:13 | christian.heimes | link | issue3816 messages |
2008-09-09 12:13:12 | christian.heimes | create | |
|