B
    \ ci                 @   s   d Z dddddgZi ZdddZdd Zye W n ek
rD   Y nX d	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   s,   t |std|t| < |d k	r(t| d S )Nz$reduction functions must be callable)callable	TypeErrordispatch_tabler   )ob_typepickle_functionconstructor_ob r   lib/python3.7/copyreg.pyr      s
    c             C   s   t | std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   s<   |t krt | }n$|| |}|jt jkr8||| |S )N)r   __new____init__)clsbasestateobjr   r   r   _reconstructor)   s    r   i   c             C   s   |dk st x*| jjD ]}t|dr|jt@ sP qW t}|tkrFd }n || jkr^td|j || }| j||f}y
| j	}W nN t
k
r   t| dd rtdd y
| j}W n t
k
r   d }Y nX Y nX | }|rt||fS t|fS d 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   s2    



r-   c             G   s   | j | f| S )N)r   )r   r*   r   r   r   
__newobj__W   s    r.   c             C   s   | j | f||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    r0   c             C   s   | j d}|dk	r|S g }t| ds(nx| jD ]}d|j kr0|j d }t|trX|f}xf|D ]^}|dkrnq^q^|dr|ds|j	d}|r|
d||f  q|
| q^|
| q^W q0W y
|| _W n   Y n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)r'   getr!   r    
isinstancestr
startswithendswithr#   lstripappendr1   )r   namesr   slotsnamestrippedr   r   r   
_slotnames`   s2    





r@   c             C   s   t |}d|  krdks&n td| |f}t||krNt||krNdS |tkrjtd|t| f |tkrtd|t| f |t|< |t|< dS )zRegister an extension code.   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_registryr5   _inverted_registry)moduler>   codekeyr   r   r   r      s    c             C   sR   | |f}t ||ks$t||kr4td||f t |= t|= |tkrNt|= dS )z0Unregister an extension code.  For testing only.z%key %s is not registered with code %sN)rD   r5   rE   rC   _extension_cache)rF   r>   rG   rH   r   r   r   r      s    c               C   s   t   d S )N)rI   clearr   r   r   r   r      s    )N)__doc____all__r   r   r   r   	NameErrorr   r   r"   r-   r.   r0   r@   rD   rE   rI   r   r   r   r   r   r   r   <module>   s.   


	!<