HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib/python3.10/site-packages/docker/api/__pycache__/client.cpython-310.pyc
o

��h�K�@s�ddlZddlZddlZddlmZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZddlmZmZmZmZddlmZddlmZdd	lmZmZmZmZdd
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
dl/m0Z0d
dl1m2Z2d
dl3m4Z4d
dl5m6Z6d
dl7m8Z8d
dl9m:Z:d
dl;m<Z<d
dl=m>Z>zddlm?Z?Wn	e@y�YnwzddlmAZAWn	e@y�YnwGdd�dejBe)e*e,e.e0e2e4e6e8e:e<e>�ZCdS)�N)�partial�)�auth)�DEFAULT_MAX_POOL_SIZE�DEFAULT_NUM_POOLS�DEFAULT_NUM_POOLS_SSH�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)�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


s�t���|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
|_n�|�d�r�ts�td��zt||||	d	�|_Wnty�}ztd�|�d}~ww|�d
|j�d|_nT|�d�r�zt ||||	|d�|_Wnty�}ztd�|�d}~ww|�d|j�|�dd�d|_n t!|t"�r�|�#|�n|�rt$j%j&|d�|_|�d|j�||_|du�st!|t'��r|�(�dk�r|�)�|_*n||_*t!|j*t'��s3tdt+|�j,����t�-|j*t.��rCt/dt.�d���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)r6r7�	shell_outz1Install paramiko package to enable ssh:// support�http+docker://ssh)r6�autoz2Version parameter must be a string or None. Found zAPI versions below z) are no longer supported by this library.)0�super�__init__rr/r0�headersr�load_general_configr-�get�KeyErrorr�	from_dict�_proxy_configsr�load_configr,r4r�
parse_hostr
�bool�
startswithrrr�_custom_adapter�mount�_unmountr
r)�	NameErrorr*�
isinstancer�configure_client�requests�adapters�HTTPAdapter�str�lower�_retrieve_server_versionr.�type�__name__�
version_ltrr)
�selfr/�versionr0r5�
user_agent�	num_poolsr4�use_ssh_clientr7�proxy_configr1�err��	__class__��G/usr/local/CyberPanel/lib/python3.10/site-packages/docker/api/client.pyr?ss�
�

��
����
�
������
�����
����
��zAPIClient.__init__c
Cs\z	|jdd�dWSty}ztd�|�d}~wty-}ztd|���|�d}~ww)NF)�api_version�
ApiVersionzAInvalid response from docker daemon: key "ApiVersion" is missing.z)Error while fetching server API version: )rZrCr
�	Exception)rY�ke�erbrbrcrU�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.r0)�
setdefaultr0)rY�kwargsrbrbrc�_set_request_timeout�szAPIClient._set_request_timeoutcK�|j|fi|�|���S�N)�postrk�rY�urlrjrbrbrc�_post��zAPIClient._postcKrlrm)rBrkrorbrbrc�_get�rrzAPIClient._getcKrlrm)�putrkrorbrbrc�_put�rrzAPIClient._putcKrlrm)�deleterkrorbrbrc�_delete�rrzAPIClient._deletecOs�|D]}t|t�std|�dt|��d���qttjjdd�}t||�}|j	|�}|�
dd�r:|j�d|j�|��S|j�|��S)	NzExpected a string but found z (z	) insteadz/:)�safe�
versioned_apiTz/v)
rNrS�
ValueErrorrVr�urllib�parse�quote�map�formatrBr/r.)rY�pathfmt�argsrj�arg�quote_f�formatted_pathrbrbrc�_urls
��

zAPIClient._urlc
Cs6z|��WdStjjy}zt|�|�d}~ww)z1Raises stored :class:`APIError`, if one occurred.N)�raise_for_statusrP�
exceptions�	HTTPErrorr)rY�responserhrbrbrc�_raise_for_statuss
��zAPIClient._raise_for_statuscCs2|r|rJ�|�|�|r|��S|r|jS|jSrm)r��json�content�text)rYr�r��binaryrbrbrc�_results
zAPIClient._resultcKs�i}|durt|t�rt|���D]\}}|dur|||<qn|dur%|}d|vr-i|d<d|dd<|j|fdt�|�i|��S)Nr@zapplication/jsonzContent-Type�data)rN�dict�iter�itemsrqr��dumps)rYrpr�rj�data2�k�vrbrbrc�
_post_json!s��zAPIClient._post_jsoncCs|pdddd�S)Nr)�stdout�stderr�streamrb)rY�overriderbrbrc�_attach_params1s
�zAPIClient._attach_params�	containercCsR|�d|�}tjd||�|�d�}|��j}|�ddd�}|�ddd�}|�|�S)	Nz/containers/{0}/attach/ws�POST)�paramsr8zws://rr9zwss://)r�rP�Requestr��preparerp�replace�_create_websocket_connection)rYr�r�rp�req�full_urlrbrbrc�_attach_websocket8s

zAPIClient._attach_websocketc
Cs8z
ddl}|�|�WSty}ztd�|�d}~ww)Nrz�The `websocket-client` library is required for using websocket connections. You can install the `docker` library with the [websocket] extra to install it.)�	websocket�create_connection�ImportErrorr
)rYrpr��ierbrbrcr�As����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<r9)r�r/�raw�_fp�fp�sockrI�channel�_sock�	_response�AttributeError)rYr�r�rbrbrc�_get_raw_response_socketMs

��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�)rYr��decode�readerr�rbrbrcr�cs�

�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)
rYr��buf�
buf_length�walker�header�_�length�start�endrbrbrc�_multiplexed_buffer_helperxs��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)rYr��socketr�r�r�r�rbrbrc�#_multiplexed_response_stream_helper�s�

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


zAPIClient._stream_raw_resultcCs`|�|�}t||�}|rdd�|D�}ndd�|D�}|r|Szt||d�W|��S|��w)z�Consume all data from the socket, close the response and return the
        data. If stream=True, then a generator is returned instead and the
        caller is responsible for closing the response.
        css�|]}t|�VqdSrm)r)�.0�framerbrbrc�	<genexpr>���z.APIClient._read_from_socket.<locals>.<genexpr>css�|]\}}|VqdSrmrb)r�r�r�rbrbrcr��r�)�demux)r�rr�close)rYr�r��ttyr�r��genrbrbrc�_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�)rYr��sockets�sr0rbrbrcr��s

�z!APIClient._disable_socket_timeoutcCs|�|�}|ddS)N�Config�Tty)�inspect_container)rYr��contrbrbrc�
_check_is_tty�s
zAPIClient._check_is_ttycCs|�|||�|��Srm)�_get_result_ttyr�)rYr�r��resrbrbrc�_get_result�szAPIClient._get_resultcCsP|r|r	|�|�S|j|dd�S|�|�d}|r|�|�S|�t|�|���S)NTr��)r�r�r�r��join�listr�)rYr�r��is_tty�seprbrbrcr��s�

�zAPIClient._get_result_ttycGs|D]}|j�|�qdSrm)rQ�pop)rYr��protorbrbrcrL�s�zAPIClient._unmountc
sHzt��|�WStjjy#}z|jr|jWYd}~S|�d}~wwrm)r>�get_adapterrPr��
InvalidSchemarJ)rYrprhr`rbrcr��s��zAPIClient.get_adaptercCs|jSrm)r.)rYrbrbrcrdszAPIClient.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
        )r4N)rrFr4r,)rY�dockercfg_pathrbrbrc�
reload_configs�zAPIClient.reload_config)FFrm)F)rT)TF)*rW�
__module__�__qualname__�__doc__rP�Session�	__attrs__rr	rr?rUrkrrqrsrurwr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�rLr��propertyrdr��
__classcell__rbrbr`rcr+9sV&�j











	
r+)Dr�r�r{�	functoolsrrP�requests.adapters�requests.exceptions�r�	constantsrrrrr	r
rr�errorsr
rrrr5r�	transportrrrrr�utils.json_streamr�utils.proxyr�utils.socketrrr�buildrrr�r�daemonr �exec_apir!�imager"�networkr#�pluginr$�secretr%�servicer&�swarmr'�volumer(r)r�r*r�r+rbrbrbrc�<module>sj(
��
�