o
    i                     @   s4   d dl Z d dlZG dd deZG dd deZdS )    Nc                   @   s   e Zd ZdZdS )UnresolvableContainerIDz1
    Unable to get container ID from cgroup.
    N)__name__
__module____qualname____doc__ r   r   V/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/vendor/dogstatsd/container.pyr   
   s    r   c                   @   sN   e Zd ZdZdZdZdZdZe	dZ
e	deeeZdd	 Zd
d ZdS )ContainerIDa$  
    A reader class that retrieves the current container ID parsed from a the cgroup file.

    Returns:
    object: ContainerID

    Raises:
        `NotImplementedError`: No proc filesystem is found (non-Linux systems)
        `UnresolvableContainerID`: Unable to read the container ID
    z/proc/self/cgroupzH[0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}z[0-9a-f]{64}z[0-9a-f]{32}-\d+z^(\d+):([^:]*):(.+)$z!(?:.+)?({0}|{1}|{2})(?:\.scope)?$c                 C   s   |  | j| _d S )N)_read_container_idCGROUP_PATHcontainer_id)selfr   r   r   __init__#   s   zContainerID.__init__c           	   
   C   s   z[t |ddJ}|D ]=}| }| j|}|sq
| \}}}dd |dD }t|rG| j| }|rG|	d  W  d    W S q
W d    W d S 1 sTw   Y  W d S  t
y| } z|jtjkrqtd| jW Y d }~d S d }~w ty } ztdt| d }~ww )	Nr)modec                 S   s   g | ]}|qS r   r   ).0pr   r   r   
<listcomp>/   s    z2ContainerID._read_container_id.<locals>.<listcomp>/   zUnable to open {}.z!Unable to read the container ID: )openstripLINE_REmatchgroupssplitlenCONTAINER_REpopgroupIOErrorerrnoENOENTNotImplementedErrorformatr   	Exceptionr   str)	r   fpathfpliner   _pathpartser   r   r   r
   &   s<   
zContainerID._read_container_idN)r   r   r   r   r   UUID_SOURCECONTAINER_SOURCETASK_SOURCErecompiler   r$   r   r   r
   r   r   r   r   r	      s    
r	   )r!   r1   r%   r   objectr	   r   r   r   r   <module>   s   