a
    jC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   )Zob_typeZpickle_functionZconstructor_ob© r	   ú#/usr/local/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 r€t
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@    


ýý

r.   c                 G   s   | j | g|¢R Ž S r   ©r   )r   r+   r	   r	   r
   Ú
__newobj__^   s    r0   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__a   s    r2   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Úappendr3   )r   Únamesr   ZslotsÚnameZstrippedr	   r	   r
   Ú
_slotnamesg   s2    





r?   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_registryr7   Ú_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)rC   r7   rD   rB   Ú_extension_cacherE   r	   r	   r
   r   »   s    ÿÿr   c                   C   s   t  ¡  d S r   )rI   Úclearr	   r	   r	   r
   r   Ç   s    r   )N)Ú__doc__Ú__all__r   r   r   r   Ú	NameErrorr   r   r   ÚtyperA   r   r!   r.   r0   r2   r?   rC   rD   rI   r   r   r   r	   r	   r	   r
   Ú<module>   s.   

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