
    g                     L   d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 d dlmZ eeeeefZ e j&                  e      Zdedej,                  dee   d	ee
ej,                  e	e
eeef   d
f   f      fdZdej,                  dee   d	eej,                     fdZ G d de      Zy)    N)OrderedDict)MutableMapping)OptionalSequenceTupleUnion)typeskeyvaluemax_lenreturn.c           
         | rt        | t              st        j                  d|        yt        |t              rt        ||      S t        |t              rd}g }|D ]  }t        ||      }||j                  |       #t        |      }|t        vr@t        j                  d|j                  | t        D cg c]  }|j                   c}        y||}n<||k7  r7t        j                  d| |j                  t        |      j                          y|j                  |        t        |      S t        j                  dt        |      j                  | t        D cg c]  }|j                   c}       yc c}w c c}w )ak  Checks if attribute value is valid and cleans it if required.

    The function returns the cleaned value or None if the value is not valid.

    An attribute value is valid if it is either:
        - A primitive type: string, boolean, double precision floating
            point (IEEE 754-1985) or integer.
        - An array of primitive type values. The array MUST be homogeneous,
            i.e. it MUST NOT contain values of different types.

    An attribute needs cleansing if:
        - Its length is greater than the maximum allowed length.
        - It needs to be encoded/decoded e.g, bytes to strings.
    z+invalid key `%s`. must be non-empty string.NzLInvalid type %s in attribute '%s' value sequence. Expected one of %s or Nonez>Attribute %r mixes types %s and %s in attribute value sequencezYInvalid type %s for attribute '%s' value. Expected one of %s or a sequence of those types)
isinstancestr_loggerwarning_VALID_ATTR_VALUE_TYPES_clean_attribute_valuer   appendtype__name__tuple)r
   r   r   sequence_first_valid_typecleaned_seqelementelement_type
valid_types           V/var/www/openai/venv/lib/python3.12/site-packages/opentelemetry/attributes/__init__.py_clean_attributer      s   $ JsC(EsK%01%eW55%"$(!G,Wg>G""7+=L#::! )) +B*AJ #++*A	  )0,8)!::T-66M**	 w'G L [!!OO	"U/FG/F		/FG C> 	Hs   6E9E>limitc                     | y t        | t              r	 | j                         } |t        | t              r| d | } | S # t        $ r t        j                  d       Y y w xY w)Nz$Byte attribute could not be decoded.)r   bytesdecodeUnicodeDecodeErrorr   r   r   )r   r    s     r   r   r   n   sh     }%	LLNE
 Zs3fuL " 	OOBC	s   > AAc            
           e Zd ZdZ	 	 	 	 ddee   dej                  dedee   fdZ	de
fd	Zd
e
dej                  fdZd
e
dej                  ddfdZd
e
ddfdZd ZdefdZd Zy)BoundedAttributeszAn ordered dict with a fixed max capacity.

    Oldest elements are dropped when the dict is full and a new element is
    added.
    Nmaxlen
attributes	immutablemax_value_lenc                     | t        |t              r|dk  rt        d      || _        d| _        || _        i | _        t        j                         | _	        |r|j                         D ]
  \  }}|| |<    || _        y )Nr   z.maxlen must be valid int greater or equal to 0)r   int
ValueErrorr'   droppedr*   _dict	threadingRLock_lockitems
_immutable)selfr'   r(   r)   r*   r
   r   s          r   __init__zBoundedAttributes.__init__   s     fc*fqj D  *  	
 __&
(..0
U!S	 1#    r   c                 .    t        | j                         S N)dictr/   r5   s    r   __repr__zBoundedAttributes.__repr__   s    tzz"#$r7   r
   c                      | j                   |   S r9   )r/   r5   r
   s     r   __getitem__zBoundedAttributes.__getitem__   s    zz#r7   r   c                    t        | dd      rt        | j                  5  | j                  .| j                  dk(  r| xj                  dz  c_        	 d d d        y t        ||| j                        }||| j                  v r| j                  |= n| j                  t        | j                        | j                  k(  ret        | j                  t              st        | j                        | _        | j                  j                  d       | xj                  dz  c_        || j                  |<   d d d        y # 1 sw Y   y xY w)Nr4   Fr      )last)getattr	TypeErrorr2   r'   r.   r   r*   r/   lenr   r   popitem)r5   r
   r   s      r   __setitem__zBoundedAttributes.__setitem__   s    4u-OZZ{{&4;;!+;! Z
 %S%1C1CDE $**$

3KK+DJJ4;;0N%djj+>%0%<
JJ&&E&2LLA%L"'

3# ZZs   2D;CD;;Ec                     t        | dd      rt        | j                  5  | j                  |= d d d        y # 1 sw Y   y xY w)Nr4   F)rC   rD   r2   r/   r>   s     r   __delitem__zBoundedAttributes.__delitem__   s/    4u-OZZ

3 ZZs	   7A c                     | j                   5  t        | j                  j                               cd d d        S # 1 sw Y   y xY wr9   )r2   iterr/   copyr;   s    r   __iter__zBoundedAttributes.__iter__   s&    ZZ

)* ZZs	   #:Ac                 ,    t        | j                        S r9   )rE   r/   r;   s    r   __len__zBoundedAttributes.__len__   s    4::r7   c                 6    | j                   j                         S r9   )r/   rL   r;   s    r   rL   zBoundedAttributes.copy   s    zz  r7   )NNTN)r   
__module____qualname____doc__r   r,   r	   
Attributesboolr6   r   r<   AttributeValuer?   rG   rI   rM   rO   rL    r7   r   r&   r&      s     !%'+'+$$ $$$ 	$
  }$6%# %s u';'; (s (5+?+? (D (, s  t  + !r7   r&   )loggingr0   collectionsr   collections.abcr   typingr   r   r   r   opentelemetry.utilr	   rU   r   r"   r,   floatr   	getLoggerr   r   rV   r   r   r&   rW   r7   r   <module>r_      s      # * 3 3 $  eS%8  '

H
%L	L))L4<SMLeE((%c3o0F0K*LLMNL^(0e""#$L! L!r7   