a
    ´ij  ã                   @   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 )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   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   ú/usr/lib64/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  | j }|jD ]:}t|dƒr(|jt@ s( qL|j}t|tƒr|j|u r qLqt	}|t	u rZd }n"||u rtt
d|j›d�ƒ‚|| ƒ}|||f}z
| j}W nX tyè   t| dd ƒrÂt
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>    


ýý

r0   c                 G   s   | j | g|¢R Ž S r   ©r   )r   r-   r   r   r   Ú
__newobj__^   s    r2   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.
    r1   )r   r-   Úkwargsr   r   r   Ú__newobj_ex__a   s    r4   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Úappendr5   )r   Únamesr   ÚslotsÚnameÚstrippedr   r   r   Ú
_slotnamesg   s2    





rC   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 r†t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_registryr9   Ú_inverted_registry©ÚmodulerA   Ú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)rG   r9   rH   rF   Ú_extension_cacherI   r   r   r   r   »   s    ÿÿr   c                   C   s   t  ¡  d S r   )rM   Úclearr   r   r   r   r   Ç   s    r   )N)Ú__doc__Ú__all__r   r   r   r   Ú	NameErrorr   r   r!   ÚtyperE   r   r#   r0   r2   r4   rC   rG   rH   rM   r   r   r   r   r   r   r   Ú<module>   s.   

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