
    Gf               
       ,   d dl mZ d dlmZ d dlmZ d dlZd dlmZmZmZ  e	ee      s ej                  e       d Zd Z eeeeeeeeei      Zi Z G d d	e      Z G d
 de      ZdddZ
ddZd Z eeeeeeei      Zi Zd ZeD  cg c]  } |  c} eD  cg c]  } |  c} z   Zd ZeeefZ 	 	 ddZ!e!jD                  e
jD                  ejD                  ejD                  ejD                  ejD                  ejD                  fZ#[[[yc c} w c c} w )    )MappingProxyType)array
frozendictN)MutableMappingMutableSequence
MutableSetc                 ~    ddl m} t        | |j                        xr  t        | t               xr t        | d       S )Nr   abcisalpha)collectionsr   
isinstanceIterable
memoryviewhasattror   s     /lib/python3.12/site-packages/frozendict/cool.pyisIterableNotStringr      s>     	1cll# 	"q*%%	"Ay!!    c                     ddl m} t        | |j                        st	        d      t        | |j
                        rt        j                  S t        S )Nr   r   zobject must be an iterable)	r   r   r   r   	TypeErrorMappingdictitems	enumerater   s     r   getItemsr      s=    a&455!S[[!zzr   c                       e Zd Zy)FreezeErrorN__name__
__module____qualname__ r   r   r    r    .       r   r    c                       e Zd Zy)FreezeWarningNr!   r%   r   r   r(   r(   2   r&   r   r(   F)inversec                V   t        t        |       t              st        d|  d      	 |j                   |rt               }n
t               }| |v r't        j                  | j                   dt               |rt        }nt        }||| <   y# t        $ r t        d| dz         w xY w)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, foundz! is already in the conversion mapN)
issubclasstype
ValueError__call__AttributeErrorgetFreezeConversionInverseMapgetFreezeConversionMapwarningswarnr"   r(   %_freeze_conversion_inverse_map_custom_freeze_conversion_map_custom)
to_convert	converterr)   freeze_conversion_maps       r   registerr:   6   s     d:&-5j\H
 	

  = ? 6 8**""##DE	

  E =(1*%-  
8D
 	

s   B B(c                 t    |rt         }nt        }	 || = y# t        $ r t        | j                   d      w xY w)z
    Unregister a type from custom conversion. If `inverse` is `True`,
    the unregistered conversion is an inverse conversion
    (see `register()`).
    z is not registeredN)r5   r6   KeyErrorr    r"   )r-   r)   r9   s      r   
unregisterr=   c   sI      E =@!$' @T]]O+=>??@s    "7c                      t         t        z  S N)_freeze_conversion_mapr6   r%   r   r   r2   r2   u   s    !$AAAr   c                      t         t        z  S r?   )_freeze_conversion_inverse_mapr5   r%   r   r   r1   r1      s    &-	.r   c                      t        t        t        D  cg c]  } |  c} z   t        D  cg c]  } |  c} z         S c c} w c c} w r?   )tuple_freeze_typesr6   r5   xs    r   getFreezeTypesrH      s>    12q2	39:q:	; 2:s   	:
	?
c                    ddl m } | |       }| |       }|j                         D ]<  \  }}t        t        |      t              st	        | ddz         	 |j
                   > |j                         D ]<  \  }}t        t        |      t              st	        | d	d
z         	 |j
                   > t        |       }t        |j                               t               z   }d}|D ]  }	t        | |	      s|	} n |	 | j                    || j                        S t               }||z  }|t         v r ||   |       S t#        |       s ||   |       S t%               }||z  }||v }|r ||   |       } ddlm}  ||       } t)        |      |      D ]  \  }}t+        |||      ||<    	 ||   } ||      S # t        $ r t	        d| ddz         w xY w# t        $ r t	        d| ddz         w xY w# t        $ r Y nw xY w	 t        |        | S # t        $ r Y nw xY wdj                  d |D              }
d| dd|
 z   }t        |      # t,        $ r	 |r|}n Y w xY w)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?
    r   r   Nz+ in `custom_converters` parameter is not a r-   zconverter for z in `custom_converters` zparameter is not a callablez* in `custom_inverse_converters` parameter zis not a typez in  z6`custom_inverse_converters`parameter is not a callablez, c              3   4   K   | ]  }|j                     y wr?   )r"   ).0rG   s     r   	<genexpr>zdeepfreeze.<locals>.<genexpr>   s     $FAQZZ$Fs   ztype z& is not hashable or is not equal or a z!subclass of the supported types: )copy)custom_converterscustom_inverse_converters)r   r   r,   r-   r.   r/   r0   rD   keysrH   r   __dict__hashr   joinr2   _freeze_types_plainr   r1   rM   r   
deepfreezer<   )r   rN   rO   r   type_ir8   type_ofreeze_typesbase_type_ofreeze_typesupported_typeserrr9   freeze_conversion_inverse_mapfrozen_typerM   o_copykvfreezes                       r   rU   rU      s:   8 & &L ($.L!.446 	$v,-(EF 
	 7<<> 	$v,-(DE  
	 !WF*//12^5EELK# a%%K
 	*JJ ajj))( 3414EE))1$[1!44q!1$[1!44$A$C! 	&!	" "
 !>>K6)+6q9!WF  ( 
1 1(A
q	
&{3 &>G  	 (@A-. 	  	 .HI 	(  		
	G H  		 ))$F$FG F8AB//@AB 	
 nJ  F sN   F>)GG< 1I >GG9<	HHH 	H%$H%I)(I))F)NN)$typesr   r   r   r3   collections.abcr   r   r	   r,   r:   r   r   	bytearraybytesrD   	frozensetr@   r6   	Exceptionr    UserWarningr(   r=   r2   r   listrB   r5   r1   rE   rH   rT   rU   r"   __all__rF   s   0r   <module>rl      so   "  !  G G
 %)OU#	 $JuU		%   !# 	) 		K 	 27 *2Z@$B ",d	4- "  )+ % ''1Q'./1Q/0  "9e4 
 !$(Ph ##!** 	_ (/s   	D	D