[Python-checkins] python/dist/src/Lib copy_reg.py,1.23,1.24
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 21 Feb 2003 14:20:35 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv12473
Modified Files:
copy_reg.py
Log Message:
Remove _reduce_2, it's now implemented in C.
Index: copy_reg.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/copy_reg.py,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** copy_reg.py 19 Feb 2003 01:58:53 -0000 1.23
--- copy_reg.py 21 Feb 2003 22:20:31 -0000 1.24
***************
*** 46,50 ****
_HEAPTYPE = 1<<9
! def _reduce(self):
for base in self.__class__.__mro__:
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
--- 46,53 ----
_HEAPTYPE = 1<<9
! # Python code for object.__reduce_ex__ for protocols 0 and 1
!
! def _reduce_ex(self, proto):
! assert proto < 2
for base in self.__class__.__mro__:
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
***************
*** 76,123 ****
return _reconstructor, args
! # A better version of _reduce, used by copy and pickle protocol 2
def __newobj__(cls, *args):
return cls.__new__(cls, *args)
-
- def _reduce_2(obj):
- cls = obj.__class__
- getnewargs = getattr(obj, "__getnewargs__", None)
- if getnewargs:
- args = getnewargs()
- else:
- args = ()
- getstate = getattr(obj, "__getstate__", None)
- if getstate:
- state = getstate()
- else:
- state = getattr(obj, "__dict__", None)
- names = _slotnames(cls)
- if names:
- slots = {}
- nil = []
- for name in names:
- value = getattr(obj, name, nil)
- if value is not nil:
- slots[name] = value
- if slots:
- state = (state, slots)
- listitems = dictitems = None
- if isinstance(obj, list):
- listitems = iter(obj)
- elif isinstance(obj, dict):
- dictitems = obj.iteritems()
- return __newobj__, (cls,) + args, state, listitems, dictitems
-
- # Extended reduce:
-
- def _reduce_ex(obj, proto=0):
- obj_reduce = getattr(obj, "__reduce__", None)
- if obj_reduce and obj.__class__.__reduce__ is not object.__reduce__:
- return obj_reduce()
- elif proto < 2:
- return _reduce(obj)
- else:
- return _reduce_2(obj)
def _slotnames(cls):
--- 79,86 ----
return _reconstructor, args
! # Helper for __reduce_ex__ protocol 2
def __newobj__(cls, *args):
return cls.__new__(cls, *args)
def _slotnames(cls):