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: //lib/python3/dist-packages/docker/api/__pycache__/client.cpython-310.pyc
o

a_a�I�@s�ddlZddlZddlZddlmZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZddlmZmZmZmZddlmZddlmZmZdd	lmZmZm Z mZdd
l!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(d
dl)m*Z*d
dlm+Z+d
dl,m-Z-d
dl.m/Z/d
dl0m1Z1d
dl2m3Z3d
dl4m5Z5d
dl6m7Z7d
dl8m9Z9d
dl:m;Z;d
dl<m=Z=d
dl>m?Z?zddlm@Z@Wn	eAy�YnwzddlmBZBWn	eAy�YnwGdd�dejCe*e+e-e/e1e3e5e7e9e;e=e?�ZDdS)�N)�partial�)�auth)�DEFAULT_NUM_POOLS�DEFAULT_NUM_POOLS_SSH�DEFAULT_MAX_POOL_SIZE�DEFAULT_TIMEOUT_SECONDS�DEFAULT_USER_AGENT�IS_WINDOWS_PLATFORM�MINIMUM_DOCKER_API_VERSION�STREAM_HEADER_SIZE_BYTES)�DockerException�InvalidVersion�TLSParameterError�$create_api_error_from_http_exception)�	TLSConfig)�SSLHTTPAdapter�UnixHTTPAdapter)�check_resource�config�update_headers�utils)�json_stream)�ProxyConfig)�consume_socket_output�
demux_adaptor�frames_iter�)�
BuildApiMixin)�ConfigApiMixin)�ContainerApiMixin)�DaemonApiMixin)�ExecApiMixin)�
ImageApiMixin)�NetworkApiMixin)�PluginApiMixin)�SecretApiMixin)�ServiceApiMixin)�
SwarmApiMixin)�VolumeApiMixin)�NpipeHTTPAdapter)�SSHHTTPAdapterc	sReZdZdZejjgd�Zddededdde	f	�fdd�	Z
dd�Zd	d
�Ze
dd��Ze
d
d��Ze
dd��Ze
dd��Zdd�Zdd�Zd@dd�Zdd�ZdAdd�Zed�dAdd��Zd d!�Zd"d#�ZdBd$d%�Zd&d'�Zd(d)�ZdCd,d-�ZdDd.d/�Zd0d1�Z ed�d2d3��Z!d4d5�Z"d6d7�Z#d8d9�Z$�fd:d;�Z%e&d<d=��Z'dAd>d?�Z(�Z)S)E�	APIClientaW
    A low-level client for the Docker Engine API.

    Example:

        >>> import docker
        >>> client = docker.APIClient(base_url='unix://var/run/docker.sock')
        >>> client.version()
        {u'ApiVersion': u'1.33',
         u'Arch': u'amd64',
         u'BuildTime': u'2017-11-19T18:46:37.000000000+00:00',
         u'GitCommit': u'f4ffd2511c',
         u'GoVersion': u'go1.9.2',
         u'KernelVersion': u'4.14.3-1-ARCH',
         u'MinAPIVersion': u'1.12',
         u'Os': u'linux',
         u'Version': u'17.10.0-ce'}

    Args:
        base_url (str): URL to the Docker server. For example,
            ``unix:///var/run/docker.sock`` or ``tcp://127.0.0.1:1234``.
        version (str): The version of the API to use. Set to ``auto`` to
            automatically detect the server's version. Default: ``1.35``
        timeout (int): Default timeout for API calls, in seconds.
        tls (bool or :py:class:`~docker.tls.TLSConfig`): Enable TLS. Pass
            ``True`` to enable it with default options, or pass a
            :py:class:`~docker.tls.TLSConfig` object to use custom
            configuration.
        user_agent (str): Set a custom user agent for requests to the server.
        credstore_env (dict): Override environment variables when calling the
            credential store process.
        use_ssh_client (bool): If set to `True`, an ssh connection is made
            via shelling out to the ssh client. Ensure the ssh client is
            installed and configured on the host.
        max_pool_size (int): The maximum number of connections
            to save in the pool.
    )�
_auth_configs�_general_configs�_version�base_url�timeoutNFc
sjt���|r
|s
td��||_||_||jd<t��|_|j�	di�}
z|
|}Wnt
y9|
�	di�}Ynwt�|�|_
tj|j|d�|_||_tj|tt|�d�}|�d�r_|p^tnt}|�d�r�t||||	d	�|_|�d
|j�|�dd�d
|_nx|�d�r�ts�td��zt||||	d	�|_Wnty�td��w|�d
|j�d|_nK|�d�r�zt ||||	|d�|_Wnty�td��w|�d|j�|�dd�d|_nt!|t"�r�|�#|�n|r�t$|d�|_|�d|j�||_|du�s
t!|t%��r|�&�dk�r|�'�|_(n||_(t!|j(t%��s$td�)t*|�j+���t�,|j(t-��r3t.d�)t-���dS)Nz5If using TLS, the base_url argument must be provided.z
User-Agent�proxies�default)�config_dict�
credstore_env)�tlszssh://zhttp+unix://)�pool_connections�
max_pool_sizezhttp+docker://�http://�https://zhttp+docker://localhostznpipe://z2The npipe:// protocol is only supported on Windowsz4Install pypiwin32 package to enable npipe:// support�http+docker://localnpipe)r7r8�	shell_outz1Install paramiko package to enable ssh:// support�http+docker://ssh)r7�autoz4Version parameter must be a string or None. Found {}z>API versions below {} are no longer supported by this library.)/�super�__init__rr0r1�headersr�load_general_configr.�get�KeyErrorr�	from_dict�_proxy_configsr�load_configr-r5r�
parse_hostr
�bool�
startswithrrr�_custom_adapter�mount�_unmountr
r*�	NameErrorr+�
isinstancer�configure_clientr�str�lower�_retrieve_server_versionr/�format�type�__name__�
version_ltrr)�selfr0�versionr1r6�
user_agent�	num_poolsr5�use_ssh_clientr8�proxy_configr2��	__class__��3/usr/lib/python3/dist-packages/docker/api/client.pyr@is�
�

��
����
�
����
���
������zAPIClient.__init__c
CsNz	|jdd�dWStytd��ty&}ztd|����d}~ww)NF)�api_version�
ApiVersionzAInvalid response from docker daemon: key "ApiVersion" is missing.z)Error while fetching server API version: )rYrDr
�	Exception)rX�er`r`rarS�s����z"APIClient._retrieve_server_versioncCs|�d|j�|S)zjPrepare the kwargs for an HTTP request by inserting the timeout
        parameter, if not already present.r1)�
setdefaultr1)rX�kwargsr`r`ra�_set_request_timeout�szAPIClient._set_request_timeoutcK�|j|fi|�|���S�N)�postrh�rX�urlrgr`r`ra�_post��zAPIClient._postcKrirj)rCrhrlr`r`ra�_get�rozAPIClient._getcKrirj)�putrhrlr`r`ra�_put�rozAPIClient._putcKrirj)�deleterhrlr`r`ra�_delete�rozAPIClient._deletecOsz|D]}t|t�std�|t|����qttjjdd�}t	||�}|�
dd�r3d�|j|j|j|��S|j�|j|���S)Nz+Expected a string but found {} ({}) insteadz/:)�safe�
versioned_apiTz{}/v{}{})
rOrQ�
ValueErrorrTrUr�urllib�parse�quote�maprCr0r/)rX�pathfmt�argsrg�arg�quote_fr`r`ra�_url�s
��
�zAPIClient._urlc
Cs4z|��WdStjjy}zt|��d}~ww)z1Raises stored :class:`APIError`, if one occurred.N)�raise_for_status�requests�
exceptions�	HTTPErrorr)rX�responserer`r`ra�_raise_for_status	s��zAPIClient._raise_for_statuscCs2|r|rJ�|�|�|r|��S|r|jS|jSrj)r��json�content�text)rXr�r��binaryr`r`ra�_results
zAPIClient._resultcKs�i}|durt|t�rt|���D]\}}|dur|||<qn|dur%|}d|vr-i|d<d|dd<|j|fdt�|�i|��S)NrAzapplication/jsonzContent-Type�data)rO�dict�iter�itemsrnr��dumps)rXrmr�rg�data2�k�vr`r`ra�
_post_jsons��zAPIClient._post_jsoncCs|pdddd�S)Nr)�stdout�stderr�streamr`)rX�overrider`r`ra�_attach_params*s
�zAPIClient._attach_params�	containercCsR|�d|�}tjd||�|�d�}|��j}|�ddd�}|�ddd�}|�|�S)	Nz/containers/{0}/attach/ws�POST)�paramsr9zws://rr:zwss://)r�r��Requestr��preparerm�replace�_create_websocket_connection)rXr�r�rm�req�full_urlr`r`ra�_attach_websocket1s

zAPIClient._attach_websocketcCs
t�|�Srj)�	websocket�create_connection)rXrmr`r`rar�:s
z&APIClient._create_websocket_connectioncCs~|�|�|jdkr|jjjjj}n|j�d�r|jjjj}n|jjjj}|j�d�r.|j}z||_	W|St
y>Y|Sw)Nr;r=r:)r�r0�raw�_fp�fp�sockrJ�channel�_sock�	_response�AttributeError)rXr�r�r`r`ra�_get_raw_response_socket=s

��z"APIClient._get_raw_response_socketccs��|jjjr;|rt|�|d��EdHdS|j}|js9|�d�}|s$dS|jjr1||�|jj�7}|V|jrdSdS|j||d�VdS)z?Generator for data coming from a chunked-encoded HTTP response.FNr)r�)	r�r��chunkedr�_stream_helper�closed�read�
chunk_leftr�)rXr��decode�readerr�r`r`rar�Ss�

�zAPIClient._stream_helperc
csr�|j|dd�}t|�}d}	||tkrdS|||t�}t�d|�\}}|t}||}	|	}|||	�Vq)zMA generator of multiplexed data blocks read from a buffered
        response.T�r�r�>BxxxLN)r��lenr�struct�unpack_from)
rXr��buf�
buf_length�walker�header�_�length�start�endr`r`ra�_multiplexed_buffer_helperhs��z$APIClient._multiplexed_buffer_helperccs^�|�|�}|�|�	|j�t�}|sdSt�d|�\}}|s!q|j�|�}|s+dS|Vq)zMA generator of multiplexed data blocks coming from a response
        stream.Tr�N)r��_disable_socket_timeoutr�r�rr��unpack)rXr��socketr�r�r�r�r`r`ra�#_multiplexed_response_stream_helperxs�

�z-APIClient._multiplexed_response_stream_helperrTccs6�|�|�|�|�}|�|�|�||�EdHdS)z< Stream result for TTY-enabled container and raw binary dataN)r�r�r��iter_content)rXr��
chunk_sizer�r�r`r`ra�_stream_raw_result�s
�


zAPIClient._stream_raw_resultcCsJ|�|�}t||�}|rdd�|D�}ndd�|D�}|r|St||d�S)Ncss�|]}t|�VqdSrj)r)�.0�framer`r`ra�	<genexpr>���z.APIClient._read_from_socket.<locals>.<genexpr>css�|]\}}|VqdSrjr`)r�r�r�r`r`rar��r�)�demux)r�rr)rXr�r��ttyr�r��genr`r`ra�_read_from_socket�s

zAPIClient._read_from_socketcCs\|t|dd�g}|D]!}t|d�sq
d}t|d�r|��}|dus%|dkr&q
|�d�q
dS)a Depending on the combination of python version and whether we're
        connecting over http or https, we might need to access _sock, which
        may or may not exist; or we may need to just settimeout on socket
        itself, which also may or may not have settimeout on it. To avoid
        missing the correct one, we try both.

        We also do not want to set the timeout if it is already disabled, as
        you run the risk of changing a socket that was non-blocking to
        blocking, for example when using gevent.
        r�N�
settimeout����
gettimeoutg)�getattr�hasattrr�r�)rXr��sockets�sr1r`r`rar��s

�z!APIClient._disable_socket_timeoutcCs|�|�}|ddS)N�Config�Tty)�inspect_container)rXr��contr`r`ra�
_check_is_tty�s
zAPIClient._check_is_ttycCs|�|||�|��Srj)�_get_result_ttyr�)rXr�r��resr`r`ra�_get_result�szAPIClient._get_resultcCsV|r|r	|�|�S|j|dd�S|�|�d}|r|�|�S|�dd�|�|�D��S)NTr��cSsg|]}|�qSr`r`)r��xr`r`ra�
<listcomp>�sz-APIClient._get_result_tty.<locals>.<listcomp>)r�r�r�r��joinr�)rXr�r��is_tty�sepr`r`rar��s�

�zAPIClient._get_result_ttycGs|D]}|j�|�qdSrj)�adapters�pop)rXr}�protor`r`rarM�s�zAPIClient._unmountc
sHzt��|�WStjjy#}z|jr|jWYd}~S|�d}~wwrj)r?�get_adapterr�r��
InvalidSchemarK)rXrmrer^r`rar��s��zAPIClient.get_adaptercCs|jSrj)r/)rXr`r`rarb�szAPIClient.api_versioncCstj||jd�|_dS)a.
        Force a reload of the auth configuration

        Args:
            dockercfg_path (str): Use a custom path for the Docker config file
                (default ``$HOME/.docker/config.json`` if present,
                otherwise ``$HOME/.dockercfg``)

        Returns:
            None
        )r5N)rrGr5r-)rX�dockercfg_pathr`r`ra�
reload_config�s�zAPIClient.reload_config)FFrj)F)rT)TF)*rV�
__module__�__qualname__�__doc__r��Session�	__attrs__rr	rr@rSrhrrnrprrrtr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�rMr��propertyrbr��
__classcell__r`r`r^rar,/sV&�k











	
r,)Er�r�rx�	functoolsrr��requests.exceptionsr��r�	constantsrrrrr	r
rr�errorsr
rrrr6r�	transportrrrrrr�utils.json_streamr�utils.proxyr�utils.socketrrr�buildrrr�r �daemonr!�exec_apir"�imager#�networkr$�pluginr%�secretr&�servicer'�swarmr(�volumer)r*�ImportErrorr+r�r,r`r`r`ra�<module>sj(��
�