
[[\                 @   s   d  Z  d d d d d g Z i  Z d d d  Z d d   Z y e Wn e k
 rX Yn Xd	 d
   Z e e e e  d d   Z d Z	 d d   Z
 d d   Z d d   Z d d   Z i  Z i  Z i  Z d d   Z d d   Z d d   Z d S)zHelper to provide extensibility for pickle.

This is only useful to add pickle support for extension types defined in
C, not for instances of user-defined classes.
pickleconstructoradd_extensionremove_extensionclear_extension_cacheNc             C   sB   t  |  s t d   n  | t |  <| d  k	 r> t |  n  d  S)Nz$reduction functions must be callable)callable	TypeErrordispatch_tabler   )ob_typepickle_functionconstructor_ob r   /usr/lib/python3.4/copyreg.pyr      s
    
c             C   s   t  |   s t d   n  d  S)Nzconstructors must be callable)r   r   )objectr   r   r   r      s    c             C   s   t  |  j |  j f f S)N)complexrealimag)cr   r   r   pickle_complex"   s    r   c             C   sY   | t  k r t  j |   } n7 | j |  |  } | j t  j k rU | j | |  n  | S)N)r   __new____init__)clsbasestateobjr   r   r   _reconstructor)   s    r      	   c             C   s=  | d k  s t   x; |  j j D]' } t | d  r | j t @r Pq q Wt } | t k re d  } n1 | |  j k r t d | j   n  | |   } |  j | | f } y |  j	 } Wn[ t
 k
 rt |  d d   r t d   n  y |  j } Wn t
 k
 rd  } Yn XYn
 X|   } | r/t | | f St | f Sd  S)N   	__flags__zcan't pickle %s objects	__slots__zNa class that defines __slots__ without defining __getstate__ cannot be pickled)AssertionError	__class____mro__hasattrr   	_HEAPTYPEr   r   __name____getstate__AttributeErrorgetattr__dict__r   )selfprotor   r   argsgetstatedictr   r   r   
_reduce_ex6   s0    		r/   c             G   s   |  j  |  |  S)N)r   )r   r,   r   r   r   
__newobj__W   s    r0   c             C   s   |  j  |  | |  S)zUsed by pickle protocol 4, instead of __newobj__ to allow classes with
    keyword-only arguments to be pickled correctly.
    )r   )r   r,   kwargsr   r   r   __newobj_ex__Z   s    r2   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 Yn X| S)	a  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.)
    __slotnames__Nr   r)   __weakref____z_%s%s)z__dict__z__weakref__)r)   getr#   r"   
isinstancestr
startswithendswithappendr%   r3   )r   namesr   slotsnamer   r   r   
_slotnames`   s,    r?   c             C   s   t  |  } d | k o# d k n s7 t d   n  |  | f } t j |  | k rq t j |  | k rq d S| t k r t d | t | f   n  | t k r t d | t | f   n  | t | <| t | <d S)zRegister an extension code.r   izcode out of rangeNz)key %s is already registered with code %sz$code %s is already in use for key %s)int
ValueError_extension_registryr6   _inverted_registry)moduler>   codekeyr   r   r   r      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)z0Unregister an extension code.  For testing only.z%key %s is not registered with code %sN)rB   r6   rC   rA   _extension_cache)rD   r>   rE   rF   r   r   r   r      s    c               C   s   t  j   d  S)N)rG   clearr   r   r   r   r      s    i   )__doc____all__r   r   r   r   	NameErrorr   r   r$   r/   r0   r2   r?   rB   rC   rG   r   r   r   r   r   r   r   <module>   s.   
	!8