
    HaH                         d Z ddlZej                  dk  rddlmZ nddlmZ ddlmZ ddlm	Z	m
Z
mZ  e
e      Ze	 G d d	e             Zy)
z$ Dot notation support for Mappings.     N)   r   )Mapping   )
AttMapLike)copy
get_loggersafedel_messagec                   f    e Zd ZdZd Zd Zd Zd Zd Ze	d        Z
d Zed	        Zd
 Zd Zd Zy)AttMapa  
    A class to convert a nested mapping(s) into an object(s) with key-values
    using object syntax (attmap.attribute) instead of getitem syntax
    (attmap["key"]). This class recursively sets mappings to objects,
    facilitating attribute traversal (e.g., attmap.attr.attr).
    c                 z    	 | j                   |= y # t        $ r! t        j                  t	        |             Y y w xY wN)__dict__KeyError_LOGGERdebugr	   )selfkeys     -lib/python3.12/site-packages/attmap/attmap.py__delitem__zAttMap.__delitem__   s3    	0c" 	0MM/#./	0s    '::c                      | j                   |   S r   )r   )r   items     r   __getitem__zAttMap.__getitem__   s    }}T""    c                 B    | j                  ||      | j                  |<   y)a*  
        This is the key to making this a unique data type.

        :param str key: name of the key/attribute for which to establish value
        :param object value: value to which set the given key; if the value is
            a mapping-like object, other keys' values may be combined.
        N)_final_for_storer   )r   r   values      r   __setitem__zAttMap.__setitem__"   s     "223>cr   c                 ,   t        |       t        |      k7  st        |       t        |      k7  ry| j                         D ]R  \  }}| j                  |      r%t        j                  dj                  |             <| j                  |||         rR y y)NFzExcluding from comparison: {}T)typelenitems_excl_from_eqr   r   format_cmp)r   otherkvs       r   __eq__zAttMap.__eq__.   s    J$u+%3t9E
+BJJL 	DAq!!!$=DDQGH99Qa)	 r   c                     | |k(   S r    )r   r%   s     r   __ne__zAttMap.__ne__:   s    5=  r   c                     d
d} || |ddg      s || |dg      rd }n || |dg      rd }nd }	  || |      S # t         $ r Y y	w xY w)zAHook to tailor value comparison in determination of map equality.c                 x    t        | j                        t        |j                        }}|r
||v xr ||v S ||k(  S r   )str	__class__)obj1obj2	typenamest1t2s        r   	same_typezAttMap._cmp.<locals>.same_typeA   s<    (#dnn*=B<EB)O7iS2QS8Sr   z<type 'numpy.ndarray'>z<class 'numpy.ndarray'>z#<class 'pandas.core.series.Series'>c                 (    | |k(  j                         S r   allxys     r   <lambda>zAttMap._cmp.<locals>.<lambda>H   s    !q& r   z%<class 'pandas.core.frame.DataFrame'>c                 D    | |k(  j                         j                         S r   r7   r9   s     r   r<   zAttMap._cmp.<locals>.<lambda>J   s    !q&!3!3!5 r   c                     | |k(  S r   r*   r9   s     r   r<   zAttMap._cmp.<locals>.<lambda>L   s
    a r   Fr   )
ValueError)abr5   checks       r   r$   zAttMap._cmp=   st    	T q+-FG
q!CDE/Eq!EFG5E'E	A; 	 	s   < 	AAc                 t    t        |t              r't        || j                        s| j                  |      }|S )z
        Before storing a value, apply any desired transformation.

        :param hashable k: key for which to store value
        :param object v: value to potentially transform before storing
        :return object: finalized value
        )
isinstancer   _lower_type_bound_metamorph_maplike)r   r&   r'   s      r   r   zAttMap._final_for_storeT   s2     a!*Q8N8N*O''*Ar   c                     t         S r   )r   r   s    r   rE   zAttMap._lower_type_bound`   s    r   c                     t        |t              s$t        dj                  |t	        |                  | j                  |j                               S )a"  
        Ensure a stored Mapping conforms with type expectation.

        :param Mapping m: the mapping to which to apply type transformation
        :return Mapping: a (perhaps more specialized) version of the given map
        :raise TypeError: if the given value isn't a Mapping
        z+Cannot integrate a non-Mapping: {}
Type: {})rD   r   	TypeErrorr#   r   rE   r!   )r   ms     r   rF   zAttMap._metamorph_mapliked   sH     !W%>EEaaQ  %%aggi00r   c                     t               S )zDReturn the empty collection builder for Mapping type simplification.)dictrH   s    r   _new_empty_basic_mapzAttMap._new_empty_basic_mapr   s	    vr   c                 F    |j                  |st        |             S d      S )a1  
        IPython display; https://ipython.readthedocs.io/en/stable/api/generated/IPython.lib.pretty.html

        :param IPython.lib.pretty.PrettyPrinter p: printer instance
        :param bool cycle: whether a cyclic reference is detected
        :return str: text representation of the instance
        z...)textrepr)r   pcycles      r   _repr_pretty_zAttMap._repr_pretty_v   s!     vvd4j99599r   N)__name__
__module____qualname____doc__r   r   r   r(   r+   staticmethodr$   r   propertyrE   rF   rN   rT   r*   r   r   r   r      s\    0#
?
!  ,
  1:r   r   )rX   sysversion_infocollectionsr   collections.abc_att_map_liker   helpersr   r   r	   rU   r   r   r*   r   r   <module>ra      sP    * 
f#' % 6 6
X
 m:Z m: m:r   