o
    éT•j  ã                   @   sÊ   d Z g d¢Zi Zddd„Zdd„ Zze W n	 ey   Y nw dd„ Zeeeeƒ d	d
„ Zee	e
eB ƒ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 )z¤Helper 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   s0   t |ƒstdƒ‚|t| < |d urt|ƒ d S d S )Nz$reduction functions must be callable)ÚcallableÚ	TypeErrorÚdispatch_tabler   )Úob_typeÚpickle_functionÚconstructor_ob© r   ú/usr/lib/python3.10/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"   dd l }dd l}|j|j| jffS )Né    )Ú	functoolsÚoperatorÚreduceÚor_Ú__args__)Úobjr   r   r   r   r   Úpickle_union'   s   r   c                 C   s>   |t u rt  | ¡}|S | | |¡}|jt jkr| ||¡ |S r   )r   Ú__new__Ú__init__)ÚclsÚbaseÚstater   r   r   r   Ú_reconstructor/   s   
ýr"   i   c           	      C   s  |dk sJ ‚| j }|jD ]}t|dƒr|jt@ s n|j}t|tƒr)|j|u r) nqt	}|t	u r3d }n||u r@t
d|j›d�ƒ‚|| ƒ}|||f}z| j}W n, tyz   t| dd ƒrgt
d|j›d|› �ƒd ‚z| j}W n tyw   d }Y nw Y nw |ƒ }|r…t||fS t|f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_ex=   sH   
€

ýý
ÿ€ø
r8   c                 G   s   | j | g|¢R Ž S r   ©r   )r   r5   r   r   r   Ú
__newobj__d   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.
    r9   )r   r5   Úkwargsr   r   r   Ú__newobj_ex__g   s   r<   c                 C   sÔ   | j  d¡}|dur|S g }t| dƒsnI| jD ]E}d|j v r\|j d }t|tƒr+|f}|D ].}|dv r4q-| d¡rV| d¡sV|j 	d¡}|rP| 
d||f ¡ q-| 
|¡ q-| 
|¡ q-qz|| _W |S    Y |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%   )r1   Ú__weakref__Ú__Ú_z_%s%s)r1   Úgetr(   r'   r*   ÚstrÚ
startswithÚendswithr-   ÚlstripÚappendr=   )r   Únamesr   ÚslotsÚnameÚstrippedr   r   r   Ú
_slotnamesm   s6   




€ýrK   c                 C   s    t |ƒ}d|  krdkstdƒ‚ tdƒ‚| |f}t |¡|kr*t |¡|kr*dS |tv r8td|t| f ƒ‚|tv rFt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_registryrA   Ú_inverted_registry©ÚmodulerI   ÚcodeÚkeyr   r   r   r   ¯   s&   ÿ
ÿ
ÿr   c                 C   sV   | |f}t  |¡|kst |¡|krtd||f ƒ‚t |= t|= |tv r)t|= dS dS )z0Unregister an extension code.  For testing only.z%key %s is not registered with code %sN)rO   rA   rP   rN   Ú_extension_cacherQ   r   r   r   r   Á   s   ÿ
ÿr   c                   C   s   t  ¡  d S r   )rU   Úclearr   r   r   r   r   Í   s   r   r   )Ú__doc__Ú__all__r   r   r   r   Ú	NameErrorr   r   ÚtyperM   rB   r"   r)   r   r+   r8   r:   r<   rK   rO   rP   rU   r   r   r   r   r   r   r   Ú<module>   s6    

ÿ	
'<