
    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d eD             d eD             z   Zd ZeeefZ 	 	 ddZ!e!j"        e
j"        ej"        ej"        ej"        ej"        ej"        fZ#[[[dS )    )MappingProxyType)array
frozendictN)MutableMappingMutableSequence
MutableSetc                     ddl m} t          | |j                  o&t          | t                     ot          | d           S )Nr   abcisalpha)collectionsr   
isinstanceIterable
memoryviewhasattror   s     /lib/python3.11/site-packages/frozendict/cool.pyisIterableNotStringr      sT     	1cl## 	"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      sY    a&& 64555!S[!! zr   c                       e Zd ZdS )FreezeErrorN__name__
__module____qualname__ r   r   r    r    .           Dr   r    c                       e Zd ZdS )FreezeWarningNr!   r%   r   r   r(   r(   2   r&   r   r(   F)inversec                ~   t          t          |           t                    st          d|  d          	 |j         n## t          $ r t          d| dz             w xY w|rt                      }nt                      }| |v r"t          j        | j	         dt                     |rt          }nt          }||| <   dS )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:&&-- 
HjHHH
 
 	

 
 
 
DDD
 
 	

  9 = ? ? 6 8 8***"EEE	
 	
 	

  > E =(1*%%%s	   ?  Ac                 z    |rt           }nt          }	 || = dS # 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   sg      > E =@!$''' @ @ @T]>>>???@s    ":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                     g | ]}|S r%   r%   .0xs     r   
<listcomp>rG      s    '''1Q'''r   c                     g | ]}|S r%   r%   rD   s     r   rG   rG      s    ///1Q///r   c                  r    t          t          d t          D             z   d t          D             z             S )Nc                     g | ]}|S r%   r%   rD   s     r   rG   z"getFreezeTypes.<locals>.<listcomp>   s    222q222r   c                     g | ]}|S r%   r%   rD   s     r   rG   z"getFreezeTypes.<locals>.<listcomp>   s    :::q:::r   )tuple_freeze_typesr6   r5   r%   r   r   getFreezeTypesrN      sE    221222	3::9:::	;  r   c                    ddl m } |
 |            }|
 |            }|                                D ]h\  }}t          t          |          t                    st	          | ddz             	 |j         E# t          $ r t	          d| ddz             w xY w|                                D ]h\  }}t          t          |          t                    st	          | d	d
z             	 |j         E# t          $ r t	          d| ddz             w xY wt          |           }t          |                                          t                      z   }d}|D ]}	t          | |	          r|	} n|	 | j          || j                  S # t          $ r Y nw xY w	 t          |            | S # t          $ r Y nw xY wd                    d |D                       }
d| dd|
 z   }t          |          t                      }||z  }|t           v r ||         |           S t#          |           s ||         |           S t%                      }||z  }||v }|r ||         |           } ddlm}  ||           } t)          |          |          D ]\  }}t+          |||          ||<   	 ||         }n# t,          $ r	 |r|}n Y nw xY w ||          S )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   $   K   | ]}|j         V  d S r?   )r"   rD   s     r   	<genexpr>zdeepfreeze.<locals>.<genexpr>   s$      $F$FAQZ$F$F$F$F$F$Fr   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   rL   keysrN   r   __dict__hashr   joinr2   _freeze_types_plainr   r1   rR   r   
deepfreezer<   )r   rS   rT   r   type_ir8   type_ofreeze_typesbase_type_ofreeze_typesupported_typeserrr9   freeze_conversion_inverse_mapfrozen_typerR   o_copykvfreezes                       r   rZ   rZ      sF   8 &%%%%% &JLL ($.JLL!.4466  	$v,,-- 	FFF  
	 	 	 	AAAA-.  	 7<<>>  	$v,,-- 	EEE   
	 	 	 	....HI  	 !WWF*//1122^5E5EELK#  a%% 	%KE	 	*JJ :aj)))  	 	 	D	
	GGG H  	 	 	D	 ))$F$F$F$F$FGG CFBBBAAAB 	
 nn24414EE)))1$[1!444q!! 51$[1!444$A$C$C! 	&!	" "
 !>>K :6)+6q99T!WWF   (( 
 
1 1(A
 
 
q		&{3    	FF F 6&>>sN   0A88!B-C55!D6F 
FFF/ /
F<;F<5J> >KK)F)NN)$typesr   r   r   r3   collections.abcr   r   r	   r,   r:   r   r   	bytearraybytesrL   	frozensetr@   r6   	Exceptionr    UserWarningr(   r=   r2   r   listrB   r5   r1   rM   rN   rY   rZ   r"   __all__r%   r   r   <module>rq      sk   " " " " " "       ! ! ! ! ! !  G G G G G G G G G G
 z%)) $OU###  	 	 	 $JuU		%    !# 	 	 	 	 	) 	 	 		 	 	 	 	K 	 	 	 27 *2 *2 *2 *2 *2Z@ @ @ @$B B B ",d	4- " "  )+ %   ('&'''//.///0    "9e4 
 !$(P P P Ph #!* 	JJr   