mò
­fIc           @   sÙ   d  Z  d k l Z d d d d d g Z h  Z d d „ Z d „  Z y e	 Wn e
 j
 o n Xd	 „  Z e e	 e e	 ƒ d
 „  Z d d >Z d „  Z d „  Z d „  Z h  Z h  Z h  Z d „  Z d „  Z d „  Z d S(   s¬   Helper to provide extensibility for pickle/cPickle.

This is only useful to add pickle support for extension types defined in
C, not for instances of user-defined classes.
(   s	   ClassTypet   picklet   constructort   add_extensiont   remove_extensiont   clear_extension_cachec         C   si   t  |  ƒ t j o t d ƒ ‚ n t | ƒ p t d ƒ ‚ n | t |  <| d  j	 o t	 | ƒ n d  S(   Ns-   copy_reg is not intended for use with classess$   reduction functions must be callable(
   t   typet   ob_typet
   _ClassTypet	   TypeErrort   callablet   pickle_functiont   dispatch_tablet   constructor_obt   NoneR   (   R   R
   R   (    (    t%   /mit/python/lib/python2.4/copy_reg.pyR       s    
c         C   s!   t  |  ƒ p t d ƒ ‚ n d  S(   Ns   constructors must be callable(   R	   t   objectR   (   R   (    (    R   R      s    c         C   s   t  |  i |  i f f S(   N(   t   complext   ct   realt   imag(   R   (    (    R   t   pickle_complex'   s    c         C   sF   | t j o t i |  ƒ } n# | i |  | ƒ } | i | | ƒ | S(   N(   t   baseR   t   __new__t   clst   objt   statet   __init__(   R   R   R   R   (    (    R   t   _reconstructor.   s
    i   i	   c         C   s8  x> |  i i D]* } t | d ƒ o | i t @o Pq q Wt } | t j o
 d  } n1 | |  i j o t
 d | i ‚ n | |  ƒ } |  i | | f } y |  i } Wn_ t j
 oS t |  d d  ƒ o t
 d ƒ ‚ n y |  i } Wqt j
 o d  } qXn X| ƒ  } | o t | | f Sn t | f Sd  S(   Nt	   __flags__s   can't pickle %s objectst	   __slots__sN   a class that defines __slots__ without defining __getstate__ cannot be pickled(   t   selft	   __class__t   __mro__R   t   hasattrR   t	   _HEAPTYPER   R   R   R   t   __name__t   argst   __getstate__t   getstatet   AttributeErrort   getattrt   __dict__t   dictR   (   R   t   protoR$   R&   R   R   R*   (    (    R   t
   _reduce_ex:   s2      	
	c         G   s   |  i |  | Œ S(   N(   R   R   R$   (   R   R$   (    (    R   t
   __newobj__[   s    c         C   s  |  i i d ƒ } | d j	 o | Sn g  } t |  d ƒ p nÄ xÀ |  i D]µ } d | i j oŸ | i d } t	 | t
 ƒ o | f } n xr | D]f } | d j o q’ q’ | i d ƒ o/ | i d ƒ o | i d | i | f ƒ q’ | i | ƒ q’ WqK qK Wy | |  _ Wn n X| S(	   s›  Return a list of slot names for a given class.

    This needs to find slots defined by the class and its bases, so we
    can't simply return the __slots__ attribute.  We must walk down
    the Method Resolution Order and concatenate the __slots__ of each
    class found there.  (This assumes classes don't modify their
    __slots__ attribute to misrepresent their slots after the class is
    defined.)
    t   __slotnames__R   R)   t   __weakref__t   __s   _%s%sN(   s   __dict__s   __weakref__(   R   R)   t   gett   namesR   R!   R    R   t   slotst
   isinstancet
   basestringt   namet
   startswitht   endswitht   appendR#   R.   (   R   R   R6   R2   R3   (    (    R   t
   _slotnames^   s2    	 
  !c         C   så   t  | ƒ } d | j o
 d j n p t d ‚ n |  | f } t i | ƒ | j o t i | ƒ | j o d Sn | t j o t d | t | f ƒ ‚ n | t j o t d | t | f ƒ ‚ n | t | <| t | <d S(   s   Register an extension code.i   iÿÿÿs   code out of rangeNs)   key %s is already registered with code %ss$   code %s is already in use for key %s(	   t   intt   codet
   ValueErrort   moduleR6   t   keyt   _extension_registryR1   t   _inverted_registry(   R>   R6   R<   R?   (    (    R   R   œ   s     ,
c         C   s|   |  | f } t i | ƒ | j p t i | ƒ | j o t d | | f ƒ ‚ n t | =t | =| t j o t | =n d S(   s0   Unregister an extension code.  For testing only.s%   key %s is not registered with code %sN(	   R>   R6   R?   R@   R1   R<   RA   R=   t   _extension_cache(   R>   R6   R<   R?   (    (    R   R   ®   s     ,c           C   s   t  i ƒ  d  S(   N(   RB   t   clear(    (    (    R   R   º   s    N(   t   __doc__t   typest	   ClassTypeR   t   __all__R   R   R    R   R   t	   NameErrorR   R   R"   R,   R-   R:   R@   RA   RB   R   R   R   (   RA   R   RG   R@   RB   R   R-   R"   R,   R   R   R   R   R   R:   R    R   (    (    R   t   ?   s,   			
	!		8		