a
    c_                     @   s   d Z g dZi ZdddZdd Zze W n ey<   Y n0 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 ur(t| d S )Nz$reduction functions must be callable)callable	TypeErrordispatch_tabler   )ob_typepickle_functionconstructor_ob r   lib/python3.9/copyreg.pyr      s
    r   c                 C   s   t | stdd S )Nzconstructors must be callable)r   r   )objectr   r   r   r      s    r   c                 C   s   t | j| jffS N)complexrealimag)cr   r   r   pickle_complex"   s    r   c                 C   s<   |t u rt | }n$|| |}|jt jkr8||| |S r   )r   __new____init__)clsbasestateobjr   r   r   _reconstructor)   s    r   i   c                 C   s   |dk sJ | j }|jD ]}t|dr|jt@ s q:qt}|tu rHd }n"||u rbtd|jd|| }|||f}z
| j}W nX t	y   t
| dd rtd|jd| d z
| j}W n t	y   d }Y n0 Y n0 | }|rt||fS t|fS d S )N   	__flags__zcannot pickle z object	__slots__zf object: a class that defines __slots__ without defining __getstate__ cannot be pickled with protocol )	__class____mro__hasattrr   	_HEAPTYPEr   r   __name____getstate__AttributeErrorgetattr__dict__r   )selfprotor   r   r   argsgetstatedictr   r   r   
_reduce_ex6   s:    




r-   c                 G   s   | j | g|R  S r   r   )r   r*   r   r   r   
__newobj__Z   s    r/   c                 C   s   | j | g|R i |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__]   s    r1   c                 C   s   | j d}|dur|S g }t| ds(n| jD ]}d|j v r.|j d }t|trV|f}|D ]^}|dv rjqZqZ|dr|ds|j	d}|r|
d||f  q|
| qZ|
| qZq.z
|| _W n   Y n0 |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appendr2   )r   namesr   slotsnamestrippedr   r   r   
_slotnamesc   s2    





rA   c                 C   s   t |}d|  krdks&n td| |f}t||krNt||krNdS |tv rjtd|t| f |tv 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_registryr6   _inverted_registrymoduler?   codekeyr   r   r   r      s$    

r   c                 C   sR   | |f}t ||ks$t||kr4td||f t |= t|= |tv rNt|= dS )z0Unregister an extension code.  For testing only.z%key %s is not registered with code %sN)rE   r6   rF   rD   _extension_cacherG   r   r   r   r      s    r   c                   C   s   t   d S r   )rK   clearr   r   r   r   r      s    r   )N)__doc____all__r   r   r   r   	NameErrorr   r   r"   r-   r/   r1   rA   rE   rF   rK   r   r   r   r   r   r   r   <module>   s,   

	$<