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/root/usr/lib/python3/dist-packages/docker/utils/__pycache__/utils.cpython-310.pyc
o

�2.a(5�@sjddlZddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddlm
Z
ddlmZdd	lmZdd
lmZddlmZmZdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd=d%d&�Z d'd(�Z!d>d)d*�Z"d+d,�Z#d-d.�Z$d/d0�Z%d1d2�Z&d3d4�Z'd5d6�Z(d7d8�Z)d?d9d:�Z*d;d<�Z+dS)@�N)�datetime��
StrictVersion�)�errors)�tls)�DEFAULT_HTTP_HOST)�DEFAULT_UNIX_SOCKET)�
DEFAULT_NPIPE)�
BYTE_UNITS)�
splitnport�urlparsecO�
t�d��)Nz[utils.create_ipam_pool has been removed. Please use a docker.types.IPAMPool object instead.�r�DeprecatedMethod��args�kwargs�r�4/usr/lib/python3/dist-packages/docker/utils/utils.py�create_ipam_pool��rcOr)Nz_utils.create_ipam_config has been removed. Please use a docker.types.IPAMConfig object instead.rrrrr�create_ipam_configrrcCst�|�}|�d�}t�|�S)N�utf-8)�base64�	b64decode�decode�json�loads)�header�datarrr�decode_json_header"s


r!cCs,t|�}t|�}||krdS||krdSdS)z�Compare docker versions

    >>> v1 = '1.9'
    >>> v2 = '1.10'
    >>> compare_version(v1, v2)
    1
    >>> compare_version(v2, v1)
    -1
    >>> compare_version(v2, v2)
    0
    r����r)�v1�v2�s1�s2rrr�compare_version(sr(cCst||�dkS)Nr)r(�r$r%rrr�
version_lt>sr*cCst||�S�N)r*r)rrr�version_gteBsr,cCs�ddd�}t|t�r2t|�dkr|d|d<|d|d<n7t|dt�r+|d|d<n)|d|d<n"t|t�rPd|vrL|d|d<d|vrK|d|d<nt|��||d<|ddur`d|d<|St|d�|d<|S)N�)�HostIp�HostPortrr#r/rr.)�
isinstance�tuple�len�str�dict�
ValueError)�binding�resultrrr�_convert_port_bindingFs*


��r8cCsbi}t|���D]&\}}t|�}d|vr|d7}t|t�r'dd�|D�||<qt|�g||<q|S)N�/z/tcpcSsg|]}t|��qSr)r8)�.0r6rrr�
<listcomp>i�z)convert_port_bindings.<locals>.<listcomp>)�iter�itemsr3r0�listr8)�
port_bindingsr7�k�v�keyrrr�convert_port_bindingsbs
rDcCs�t|t�r|Sg}|��D]m\}}t|t�r|�d�}t|t�red|vr1d|vr1td�t|����|d}t|t�r?|�d�}d|vrL|drIdnd}nd|vrU|d}nd}|�	|�d|�d|���q
t|t�ro|�d�}|�	|�d|�d��q
|S)	Nr�ro�modez/Binding cannot contain both "ro" and "mode": {}�bind�rw�:z:rw)
r0r?r>�bytesrr4r5�format�repr�append)�bindsr7rArBrGrFrrr�convert_volume_bindsos:




�


�

�rOcCs�t|t�r|St|t�std�t|�j���i}|D]'}t|t�r3d|vr.|�dd�\}}n|}d}n
td�t|�j���|||<q|S)Nz=Expected tmpfs value to be either a list or a dict, found: {}rIr#r-z5Expected item in tmpfs list to be a string, found: {})	r0r4r?r5rK�type�__name__r3�split)�tmpfsr7�mount�name�optionsrrr�convert_tmpfs_mounts�s(

�
�
rWcCsH|s|St|t�s
td��g}|D]}t|t�rd|i}|�|�q|S)Nz"networks parameter must be a list.�Target)r0r?�	TypeErrorr3rM)�networksr7�nrrr�convert_service_networks�s

r\cCsT|�dd�}t|�dkrt|�S|�dd�}t|�dkr&d|dvr&t|�S|dfS)N�@r#rrIr9)�rsplitr2r1)�	repo_name�partsrrr�parse_repository_tag�sraFcCs�d}d}d}|s|rtS|r|��dkrtS|��}t|�}|j}|r,tdd�|D��r5td|d�}d}|dkr>t�d��|d	ksF|d
krM|d
k}d}n|dkrSd}|d
vr_t�d|����|dkrn|jsnt�d|����t|j	|j
|j|jg�r�t�d|����|j
r�|dkr�t�d�|���|j
}|dkr�|jdur�d�|j|f�}|dvr�t|j�\}}|dus�|dkr�|dkr�t�d�|���d}|s�t}|dkr�d�|r�dnd�}n|dkr�d}|dvr�|�d|���d�S|�d|�d|�|���d�S)Nr-zunix://cSsg|]	}|tjdv�qS)�+)�string�
ascii_letters)r:�xrrrr;�szparse_host.<locals>.<listcomp>z//�tcp�fdzfd protocol is not implemented�http�https�	http+unix�unix)rfrk�npipe�sshzInvalid bind address protocol: zInvalid bind address format: rmzBInvalid bind address format: no path allowed for this protocol: {}r9)rfrmrz1Invalid bind address format: port is required: {}�zhttp{}�s)rjrlz://rI)r
�stripr	r
�scheme�anyr�DockerException�netloc�params�query�fragment�password�pathrK�hostname�joinrr�rstrip)�addr�is_win32rry�port�host�
parsed_url�protorrr�
parse_host�sz
������r�cCs�g}|D]J}t|t�r|�|�qt|t�s t�dt|�����|�d�}|rN|d}t|�dkr6|d}n|}t|�dkrC|d}nd}|�|||d��q|S)NzInvalid device type rIrr#r�rwm)�
PathOnHost�PathInContainer�CgroupPermissions)	r0r4rMr3rrsrPrRr2)�devices�device_list�device�device_mapping�path_on_host�path_in_container�permissionsrrr�
parse_devices$s2


�


��r�cCs�|stj}|�d�}|�d�pd}|�d�}|dkrd}n|du}|p$|}i}|r-||d<|s1|S|s>tj�tj�d�d�}|sF|durFd}tjtj�|d	�tj�|d
�ftj�|d�|||d�|d
<|S)N�DOCKER_HOST�DOCKER_CERT_PATH�DOCKER_TLS_VERIFYr-F�base_url�~z.dockerzcert.pemzkey.pemzca.pem)�client_cert�ca_cert�verify�ssl_version�assert_hostnamer)�os�environ�getryr{�
expanduserr�	TLSConfig)r�r��environmentr��	cert_path�
tls_verify�
enable_tlsrurrr�kwargs_from_envAs8

�
�	r�cCs\i}t|���D] \}}t|t�r|rdnd}t|t�s|g}dd�|D�||<qt�|�S)N�true�falsecSs"g|]
}t|t�s
t|�n|�qSr)r0r3)r:�itemrrrr;us��z#convert_filters.<locals>.<listcomp>)r=r>r0�boolr?r�dumps)�filtersr7rArBrrr�convert_filtersns

�
r�cCs"|t�d�}|j|jddS)z*Convert a UTC datetime to a Unix timestampr�i)r�utcfromtimestamp�seconds�days)�dt�deltarrr�datetime_to_timestamp|sr�cCs�t|ttf�r	|St|�dkrdS|dd���r1|d��r1|ddks+|ddkr1|dd�}t}|d��}|��rB|}d}n|dd�}||��vsR|��rrzt|�}Wnt	ygt
�d�|���wt|||�}|St
�d�|���)Nr���r"�b�BzAFailed converting the string value for memory ({}) to an integer.zyThe specified value for memory ({}) should specify the units. The postfix should be one of the `b` `k` `m` `g` characters)
r0�int�floatr2�isalphar�lower�isdigit�keysr5rrsrK)ro�units�suffix�digits_part�digitsrrr�parse_bytes�s8����r�cCs(t|t�rt|���}dd�t|�D�S)NcSs&g|]\}}|r|�d|��n|�qS�rIr�r:rArBrrrr;�s&z#normalize_links.<locals>.<listcomp>)r0r4r=r>�sorted)�linksrrr�normalize_links�s
r�cCs�i}t|��9}|D]-}|ddkrq	|��}|sq	|�dd�}t|�dkr.|\}}|||<q	t�d�||���Wd�|S1sBwY|S)ze
    Reads a line-separated environment file.
    The format of each line should be "key=value".
    r�#�=r#rz'Invalid line in environment file {}:
{}N)�openrprRr2rrsrK)�env_filer��f�line�
parse_linerArBrrr�parse_env_file�s,

���
��r�cCs
t�|�Sr+)�shlexrR)�commandrrr�
split_command�s
r�cs"dd���fdd�t|���D�S)NcSs.|dur|St|t�r|�d�}|�d|��S)Nrr�)r0rJr)rC�valuerrr�
format_env�s


z&format_environment.<locals>.format_envcsg|]}�|��qSrr)r:�var�r�rrr;�r<z&format_environment.<locals>.<listcomp>)r=r>)r�rr�r�format_environment�sr�cCs8|rdd�tt|����D�Sdd�tt|����D�S)NcSsg|]\}}|�d|���qS)� rr�rrrr;���z&format_extra_hosts.<locals>.<listcomp>cSsg|]\}}|�d|���qSr�rr�rrrr;�r�)r�r=r>)�extra_hosts�taskrrr�format_extra_hosts�s��r�cOr)Nz_utils.create_host_config has been removed. Please use a docker.types.HostConfig object instead.r)�selfrrrrr�create_host_config�rr�)FF)NNN)F),rrr��os.pathr�rcr�distutils.versionrr-rr�	constantsrr	r
r�urllib.parserr
rrr!r(r*r,r8rDrOrWr\rar�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sN
'

Y
-)