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__/image.cpython-310.pyc
o

�2.a�N�@sbddlZddlZddlmZmZmZddlmZe�e	�Z
Gdd�d�Zdd�Z		dd	d
�Z
dS)�N�)�auth�errors�utils)�DEFAULT_DATA_CHUNK_SIZEc@s.eZdZe�d�efdd��Ze�d�dd��Zd*dd	�Z		d+d
d�Z			d,dd
�Z
		d,dd�Z		d,dd�Z		d,dd�Z
		d,dd�Ze�d�dd��Ze�d�e�d�d-dd���Zd-dd�Ze�d�d-dd��Z		d.d d!�Z		d/d"d#�Ze�d�d0d$d%��Zd-d&d'�Ze�d�d1d(d)��ZdS)2�
ImageApiMixin�imagecCs$|j|�d|�dd�}|�||d�S)a�
        Get a tarball of an image. Similar to the ``docker save`` command.

        Args:
            image (str): Image name to get
            chunk_size (int): The number of bytes returned by each iteration
                of the generator. If ``None``, data will be streamed as it is
                received. Default: 2 MB

        Returns:
            (generator): A stream of raw archive data.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:

            >>> image = client.api.get_image("busybox:latest")
            >>> f = open('/tmp/busybox-latest.tar', 'wb')
            >>> for chunk in image:
            >>>   f.write(chunk)
            >>> f.close()
        z/images/{0}/getT)�streamF)�_get�_url�_stream_raw_result)�selfr�
chunk_size�res�r�2/usr/lib/python3/dist-packages/docker/api/image.py�	get_imageszImageApiMixin.get_imagecCs|�|�d|��}|�|d�S)a#
        Show the history of an image.

        Args:
            image (str): The image to show history for

        Returns:
            (str): The history of the image

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        z/images/{0}/historyT)r
r�_result)r
rrrrr�history)szImageApiMixin.historyNFcCs�|rdnd|r	dndd�}|r&t�|jd�r||d<n|r"||d<nd|i}|r/t�|�|d<|�|j|�d�|d	�d
�}|rFdd�|D�S|S)
a
        List images. Similar to the ``docker images`` command.

        Args:
            name (str): Only show images belonging to the repository ``name``
            quiet (bool): Only return numeric IDs as a list.
            all (bool): Show intermediate image layers. By default, these are
                filtered out.
            filters (dict): Filters to be processed on the image list.
                Available filters:
                - ``dangling`` (bool)
                - `label` (str|list): format either ``"key"``, ``"key=value"``
                    or a list of such.

        Returns:
            (dict or list): A list if ``quiet=True``, otherwise a dict.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        �r)�only_ids�all�1.25�filter�	reference�filtersz/images/json��paramsTcSsg|]}|d�qS)�Idr)�.0�xrrr�
<listcomp>csz(ImageApiMixin.images.<locals>.<listcomp>)r�
version_lt�_version�convert_filtersrr
r)r
�name�quietrrrrrrr�images;s"

�

�zImageApiMixin.imagesc
Cs�|s	|s	t�d��|�d�}t|||t|t�r|nd|d�}ddi}	|s+|�d�dkr6|�|j|d|d	��St|t�r_t	|d
��}
|�|j||
||	dd��Wd�S1sXwYdS|red|	d
<|�|j||||	d��S)ad
        Import an image. Similar to the ``docker import`` command.

        If ``src`` is a string or unicode string, it will first be treated as a
        path to a tarball on the local system. If there is an error reading
        from that file, ``src`` will be treated as a URL instead to fetch the
        image from. You can also pass an open file handle as ``src``, in which
        case the data will be read from that file.

        If ``src`` is unset but ``image`` is set, the ``image`` parameter will
        be taken as the name of an existing image to import from.

        Args:
            src (str or file): Path to tarfile, URL, or file-like object
            repository (str): The repository to create
            tag (str): The tag to apply
            image (str): Use another image like the ``FROM`` Dockerfile
                parameter
        z(Must specify src or image to import from�/images/createN��src�changes�Content-Type�application/tar�fromSrc�-)�datar�rb�r0r�headers�timeout�chunkedzTransfer-Encoding)r0rr3)
r�DockerExceptionr�_import_image_params�
isinstance�str�getr�_post�open)r
r*�
repository�tagrr+�
stream_src�urr3�frrr�import_imagefs8�
��

��$��zImageApiMixin.import_imagec	Cs<|�d�}t||d|d�}ddi}|�|j||||dd��S)a@
        Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but
        allows importing in-memory bytes data.

        Args:
            data (bytes collection): Bytes collection containing valid tar data
            repository (str): The repository to create
            tag (str): The tag to apply
        r(r/r)r,r-Nr2)rr7rr;)r
r0r=r>r+r@rr3rrr�import_image_from_data�s
�
��z$ImageApiMixin.import_image_from_datacC�|j||||d�S)aj
        Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only
        supports importing from a tar file on disk.

        Args:
            filename (str): Full path to a tar file.
            repository (str): The repository to create
            tag (str): The tag to apply

        Raises:
            IOError: File does not exist.
        �r*r=r>r+�rB)r
�filenamer=r>r+rrr�import_image_from_file�s�z$ImageApiMixin.import_image_from_filecCs|j|d|||d�S)NT)r*r?r=r>r+rF)r
r	r=r>r+rrr�import_image_from_stream�s�z&ImageApiMixin.import_image_from_streamcCrD)a"
        Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only
        supports importing from a URL.

        Args:
            url (str): A URL pointing to a tar file.
            repository (str): The repository to create
            tag (str): The tag to apply
        rErF)r
�urlr=r>r+rrr�import_image_from_url�s�z#ImageApiMixin.import_image_from_urlcCrD)aX
        Like :py:meth:`~docker.api.image.ImageApiMixin.import_image`, but only
        supports importing from another image, like the ``FROM`` Dockerfile
        parameter.

        Args:
            image (str): Image name to import from
            repository (str): The repository to create
            tag (str): The tag to apply
        )rr=r>r+rF)r
rr=r>r+rrr�import_image_from_image�s�z%ImageApiMixin.import_image_from_imagecCs|�|�|�d|��d�S)a�
        Get detailed information about an image. Similar to the ``docker
        inspect`` command, but only for images.

        Args:
            image (str): The image to inspect

        Returns:
            (dict): Similar to the output of ``docker inspect``, but as a
        single dict

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        z/images/{0}/jsonT�rr
r)r
rrrr�
inspect_image�s�zImageApiMixin.inspect_imagez1.30cCsnt�|�\}}i}|durt�||�}|r||d<nt�d�t�|�|d<|�d|�}|�|j||d�d�S)a/
        Get image digest and platform information by contacting the registry.

        Args:
            image (str): The image name to inspect
            auth_config (dict): Override the credentials that are found in the
                config for this request.  ``auth_config`` should contain the
                ``username`` and ``password`` keys to be valid.

        Returns:
            (dict): A dict containing distribution data

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        N�X-Registry-Auth�Sending supplied auth configz/distribution/{0}/json)r3T)	r�resolve_repository_name�get_config_header�log�debug�
encode_headerrrr
)r
r�auth_config�registry�_r3�headerrJrrr�inspect_distribution�s�
�z"ImageApiMixin.inspect_distributioncCsni}|durt�|jd�rt�d��||d<|j|�d�||dd�}t�|jd�r0|j|dd�S|�	|�dS)	a9
        Load an image that was previously saved using
        :py:meth:`~docker.api.image.ImageApiMixin.get_image` (or ``docker
        save``). Similar to ``docker load``.

        Args:
            data (binary): Image data to be loaded.
            quiet (boolean): Suppress progress details in response.

        Returns:
            (generator): Progress output as JSON objects. Only available for
                         API version >= 1.23

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        Nz1.23z,quiet is not supported in API version < 1.23r&z/images/loadT)r0rr	��decode)
rr"r#r�InvalidVersionr;r�version_gte�_stream_helper�_raise_for_status)r
r0r&rrrrr�
load_image#s��zImageApiMixin.load_imagercCs:|�d�}i}|durt�|�|d<|�|j||d�d�S)a
        Delete unused images

        Args:
            filters (dict): Filters to process on the prune list.
                Available filters:
                - dangling (bool):  When set to true (or 1), prune only
                unused and untagged images.

        Returns:
            (dict): A dict containing a list of deleted image IDs and
                the amount of disk space reclaimed in bytes.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        z
/images/pruneNrrT)rrr$rr;)r
rrJrrrr�prune_imagesFs

zImageApiMixin.prune_imagescCs�t�|�\}}|p|pd}|rd}t�|�\}	}
||d�}i}|dur0t�||	�}
|
r/|
|d<nt�d�t�|�|d<|durPt�|j	d�rLt
�d��||d<|j|�
d	�|||dd
�}|�|�|rk|j||d�S|�|�S)aE
        Pulls an image. Similar to the ``docker pull`` command.

        Args:
            repository (str): The repository to pull
            tag (str): The tag to pull. If ``tag`` is ``None`` or empty, it
                is set to ``latest``.
            stream (bool): Stream the output as a generator. Make sure to
                consume the generator, otherwise pull might get cancelled.
            auth_config (dict): Override the credentials that are found in the
                config for this request.  ``auth_config`` should contain the
                ``username`` and ``password`` keys to be valid.
            decode (bool): Decode the JSON data from the server into dicts.
                Only applies with ``stream=True``
            platform (str): Platform in the format ``os[/arch[/variant]]``
            all_tags (bool): Pull all image tags, the ``tag`` parameter is
                ignored.

        Returns:
            (generator or str): The output

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:

            >>> for line in client.api.pull('busybox', stream=True, decode=True):
            ...     print(json.dumps(line, indent=4))
            {
                "status": "Pulling image (latest) from busybox",
                "progressDetail": {},
                "id": "e72ac664f4f0"
            }
            {
                "status": "Pulling image (latest) from busybox, endpoint: ...",
                "progressDetail": {},
                "id": "e72ac664f4f0"
            }

        �latestN)r>�	fromImagerOrPz1.32z0platform was only introduced in API version 1.32�platformr()rr3r	r4r[)r�parse_repository_tagrrQrRrSrTrUr"r#rr]r;rr`r_r)r
r=r>r	rVr\re�all_tags�	image_tagrW�	repo_namerr3rY�responserrr�pull_s<+��
��

zImageApiMixin.pullc
Cs�|s	t�|�\}}t�|�\}}|�d|�}d|i}	i}
|dur-t�||�}|r,||
d<nt�d�t�|�|
d<|j	|d|
||	d�}|�
|�|rQ|j||d�S|�|�S)a�
        Push an image or a repository to the registry. Similar to the ``docker
        push`` command.

        Args:
            repository (str): The repository to push to
            tag (str): An optional tag to push
            stream (bool): Stream the output as a blocking generator
            auth_config (dict): Override the credentials that are found in the
                config for this request.  ``auth_config`` should contain the
                ``username`` and ``password`` keys to be valid.
            decode (bool): Decode the JSON data from the server into dicts.
                Only applies with ``stream=True``

        Returns:
            (generator or str): The output from the server.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:
            >>> for line in client.api.push('yourname/app', stream=True, decode=True):
            ...   print(line)
            {'status': 'Pushing repository yourname/app (1 tags)'}
            {'status': 'Pushing','progressDetail': {}, 'id': '511136ea3c5a'}
            {'status': 'Image already pushed, skipping', 'progressDetail':{},
             'id': '511136ea3c5a'}
            ...

        z/images/{0}/pushr>NrOrP)r3r	rr[)
rrfrrQrrRrSrTrU�
_post_jsonr`r_r)
r
r=r>r	rVr\rWrir@rr3rYrjrrr�push�s*!��

�

zImageApiMixin.pushcCs,||d�}|j|�d|�|d�}|�|d�S)z�
        Remove an image. Similar to the ``docker rmi`` command.

        Args:
            image (str): The image to remove
            force (bool): Force removal of the image
            noprune (bool): Do not delete untagged parents
        )�force�noprunez/images/{0}rT)�_deleterr)r
rrnrorrrrr�remove_image�s

zImageApiMixin.remove_imagecCs4d|i}|dur||d<|�|j|�d�|d�d�S)a�
        Search for images on Docker Hub. Similar to the ``docker search``
        command.

        Args:
            term (str): A term to search for.
            limit (int): The maximum number of results to return.

        Returns:
            (list of dicts): The response of the search.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        �termN�limitz/images/searchrTrM)r
rrrsrrrr�search�s�zImageApiMixin.searchcCsB|||rdndd�}|�d|�}|j||d�}|�|�|jdkS)aH
        Tag an image into a repository. Similar to the ``docker tag`` command.

        Args:
            image (str): The image to tag
            repository (str): The repository to set for the tag
            tag (str): The tag name
            force (bool): Force

        Returns:
            (bool): ``True`` if successful

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.

        Example:

            >>> client.api.tag('ubuntu', 'localhost:5000/ubuntu', 'latest',
                           force=True)
        rr)r>�repornz/images/{0}/tagr��)rr;r`�status_code)r
rr=r>rnrrJrrrrr>s
�

zImageApiMixin.tag)NFFN)NNNNNF�NNN)N)NFNFNF)NFNF)FF�NF)�__name__�
__module__�__qualname__r�check_resourcerrrr'rBrCrHrIrKrLrN�minimum_versionrZrarbrkrmrqrtr>rrrrr
sV

+
�4
�
�
�
�
�

"#
�T
�=

rcCs.zt|t�otj�|�WStyYdSwry)r8r9�os�path�isfile�	TypeError)r*rrr�is_file9s

��r�cCsF||d�}|r||d<n|rt|�s||d<nd|d<|r!||d<|S)N)rur>rdr.r/r+)r�)rur>rr*r+rrrrr7Cs�

r7rx)�loggingr�rrr�	constantsr�	getLoggerrzrSrr�r7rrrr�<module>s
3
�