o
    Ei!                     @   s^  d dl mZmZmZ d dlmZ d dlmZ d dlmZ d dl	m	Z	 e
ees,ee dd Zdd	 Zd
d Ze	ee	eeeeeeeeiZi ZG dd deZG dd deZddddZd"ddZdd Ze	e	eeeeeiZi Zdd Zdd eD dd eD  Z dd Z!eeefZ"		d#d d!Z#e#j$ej$ej$ej$ej$ej$ej$fZ%[[[	[[[[dS )$    )MutableMappingMutableSequence
MutableSet)Enum)MappingProxyType)array
frozendictc                 C   s0   ddl m} t| |jot| t ot| d S )Nr   abcisalpha)collectionsr   
isinstanceIterable
memoryviewhasattror    r   L/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/frozendict/cool.pyisIterableNotString   s   

r   c                 C   s6   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   r   r   r   getItems   s   r   c                 C   s   | S Nr   )xr   r   r   nil&   s   r   c                   @      e Zd ZdS )FreezeErrorN__name__
__module____qualname__r   r   r   r   r!   5       r!   c                   @   r    )FreezeWarningNr"   r   r   r   r   r'   9   r&   r'   F)inversec                C   s   t t| tstd|  dz|j W n ty$   td| d w |r+t }nt }| |v r@ddl}|| j	 dt
 |rEt}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, foundr   Nz! is already in the conversion map)
issubclasstype
ValueError__call__AttributeErrorgetFreezeConversionInverseMapgetFreezeConversionMapwarningswarnr#   r'   %_freeze_conversion_inverse_map_custom_freeze_conversion_map_custom)
to_convert	converterr(   freeze_conversion_mapr1   r   r   r   register=   s4   


r8   c                 C   s:   |rt }nt}z|| = W dS  ty   t| j d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)r3   r4   KeyErrorr!   r#   )r+   r(   r7   r   r   r   
unregisterl   s   r:   c                   C      t tB S r   )_freeze_conversion_mapr4   r   r   r   r   r0   ~   s   r0   c                   C   r;   r   )_freeze_conversion_inverse_mapr3   r   r   r   r   r/      s   r/   c                 C      g | ]}|qS r   r   .0r   r   r   r   
<listcomp>       rA   c                 C   r>   r   r   r?   r   r   r   rA      rB   c                   C   s$   t tdd tD  dd tD  S )Nc                 S   r>   r   r   r?   r   r   r   rA      rB   z"getFreezeTypes.<locals>.<listcomp>c                 S   r>   r   r   r?   r   r   r   rA      rB   )tuple_freeze_typesr4   r3   r   r   r   r   getFreezeTypes   s   rE   Nc              	   C   sx  ddl m } |du r| }|du r| }| D ]*\}}tt|ts,t| dd z|j W q tyB   td| dd w | D ]*\}}tt|ts[t| d	d
 z|j W qG tyq   td| dd w t| }t| t	  }d}|D ]}	t
| |	r|	} nq|du rz| j W n	 ty   Y nw || jS zt|  W | S  ty   Y nw ddd |D }
d| dd|
  }t|t }||B }|tv r|| | S t| s|| | S t }||B }||v }|r|| | } ddlm} || }t||D ]\}}t|||d||< qz	|| }W ||S  ty;   |r5|}n Y ||S 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                 s   s    | ]}|j V  qd S r   )r#   r?   r   r   r   	<genexpr>  s    zdeepfreeze.<locals>.<genexpr>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-   r.   rC   keysrE   r   __dict__hashr   joinr0   _freeze_types_plainr   r/   rG   r   
deepfreezer9   )r   rH   rI   r	   type_ir6   type_ofreeze_typesbase_type_ofreeze_typesupported_typeserrr7   freeze_conversion_inverse_mapfrozen_typerG   o_copykvfreezer   r   r   rO      s   









rO   )F)NN)&collections.abcr   r   r   enumr   typesr   r   r	   r*   r8   r   r   r   	bytearraybytesrC   	frozensetr<   r4   	Exceptionr!   UserWarningr'   r:   r0   r   listr=   r3   r/   rD   rE   rN   rO   r#   __all__r   r   r   r   <module>   sn    



/

 
