a
    Ifj                     @   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	e
ej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r4|jt@ s4 qX|j}t|tr|j|u r qXqt	}|t	u rfd }n"||u rt
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 | }|rt||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   
isinstance	_new_type__self__r   r   __name____getstate__AttributeErrorgetattr__dict__r   )	selfprotor   r   newr   argsgetstatedictr   r   r   
_reduce_ex7   s@    




r1   c                 G   s   | j | g|R  S r   r   )r   r.   r   r   r   
__newobj__^   s    r3   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.
    r2   )r   r.   kwargsr   r   r   __newobj_ex__a   s    r5   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    r#   str
startswithendswithr&   lstripappendr6   )r   namesr   slotsnamestrippedr   r   r   
_slotnamesg   s2    





rD   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_registryr:   _inverted_registrymodulerB   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)rH   r:   rI   rG   _extension_cacherJ   r   r   r   r      s    r   c                   C   s   t   d S r   )rN   clearr   r   r   r   r      s    r   )N)__doc____all__r   r   r   r   	NameErrorr   r   r"   typerF   r   r$   r1   r3   r5   rD   rH   rI   rN   r   r   r   r   r   r   r   <module>   s.   

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