ó
dň`Sc           @   sÖ   d  Z  d d l m Z d d d d d g Z i  Z d d  Z d	   Z y e	 Wn e
 k
 ra n Xd
   Z e e	 e e	  d   Z d Z d   Z d   Z d   Z i  Z i  Z i  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.
i˙˙˙˙(   t	   ClassTypet   picklet   constructort   add_extensiont   remove_extensiont   clear_extension_cachec         C   sf   t  |   t k r! t d   n  t | d  s? t d   n  | t |  <| d  k	 rb t |  n  d  S(   Ns-   copy_reg is not intended for use with classest   __call__s$   reduction functions must be callable(   t   typet
   _ClassTypet	   TypeErrort   hasattrt   dispatch_tablet   NoneR   (   t   ob_typet   pickle_functiont   constructor_ob(    (    s   C:\Python27\lib\copy_reg.pyR      s    
c         C   s"   t  |  d  s t d   n  d  S(   NR   s   constructors must be callable(   R
   R	   (   t   object(    (    s   C:\Python27\lib\copy_reg.pyR      s    c         C   s   t  |  j |  j f f S(   N(   t   complext   realt   imag(   t   c(    (    s   C:\Python27\lib\copy_reg.pyt   pickle_complex'   s    c         C   sY   | t  k r t  j |   } n7 | j |  |  } | j t  j k rU | j | |  n  | S(   N(   R   t   __new__t   __init__(   t   clst   baset   statet   obj(    (    s   C:\Python27\lib\copy_reg.pyt   _reconstructor.   s    i   i	   c         C   s&  x; |  j  j D]' } t | d  r | j t @r Pq q Wt } | t k rS d  } n. | |  j  k ru t d | j  n  | |   } |  j  | | f } y |  j	 } WnY t
 k
 rű t |  d d   rŃ t d   n  y |  j } Wqt
 k
 r÷ d  } qXn
 X|   } | rt | | f St | 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	   __class__t   __mro__R
   R   t	   _HEAPTYPER   R   R	   t   __name__t   __getstate__t   AttributeErrort   getattrt   __dict__R   (   t   selft   protoR   R   t   argst   getstatet   dict(    (    s   C:\Python27\lib\copy_reg.pyt
   _reduce_ex;   s.    		c         G   s   |  j  |  |  S(   N(   R   (   R   R)   (    (    s   C:\Python27\lib\copy_reg.pyt
   __newobj__\   s    c         C   s  |  j  j d  } | d k	 r" | Sg  } t |  d  s: nş xˇ |  j D]Ź } d | j  k rD | j  d } t | t  r | f } n  xl | D]a } | d k r  q q | j d  rÜ | j d  rÜ | j	 d | j
 | f  q | j	 |  q WqD qD 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&   t   getR   R
   R    t
   isinstancet
   basestringt
   startswitht   endswitht   appendR"   R.   (   R   t   namesR   t   slotst   name(    (    s   C:\Python27\lib\copy_reg.pyt
   _slotnames_   s,    c         C   sŘ   t  |  } d | k o# d k n s4 t d  n  |  | f } t j |  | k rn t j |  | k rn d S| t k r t d | t | f   n  | t k rŔ 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
   ValueErrort   _extension_registryR1   t   _inverted_registry(   t   moduleR9   t   codet   key(    (    s   C:\Python27\lib\copy_reg.pyR      s    
c         C   sw   |  | f } t  j |  | k s6 t j |  | k rO t d | | f   n  t  | =t | =| t k rs t | =n  d S(   s0   Unregister an extension code.  For testing only.s%   key %s is not registered with code %sN(   R=   R1   R>   R<   t   _extension_cache(   R?   R9   R@   RA   (    (    s   C:\Python27\lib\copy_reg.pyR   Ż   s    c           C   s   t  j   d  S(   N(   RB   t   clear(    (    (    s   C:\Python27\lib\copy_reg.pyR   ť   s    Ni   (   t   __doc__t   typesR    R   t   __all__R   R   R   R   R   t	   NameErrorR   R   R!   R,   R-   R:   R=   R>   RB   R   R   R   (    (    (    s   C:\Python27\lib\copy_reg.pyt   <module>   s.   					!		8		