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/models/__pycache__/images.cpython-310.pyc
o

�2.a`D�@s�ddlZddlZddlZddlmZddlmZddlmZm	Z	m
Z
ddlmZddl
mZdd	lmZmZGd
d�de�ZGdd
�d
e�ZGdd�de�Zdd�ZdS)�N�)�	APIClient)�DEFAULT_DATA_CHUNK_SIZE)�
BuildError�ImageLoadError�InvalidArgument)�parse_repository_tag)�json_stream�)�
Collection�Modelc@s\eZdZdZdd�Zedd��Zedd��Zedd	��Zd
d�Z	e
dfd
d�Zddd�ZdS)�Imagez!
    An image on the server.
    cCsd�|jjd�|j��S)Nz
<{}: '{}'>z', ')�format�	__class__�__name__�join�tags��self�r�6/usr/lib/python3/dist-packages/docker/models/images.py�__repr__�zImage.__repr__cCs|jd�d�}|piS)z7
        The labels of an image as dictionary.
        �Config�Labels��attrs�get)r�resultrrr�labelsszImage.labelscCs(|j�d�r
|jdd�S|jdd�S)�f
        The ID of the image truncated to 10 characters, plus the ``sha256:``
        prefix.
        �sha256:N��
)�id�
startswithrrrr�short_idszImage.short_idcCs&|j�d�}|durg}dd�|D�S)z#
        The image's tags.
        �RepoTagsNcSsg|]}|dkr|�qS)z
<none>:<none>r)�.0�tagrrr�
<listcomp>.szImage.tags.<locals>.<listcomp>r)rrrrrr&sz
Image.tagscCs|jj�|j�S)z�
        Show the history of an image.

        Returns:
            (str): The history of the image.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        )�client�api�historyr$rrrrr-0sz
Image.historyFcCsT|j}|r"|jr
|jdn|}t|t�r"||jvr t|�d���|}|jj�||�S)a�
        Get a tarball of an image. Similar to the ``docker save`` command.

        Args:
            chunk_size (int): The generator will return up to that much data
                per iteration, but may return less. If ``None``, data will be
                streamed as it is received. Default: 2 MB
            named (str or bool): If ``False`` (default), the tarball will not
                retain repository and tag information for this image. If set
                to ``True``, the first tag in the :py:attr:`~tags` list will
                be used to identify the image. Alternatively, any element of
                the :py:attr:`~tags` list can be used as an argument to use
                that specific tag as the saved identifier.

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

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

        Example:

            >>> image = cli.images.get("busybox:latest")
            >>> f = open('/tmp/busybox-latest.tar', 'wb')
            >>> for chunk in image.save():
            >>>   f.write(chunk)
            >>> f.close()
        rz" is not a valid tag for this image)r$r�
isinstance�strrr+r,�	get_image)r�
chunk_size�named�imgrrr�save=s

�z
Image.saveNcKs|jjj|j|fd|i|��S)a�
        Tag this image into a repository. Similar to the ``docker tag``
        command.

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

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

        Returns:
            (bool): ``True`` if successful
        r))r+r,r)r$�r�
repositoryr)�kwargsrrrr)gsz	Image.tag�N)
r�
__module__�__qualname__�__doc__r�propertyrr&rr-rr4r)rrrrr

s

	
	
*r
cs\eZdZdZ�fdd�Zedd��Zedd��Zdd	d
�Zdd�Z	d
d�Z
ej
je
_�ZS)�RegistryDatazO
    Image metadata stored on the registry, including available platforms.
    cst�j|i|��||_dSr8)�super�__init__�
image_name)rr@�argsr7�rrrr?s
zRegistryData.__init__cCs|jddS)z'
        The ID of the object.
        �
Descriptor�digest)rrrrrr$�szRegistryData.idcCs|jdd�S)r Nr")r$rrrrr&�szRegistryData.short_idNcCs"t|j�\}}|jj||j|d�S)z�
        Pull the image digest.

        Args:
            platform (str): The platform to pull the image for.
            Default: ``None``

        Returns:
            (:py:class:`Image`): A reference to the pulled image.
        )r)�platform)rr@�
collection�pullr$)rrEr6�_rrrrG�szRegistryData.pullcCs�|r>t|t�s>|�d�}t|�dkst|�dkr td|�d���d|di}t|�dkr2|d|d	<t|�dkr>|d|d
<t||j���|jdvS)a�
        Check whether the given platform identifier is available for this
        digest.

        Args:
            platform (str or dict): A string using the ``os[/arch[/variant]]``
                format, or a platform dictionary.

        Returns:
            (bool): ``True`` if the platform is recognized as available,
            ``False`` otherwise.

        Raises:
            :py:class:`docker.errors.InvalidArgument`
                If the platform argument is not a valid descriptor.
        �/�r
�"z$" is not a valid platform descriptor�osrr�variant�architecture�	Platforms)	r.�dict�split�lenr�normalize_platformr+�versionr)rrE�partsrrr�has_platform�s 

�
��zRegistryData.has_platformcCs|jj�|j�|_dSr8)r+r,�inspect_distributionr@rrrrr�reload�szRegistryData.reloadr8)
rr9r:r;r?r<r$r&rGrVrXr�
__classcell__rrrBrr={s


 r=c@s�eZdZeZdd�Zdd�Zddd�Zdd	d
�Zdd�Z	dd
d�Z
ddd�Zejj
e_
dd�Zejj
e_
dd�Zejj
e_
ddd�Zejj
e_
dd�Zejj
e_
dS)�ImageCollectionc	Ks�|jjjdi|��}t|t�r|�|�Sd}d}t�t|��\}}|D]"}d|vr0t	|d|��d|vrCt
�d|d�}|rC|�d�}|}q#|rO|�|�|fSt	|pSd|��)a�
        Build an image and return it. Similar to the ``docker build``
        command. Either ``path`` or ``fileobj`` must be set.

        If you have a tar file for the Docker build context (including a
        Dockerfile) already, pass a readable file-like object to ``fileobj``
        and also pass ``custom_context=True``. If the stream is compressed
        also, set ``encoding`` to the correct value (e.g ``gzip``).

        If you want to get the raw output of the build, use the
        :py:meth:`~docker.api.build.BuildApiMixin.build` method in the
        low-level API.

        Args:
            path (str): Path to the directory containing the Dockerfile
            fileobj: A file object to use as the Dockerfile. (Or a file-like
                object)
            tag (str): A tag to add to the final image
            quiet (bool): Whether to return the status
            nocache (bool): Don't use the cache when set to ``True``
            rm (bool): Remove intermediate containers. The ``docker build``
                command now defaults to ``--rm=true``, but we have kept the old
                default of `False` to preserve backward compatibility
            timeout (int): HTTP timeout
            custom_context (bool): Optional if using ``fileobj``
            encoding (str): The encoding for a stream. Set to ``gzip`` for
                compressing
            pull (bool): Downloads any updates to the FROM image in Dockerfiles
            forcerm (bool): Always remove intermediate containers, even after
                unsuccessful builds
            dockerfile (str): path within the build context to the Dockerfile
            buildargs (dict): A dictionary of build arguments
            container_limits (dict): A dictionary of limits applied to each
                container created by the build process. Valid keys:

                - memory (int): set memory limit for build
                - memswap (int): Total memory (memory + swap), -1 to disable
                    swap
                - cpushares (int): CPU shares (relative weight)
                - cpusetcpus (str): CPUs in which to allow execution, e.g.,
                    ``"0-3"``, ``"0,1"``
            shmsize (int): Size of `/dev/shm` in bytes. The size must be
                greater than 0. If omitted the system uses 64MB
            labels (dict): A dictionary of labels to set on the image
            cache_from (list): A list of images used for build cache
                resolution
            target (str): Name of the build-stage to build in a multi-stage
                Dockerfile
            network_mode (str): networking mode for the run commands during
                build
            squash (bool): Squash the resulting images layers into a
                single layer.
            extra_hosts (dict): Extra hosts to add to /etc/hosts in building
                containers, as a mapping of hostname to IP address.
            platform (str): Platform in the format ``os[/arch[/variant]]``.
            isolation (str): Isolation technology used during build.
                Default: `None`.
            use_config_proxy (bool): If ``True``, and if the docker client
                configuration file (``~/.docker/config.json`` by default)
                contains a proxy configuration, the corresponding environment
                variables will be set in the container being built.

        Returns:
            (tuple): The first item is the :py:class:`Image` object for the
                image that was build. The second item is a generator of the
                build logs as JSON-decoded objects.

        Raises:
            :py:class:`docker.errors.BuildError`
                If there is an error during the build.
            :py:class:`docker.errors.APIError`
                If the server returns any other error.
            ``TypeError``
                If neither ``path`` nor ``fileobj`` is specified.
        N�error�streamz*(^Successfully built |sha256:)([0-9a-f]+)$r�Unknownr)
r+r,�buildr.r/r�	itertools�teer	r�re�search�group)	rr7�resp�
last_event�image_id�
result_stream�internal_stream�chunk�matchrrrr^�s(L

�
zImageCollection.buildcCs|�|jj�|��S)am
        Gets an image.

        Args:
            name (str): The name of the image.

        Returns:
            (:py:class:`Image`): The image.

        Raises:
            :py:class:`docker.errors.ImageNotFound`
                If the image does not exist.
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        )�
prepare_modelr+r,�
inspect_image)r�namerrrr*szImageCollection.getNcCst||jj�||�|j|d�S)a
        Gets the registry data for an image.

        Args:
            name (str): The name of the image.
            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:
            (:py:class:`RegistryData`): The data object.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        )r@rr+rF)r=r+r,rW)rrm�auth_configrrr�get_registry_data<s�z!ImageCollection.get_registry_dataFcs&�jjj|||d�}�fdd�|D�S)a�
        List images on the server.

        Args:
            name (str): Only show images belonging to the repository ``name``
            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:
            (list of :py:class:`Image`): The images.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        )rm�all�filterscsg|]	}��|d��qS)�Id�r)r(�rrrrr*jsz(ImageCollection.list.<locals>.<listcomp>)r+r,�images)rrmrprqrdrrr�listTszImageCollection.listcsr�jj�|�}g}|D]$}d|vr%t�d|d�}|r%|�d�}|�|�d|vr/t|d��q�fdd�|D�S)a�
        Load an image that was previously saved using
        :py:meth:`~docker.models.images.Image.save` (or ``docker save``).
        Similar to ``docker load``.

        Args:
            data (binary): Image data to be loaded.

        Returns:
            (list of :py:class:`Image`): The images.

        Raises:
            :py:class:`docker.errors.APIError`
                If the server returns an error.
        r\z)(^Loaded image ID: |^Loaded image: )(.+)$rr[csg|]}��|��qSrrs)r(�irrrr*�sz(ImageCollection.load.<locals>.<listcomp>)r+r,�
load_imagerarbrc�appendr)r�datardrurirjrfrrr�loadls�

�zImageCollection.loadc	Ks�t|�\}}|p|pd}d|vrt�d�|d=|jjj|f|d|d�|��}|D]}q)|sA|�d�|||�d�r=d��Sd	��S|�	|�S)
a�
        Pull an image of the given name and return it. Similar to the
        ``docker pull`` command.
        If ``tag`` is ``None`` or empty, it is set to ``latest``.
        If ``all_tags`` is set, the ``tag`` parameter is ignored and all image
        tags will be pulled.

        If you want to get the raw pull output, use the
        :py:meth:`~docker.api.image.ImageApiMixin.pull` method in the
        low-level API.

        Args:
            repository (str): The repository to pull
            tag (str): The tag to pull
            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.
            platform (str): Platform in the format ``os[/arch[/variant]]``
            all_tags (bool): Pull all image tags

        Returns:
            (:py:class:`Image` or list): The image that has been pulled.
                If ``all_tags`` is True, the method will return a list
                of :py:class:`Image` objects belonging to this repository.

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

        Example:

            >>> # Pull the image tagged `latest` in the busybox repo
            >>> image = client.images.pull('busybox')

            >>> # Pull all tags in the busybox repo
            >>> images = client.images.pull('busybox', all_tags=True)
        �latestr\zH`stream` is not a valid parameter for this method and will be overriddenT)r)r\�all_tagsz	{0}{2}{1}r!�@�:)
r�warnings�warnr+r,rGrrr%rv)rr6r)r}r7�	image_tag�pull_logrHrrrrG�s.&������
zImageCollection.pullcKs|jjj|fd|i|��S)Nr))r+r,�pushr5rrrr��szImageCollection.pushcOs|jjj|i|��dSr8)r+r,�remove_image�rrAr7rrr�remove�rzImageCollection.removecO�|jjj|i|��Sr8)r+r,rbr�rrrrb��zImageCollection.searchcCs|jjj|d�S)N)rq)r+r,�prune_images)rrqrrr�prune�szImageCollection.prunecOr�r8)r+r,�prune_buildsr�rrrr��r�zImageCollection.prune_buildsr8)NFN)NF)rr9r:r
�modelr^rrorvr{rGr�rr;r�r�rbr�r�r�rrrrrZ�s$a


 
>




rZcCs8|duri}d|vr|d|d<d|vr|d|d<|S)NrL�OsrN�Archr)rE�engine_inforrrrS�srS)r_rar�r,r�	constantsr�errorsrrr�utilsr�utils.json_streamr	�resourcerrr
r=rZrSrrrr�<module>snK