
    g)                         d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m	Z	 d Z
d Z G d d	e      Z e	d
       G d de             Zy)    N)deque)MutableMappingSequence)Optional)
deprecatedc                     t         j                   j                  | dz  t         j                  j                        }|j	                  d      S )z*Get an ISO 8601 string from time_ns value.g    eA)tzz%Y-%m-%dT%H:%M:%S.%fZ)datetimefromtimestamptimezoneutcstrftime)nanosecondstss     T/var/www/openai/venv/lib/python3.12/site-packages/opentelemetry/sdk/util/__init__.pyns_to_iso_strr      sE    				(	(ch//33 
) 
B ;;.//    c           	      \    t        t        t        d | j                                           S )z*Converts a dict to be used as a unique keyc                 R    t        | d   t              r| d   t        | d         fS | S )N   r   )
isinstancelisttuple)kvs    r   <lambda>z!get_dict_as_key.<locals>.<lambda>%   s+    -71t-DRUE"Q%L)L"Lr   )r   sortedmapitems)labelss    r   get_dict_as_keyr        s/     		
	 	r   c                   V    e Zd ZdZdee   fdZd Zd Zd Z	d Z
d Zd	 Zed
        Zy)BoundedListzAn append only list with a fixed max size.

    Calls to `append` and `extend` will drop the oldest elements if there is
    not enough room.
    maxlenc                 f    d| _         t        |      | _        t        j                         | _        y )Nr   )r#   )droppedr   _dq	threadingLock_lockselfr#   s     r   __init__zBoundedList.__init__5   s#    '^^%
r   c                     t        |       j                   dt        | j                         d| j                  j                   dS N(z	, maxlen=))type__name__r   r&   r#   r+   s    r   __repr__zBoundedList.__repr__:   s9    t*%%&aTXX'7y@QQRSSr   c                      | j                   |   S N)r&   )r+   indexs     r   __getitem__zBoundedList.__getitem__=   s    xxr   c                 ,    t        | j                        S r6   )lenr&   r3   s    r   __len__zBoundedList.__len__@   s    488}r   c                     | j                   5  t        t        | j                              cd d d        S # 1 sw Y   y xY wr6   )r)   iterr   r&   r3   s    r   __iter__zBoundedList.__iter__C   s#    ZZdhh( ZZs   5>c                 *   | j                   5  | j                  j                  At        | j                        | j                  j                  k(  r| xj                  dz  c_        | j                  j                  |       d d d        y # 1 sw Y   y xY w)Nr   )r)   r&   r#   r:   r%   append)r+   items     r   r@   zBoundedList.appendG   sW    ZZ+MTXX__4!HHOOD! ZZs   A3B		Bc                 L   | j                   5  | j                  j                  Rt        |      t        | j                        z   | j                  j                  z
  }|dkD  r| xj                  |z  c_        | j                  j                  |       d d d        y # 1 sw Y   y xY wNr   )r)   r&   r#   r:   r%   extend)r+   seqto_drops      r   rD   zBoundedList.extendP   si    ZZxx*c(S]2TXX__DQ;LLG+LHHOOC  ZZs   BBB#c                 N    t        |      } | |      }|j                  |       |S r6   )r   rD   )clsr#   rE   bounded_lists       r   from_seqzBoundedList.from_seqX   s(    Cj6{C r   N)r2   
__module____qualname____doc__r   intr,   r4   r8   r;   r>   r@   rD   classmethodrJ    r   r   r"   r"   .   sJ    &x} &
T)"!  r   r"   z1.4.0)versionc                   V    e Zd ZdZdee   fdZd Zd Zd Z	d Z
d Zd	 Zed
        Zy)BoundedDictzAn ordered dict with a fixed max capacity.

    Oldest elements are dropped when the dict is full and a new element is
    added.
    r#   c                     |!t        |t              st        |dk  rt        || _        d| _        i | _        t        j                         | _        y rC   )	r   rN   
ValueErrorr#   r%   _dictr'   r(   r)   r*   s     r   r,   zBoundedDict.__init__h   sH    fc*  z  
^^%
r   c                 x    t        |       j                   dt        | j                         d| j                   dS r.   )r1   r2   dictrV   r#   r3   s    r   r4   zBoundedDict.__repr__s   s6    Dz""#1T$**%5$6i}AN	
r   c                      | j                   |   S r6   rV   r+   keys     r   r8   zBoundedDict.__getitem__x   s    zz#r   c                    | j                   5  | j                  .| j                  dk(  r| xj                  dz  c_        	 d d d        y || j                  v r| j                  |= nz| j                  nt	        | j                        | j                  k(  rL| j                  t        t        | j                  j                                     = | xj                  dz  c_        || j                  |<   d d d        y # 1 sw Y   y xY w)Nr   r   )r)   r#   r%   rV   r:   nextr=   keys)r+   r\   values      r   __setitem__zBoundedDict.__setitem__{   s    ZZ{{&4;;!+;! Z
 djj JJsO(S_-KJJtD):$;<=!#DJJsO ZZs   2C6B%C66C?c                     | j                   |= y r6   rZ   r[   s     r   __delitem__zBoundedDict.__delitem__   s    JJsOr   c                     | j                   5  t        | j                  j                               cd d d        S # 1 sw Y   y xY wr6   )r)   r=   rV   copyr3   s    r   r>   zBoundedDict.__iter__   s&    ZZ

)* ZZs	   #:Ac                 ,    t        | j                        S r6   )r:   rV   r3   s    r   r;   zBoundedDict.__len__   s    4::r   c                 f    t        |      } | |      }|j                         D ]
  \  }}|||<    |S r6   )rX   r   )rH   r#   mappingbounded_dictr\   r`   s         r   from_mapzBoundedDict.from_map   s8    w-6{!--/JC %L *r   N)r2   rK   rL   rM   r   rN   r,   r4   r8   ra   rc   r>   r;   rO   rj   rP   r   r   rS   rS   `   sI    	&x} 	&

$+  r   rS   )r
   r'   collectionsr   collections.abcr   r   typingr   r   r   r    r"   rS   rP   r   r   <module>rn      sP       4  !0/( /d G7. 7 7r   