o Ƌ|c@sdZgdZiZdddZddZzeWn eyYn wddZeeeed d Zee e e Bed d Z d Z e e jZddZddZddZddZiZiZiZddZddZddZdS)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_extensionremove_extensionclear_extension_cacheNcCs0t|std|t|<|durt|dSdS)Nz$reduction functions must be callable)callable TypeErrordispatch_tabler)Zob_typeZpickle_functionZconstructor_obr $/opt/conda/lib/python3.10/copyreg.pyr s  rcCst|stddS)Nzconstructors must be callable)rr)objectr r r rsrcCst|j|jffSN)complexrealimag)cr r r pickle_complex"srcCs"ddl}ddl}|j|j|jffS)N) functoolsoperatorreduceor___args__)objrrr r r pickle_union'srcCs>|tur t|}|S|||}|jtjkr||||Sr )r __new____init__)clsbasestaterr r r _reconstructor/s   ric Cs|dksJ|j}|jD]}t|dr|jt@sn|j}t|tr)|j|ur)nq t }|t ur3d}n||ur@t d|j d||}|||f}z|j }Wn,t yzt|ddrgt d|j d|dz|j}Wn t ywd}YnwYnw|}|rt||fSt|fS)N __flags__zcannot 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__AttributeErrorgetattr__dict__r) selfprotorrnewrargsgetstatedictr r r _reduce_ex=sH           r5cGs|j|g|RSr r)rr2r r r __newobj__dsr7cCs|j|g|Ri|S)zUsed by pickle protocol 4, instead of __newobj__ to allow classes with keyword-only arguments to be pickled correctly. r6)rr2kwargsr r r __newobj_ex__gsr9cCs|jd}|dur |Sg}t|dsnI|jD]E}d|jvr\|jd}t|tr+|f}|D].}|dvr4q-|drV|dsV|j d}|rP| d||fq-| |q-| |q-qz||_ W|SY|S)aReturn 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 startswithendswithr*lstripappendr:)rnamesrZslotsnameZstrippedr r r _slotnamesms6         rFcCst|}d|krdkstdtd||f}t||kr*t||kr*dS|tvr8td|t|f|tvrFtd|t|f|t|<|t|<dS)zRegister an extension code.izcode 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_registrymodulerEcodekeyr r r rs&   rcCsV||f}t||kst||krtd||ft|=t|=|tvr)t|=dSdS)z0Unregister an extension code. For testing only.z%key %s is not registered with code %sN)rJr>rKrI_extension_cacherLr r r rs rcCs tdSr )rPclearr r r r rs rr )__doc____all__rrrr NameErrorrrtyperHr?rr&rr(r5r7r9rFrJrKrPrrrr r r r s6     '<