L i! BddlmZmZmZddlmZddlmZddlmZddl m Z e eesejedZ dZ dZe ee eeeeeeeeiZiZGd d eZGd d eZd ddZ ddZdZe e eeeeeiZiZdZeDcgc]}|c}eDcgc]}|c}zZ dZ!eeefZ" ddZ#e#jHe jHejHejHejHejHejHfZ%[[[ [[[[ycc}wcc}w))MutableMappingMutableSequence MutableSet)Enum)MappingProxyType)array frozendictc~ddlm}t||jxr t|t xr t |d S)Nrabcisalpha) collectionsr isinstanceIterable memoryviewhasattror s U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/frozendict/cool.pyisIterableNotStringrs> 1cll# " q* %% " Ay !!cddlm}t||js t dt||j rt jStS)Nrr zobject must be an iterable) rr rr TypeErrorMappingdictitems enumeraters rgetItemsrs= a &455!S[[!zz rc|SNxs rnilr%&s Hrc eZdZy) FreezeErrorN__name__ __module__ __qualname__r"rrr'r'5rr'c eZdZy) FreezeWarningNr(r"rrr.r.9r,rr.F)inversecVtt|tstd|d |j|r t }n t }||vr'ddl}|j|jdt|rt}nt}|||<y#t$rtd|dzwxYw)a Adds a `converter` for a type `to_convert`. `converter` must be callable. The new converter will be used by `deepfreeze()` and has precedence over any previous converter. If `to_covert` has already a converter, a FreezeWarning is raised. If `inverse` is True, the conversion is considered from an immutable type to a mutable one. This make it possible to convert mutable objects nested in the registered immutable one. z'`to_convert` parameter must be a type, z foundz*`converter` parameter must be a callable, foundrNz! is already in the conversion map) issubclasstype ValueError__call__AttributeErrorgetFreezeConversionInverseMapgetFreezeConversionMapwarningswarnr)r.%_freeze_conversion_inverse_map_custom_freeze_conversion_map_custom) to_convert converterr/freeze_conversion_mapr9s rregisterr@=s d:& -5j\ H    = ? 6 8** ""##D E   E =(1*%1  8 D     s B B(ct|rt}nt} ||=y#t$rt|jdwxYw)z Unregister a type from custom conversion. If `inverse` is `True`, the unregistered conversion is an inverse conversion (see `register()`). z is not registeredN)r;r<KeyErrorr'r))r3r/r?s r unregisterrClsI E =@ !$ ' @T]]O+=>??@s"7cttzSr!)_freeze_conversion_mapr<r"rrr8r8~s !$A AArcttzSr!)_freeze_conversion_inverse_mapr;r"rrr7r7s&- .rctttDcgc]}|c}ztDcgc]}|c}zScc}wcc}wr!)tuple _freeze_typesr<r;r#s rgetFreezeTypesrKs> 12q2 39:q: ; 2:s : ? Ncddlm}||}||}|jD]<\}}tt|tst |ddz |j >|jD]<\}}tt|tst |d d z |j >t|}t|jtz}d}|D]} t|| s| }n| |j||jSt} | |z} |t vr | ||St#|s | ||St%} | |z} || v}|r | ||}ddlm}||}t)||D]\}}t+|||||< | |}||S#t $rt d|ddzwxYw#t $rt d|d d zwxYw#t $rYnwxYw t||S#t$rYnwxYwd jd|D} d|dd| z} t| #t,$r |r|}nYwxYw)a  Converts the object and all the objects nested in it in its immutable counterparts. The conversion map is in getFreezeConversionMap(). You can register a new conversion using `register()` You can also pass a map of custom converters with `custom_converters` and a map of custom inverse converters with `custom_inverse_converters`, without using `register()`. By default, if the type is not registered and has a `__dict__` attribute, it's converted to the `frozendict` of that `__dict__`. This function assumes that hashable == immutable (that is not always true). This function uses recursion, with all the limits of recursions in Python. Where is a good old tail call when you need it? rr Nz+ in `custom_converters` parameter is not a r3zconverter for z in `custom_converters` zparameter is not a callablez* in `custom_inverse_converters` parameter z is not a typez in z6`custom_inverse_converters`parameter is not a callablez, c34K|]}|jywr!)r)).0r$s r zdeepfreeze..s$FAQZZ$Fsztype z& is not hashable or is not equal or a z!subclass of the supported types: )copy)custom_converterscustom_inverse_converters)r rr2r3r4r5r6rIkeysrKr__dict__hashrjoinr8_freeze_types_plainrr7rPr deepfreezerB)rrQrRr type_ir>type_o freeze_types base_type_o freeze_typesupported_typeserrr?freeze_conversion_inverse_map frozen_typerPo_copykvfreezes rrXrXs:8& &L ($.L!.446  $v,-(EF       7<<>  $v,-(DE        !WF*//12^5EELK# a %%K   * JJajj) )(3414EE))1$[1!44 q !1$[1!44$A$C! &! "" !>>K 6 )+ 6q 9 !WF  ( 1 1(A q  &{3 &>K  (@A-.    .HI  ,      G H    ))$F$FGF8A B//@ A B nJ  F  sN F>) G G<1I>GG9< HH H H%$H%I)(I))F)NN)&collections.abcrrrenumrtypesrrr r2r@rrr% bytearraybytesrI frozensetrEr< Exceptionr' UserWarningr.rCr8rlistrGr;r7rJrKrWrXr)__all__r#s0rrpsGG"! %)OU#  $J uU # %!# )  K 27,2^@$B",d 4-" )+%''1Q'./1Q/0 "9e4 !$(Rl ##!**  k(/s  D$ D