HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/cwd/usr/lib/python3/dist-packages/compose/__pycache__/utils.cpython-310.pyc
o

S�`�@s2ddlZddlZddlZddlZddlZddlmZddlm	Z
ddlmZddl
mZddl
m
Z
e��Ze�e�Zdd	�Zd5dd�Zdd
d�fdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Z	d%d&�Z d'd(�Z!d)d*�Z"d+d�fd,d-�Z#d6d/d0�Z$d1d2d�fd3d4�Z%dS)7�N)�DockerException)�parse_bytes�)�StreamParseError)�MULTIPLIERS��	timeparseccs,�|D]}t|t�s|�dd�}|VqdS)z�Given a stream of bytes or text, if any of the items in the stream
    are bytes convert them to text.

    This function can be removed once docker-py returns text streams instead
    of byte streams.
    zutf-8�replaceN)�
isinstance�str�decode)�stream�data�r�//usr/lib/python3/dist-packages/compose/utils.py�stream_as_texts�
�r�
cCs:|�t|��}|dkr
dS|d|d�||dd�fS)N���r)�findr)�buffer�	separator�indexrrr�
line_splitter s rcC�|S�Nr)�arrr�<lambda>'�rc
cs��|pt}d}t|�D]}||7}	||�}|durn|\}}|Vqq|rHz||�VWdStyG}z
t�dt|��t|��d}~wwdS)aGiven a generator which yields strings and a splitter function,
    joins all input, splits on the separator and yields each chunk.

    Unlike string.split(), each chunk includes the trailing
    separator, except for the last one if none was found on the end
    of the input.
    �TNz?Compose tried decoding the following data chunk, but failed:
%s)rr�	Exception�log�error�reprr)r
�splitter�decoder�bufferedr�buffer_split�item�errr�split_buffer's4�������r)cCsR|��}zt�|�\}}|tjj�||���d�}||fWSty(YdSw)z�Attempt to parse a json object from a buffer. If there is at least one
    object, return it and the rest of the buffer, otherwise return None.
    N)	�strip�json_decoder�
raw_decode�jsonr$�
WHITESPACE�match�end�
ValueError)r�objr�restrrr�
json_splitterGs
�r4cCst|ttj�S)z�Given a stream of text, return a stream of json objects.
    This handles streams which are inconsistently buffered (some entries may
    be newline delimited, and others are not).
    )r)r4r+r)r
rrr�json_streamTsr5cCs6tj|dddd�d�}t��}|�|�d��|��S)NT)�,�:cSs|��Sr)r"��xrrrr]szjson_hash.<locals>.<lambda>)�	sort_keys�
separators�default�utf8)r-�dumps�hashlib�sha256�update�encode�	hexdigest)r2�dump�hrrr�	json_hash\srFcCst|dd�S)Niʚ;i�)�int)�	time_nanorrr�microseconds_from_time_nanoc�rIcCst|td�S)N�nano)rGr)�time_secondsrrr�nanoseconds_from_time_secondsgrJrMcCst|pd�S�Nrr��valuerrr�parse_seconds_floatksrQcCs t|pd�}|durdSt|�SrN)rrM)rP�parsedrrr�parse_nanoseconds_intosrScCsdd�|��D�S)NcSs&i|]\}}|t|dur|nd��qSrN)r)�.0�k�vrrr�
<dictcomp>ws&z%build_string_dict.<locals>.<dictcomp>)�items)�source_dictrrr�build_string_dictvsrZcCs.t|�dkrdS|ddvrd|fSt�|�S)Nr)rr)�.�\�/�~r)�len�ntpath�
splitdrive)�pathrrrrazs

racCs zt|�WStyYdSwr)�sdk_parse_bytesr)�nrrrr�s

�rcCs0|s|S|ddkr|ddkr|dd�S|S)Nr�"rrr)�srrr�unquote_path�s
rgcCs@	tt�d��dd�}ztt|��Wqty|YSw)NT��r)�hex�random�getrandbitsrG�truncate_idr1)�valrrr�generate_random_id�s�rocCs:d|vr||�d�dd�}t|�dkr|dd�S|S)Nr7r�)rr_rOrrrrm�s
rmcCrrrr8rrrr�rccs6�t�}|D]}||�}||vr|�|�|VqdS)zHList unique elements, preserving order. Remember all elements ever seen.N)�set�add)�iterable�key�seen�element�
unique_keyrrr�unique_everseen�s�
��rx�#cCs$t|�|kr|d|d�dS|S)Nriz...)r_)rf�	max_charsrrr�truncate_string�sr{FcCrrrr8rrrr�rcs |s�s|S��fdd�|D�S)aThis function contains the logic of choosing which services to
    attach when doing docker-compose up. It may be used both with containers
    and services, and any other entities that map to service names -
    this mapping is provided by item_to_service_name.csg|]
}�|��vr|�qSrr)rTr'��item_to_service_name�
service_namesrr�
<listcomp>�s�z*filter_attached_for_up.<locals>.<listcomp>r)rXr~�attach_dependenciesr}rr|r�filter_attached_for_up�s
�r�)r)ry)&r?�json.decoderr-�loggingr`rk�
docker.errorsr�docker.utilsrrc�errorsrrr�JSONDecoderr+�	getLogger�__name__r rrr)r4r5rFrIrMrQrSrZrargrormrxr{r�rrrr�<module>sB


 



�