
    Rh                         d Z g dZi ZddZd Zd Z eeee       d Z e ee	e
z        e       d ZdZ ee	j                        Zd	 Zd
 Zd Zd Zi Zi Zi Zd Zd Zd Zy)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                 ^    t        |      st        d      |t        | <   |t        |       y y )Nz$reduction functions must be callable)callable	TypeErrordispatch_tabler   )ob_typepickle_functionconstructor_obs      /usr/lib/python3.12/copyreg.pyr   r      s5    O$>??-N7 !N# "    c                 0    t        |       st        d      y )Nzconstructors must be callable)r   r	   )objects    r   r   r      s    F788 r   c                 >    t         | j                  | j                  ffS N)complexrealimag)cs    r   pickle_complexr      s    QVVQVV$$$r   c                 Z    dd l }dd l}|j                  |j                  | j                  ffS )N    )	functoolsoperatorreduceor___args__)objr   r   s      r   pickle_unionr!   !   s#    hllCLL999r   c                     |t         u rt         j                  |       }|S |j                  | |      }|j                  t         j                  k7  r|j                  ||       |S r   )r   __new____init__)clsbasestater    s       r   _reconstructorr(   )   sS    v~nnS!
 J ll3&==FOO+MM#u%Jr   i   c                    |dk  sJ | j                   }|j                  D ]P  }t        |d      r|j                  t        z  s n5|j
                  }t        |t              sA|j                  |u sP n t        }|t        u rd }n%||u rt        d|j                  d       ||       }|||f}	 | j                  }t        |       j                  t        j                  u rt        | dd       rt        d       |       }|r	t"        ||fS t"        |fS # t        $ rK t        | dd       rt        d|j                  d|       d 	 | j                   }n# t        $ r d }Y nw xY wY fw xY w)N   	__flags__zcannot pickle z object	__slots__zNa class that defines __slots__ without defining __getstate__ cannot be pickledzf 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__typegetattrAttributeError__dict__r(   )	selfprotor%   r&   newr'   argsgetstatedicts	            r   
_reduce_exr@   7   s   199
..C 4%dnny.Hllc9%#,,$*> v~3;nS\\,<GDEET
uD$$ J##v':'::D+t, F G GztT))t##'  	4d+nS\\,< =- .3G5 6 <@@	==D 	D		s6   /D 2E&EE&E E&E  E&%E&c                 (     | j                   | g| S r   r#   )r%   r=   s     r   
__newobj__rC   b   s    3;;s"T""r   c                 .     | j                   | g|i |S )zUsed by pickle protocol 4, instead of __newobj__ to allow classes with
    keyword-only arguments to be pickled correctly.
    rB   )r%   r=   kwargss      r   __newobj_ex__rF   e   s     3;;s,T,V,,r   c                    | j                   j                  d      }||S g }t        | d      sn| j                  D ]  }d|j                   v s|j                   d   }t	        |t
              r|f}|D ]  }|dv r|j                  d      rW|j                  d      sF|j                  j                  d      }|r|j                  d||       ^|j                  |       p|j                  |         	 || _        |S #  Y |S xY w)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__r,   )r9   __weakref_____)r9   getr/   r.   r1   str
startswithendswithr4   lstripappendrH   )r%   namesr   slotsnamestrippeds         r   
_slotnamesrV   k   s    LL_-E E3$  	+Aajj(

;/eS)"HE! +D:: .t}}T7J#$::#4#4S#9#!LLHd)CD!LL.T*+	+*! LLs   7D   Dc                 l   t        |      }d|cxk  rdk  st        d       t        d      | |f}t        j                  |      |k(  rt        j                  |      |k(  ry|t        v rt        d|dt        |         |t        v rt        d|dt        |         |t        |<   |t        |<   y)	zRegister an extension code.   izcode out of rangeNkey z! is already registered with code zcode z is already in use for key )int
ValueError_extension_registryrL   _inverted_registrymodulerT   codekeys       r   r   r      s    t9D"
",-- #,--4.C$,t$+
!!2379 : 	:!! 24 8: ; 	;#"tr   c                     | |f}t         j                  |      |k7  st        j                  |      |k7  rt        d|d|      t         |= t        |= |t        v rt        |= yy)z0Unregister an extension code.  For testing only.rY   z is not registered with code N)r\   rL   r]   r[   _extension_cacher^   s       r   r   r      sn    4.C$,t$+t% & 	&C 4 T"  r   c                  ,    t         j                          y r   )rc   clear r   r   r   r      s    r   r   )__doc____all__r
   r   r   r   r   r!   r6   rZ   rM   r(   r0   r#   r2   r@   rC   rF   rV   r\   r]   rc   r   r   r   rf   r   r   <module>ri      s   I $9% w (: tC#I % 		'$V#-1x    #$
#r   