
    ZF                         S SK r S SKrS SKrSSKJr  SSKJr  SSKJrJ	r	J
r
  SSKJr  SSKJr  SS	KJrJr   " S
 S\5      r " S S\5      r " S S\5      rS rg)    N   )	APIClient)DEFAULT_DATA_CHUNK_SIZE)
BuildErrorImageLoadErrorInvalidArgument)parse_repository_tag)json_stream   )
CollectionModelc                   v    \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	S r
SS	 jr\S4S
 jrSS jrSrg)Image   z
An image on the server.
c                     SR                  U R                  R                  SR                  U R                  5      5      $ )Nz
<{}: '{}'>z', ')format	__class____name__jointagsselfs    'lib/third_party/docker/models/images.py__repr__Image.__repr__   s2    ""NN##KK		"
 	
    c                 T    U R                   S   R                  S5      nU=(       d    0 $ )z'
The labels of an image as dictionary.
ConfigLabelsattrsget)r   results     r   labelsImage.labels   s'    
 H%))(3|r   c                 ~    U R                   R                  S5      (       a  U R                   SS $ U R                   SS $ )N
The ID of the image truncated to 12 characters, plus the ``sha256:``
prefix.
sha256:N      )id
startswithr   s    r   short_idImage.short_id   s9     77i((773B<wws|r   c                     U R                   R                  S5      nUc  / nU Vs/ s H  o"S:w  d  M
  UPM     sn$ s  snf )z
The image's tags.
RepoTagsz<none>:<none>r    )r   r   tags      r   r   
Image.tags)   s=    
 zz~~j)<D#>to'=t>>>s   	;;c                 `    U R                   R                  R                  U R                  5      $ )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+   r   s    r   r6   Image.history3   s!     {{&&tww//r   Fc                 `    U R                   R                  R                  U R                  UUS9$ )z
Remove this image.

Args:
    force (bool): Force removal of the image
    noprune (bool): Do not delete untagged parents

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)forcenoprune)r4   r5   remove_imager+   )r   r9   r:   s      r   removeImage.remove@   s1     {{++GG , 
 	
r   c                    U R                   nU(       aV  U R                  (       a  U R                  S   OUn[        U[        5      (       a  X R                  ;  a  [	        U S35      eUnU R
                  R                  R                  X15      $ )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()
r   z" is not a valid tag for this image)r+   r   
isinstancestrr   r4   r5   	get_image)r   
chunk_sizenamedimgs       r   save
Image.saveR   st    < gg"&))$))A,C%%%		)) '!CD  {{((99r   Nc                 j    U R                   R                  R                  " U R                  U4SU0UD6$ )aB  
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
r1   )r4   r5   r1   r+   r   
repositoryr1   kwargss       r   r1   	Image.tag|   s-    " {{""477JJCJ6JJr    )FFN)r   
__module____qualname____firstlineno____doc__r   propertyr$   r-   r   r6   r<   r   rE   r1   __static_attributes__rL   r   r   r   r      se    
     ? ?0
$ 6U (:TKr   r   c                      ^  \ rS rSrSrU 4S jr\S 5       r\S 5       rS
S jr	S r
S r\R                  R                  \l        S	rU =r$ )RegistryData   zG
Image metadata stored on the registry, including available platforms.
c                 2   > [         TU ]  " U0 UD6  Xl        g rM   )super__init__
image_name)r   rZ   argsrJ   r   s       r   rY   RegistryData.__init__   s    $)&)$r   c                 &    U R                   S   S   $ )z
The ID of the object.

Descriptordigest)r!   r   s    r   r+   RegistryData.id   s    
 zz,'11r   c                      U R                   SS $ )r'   Nr)   )r+   r   s    r   r-   RegistryData.short_id   s     wws|r   c                 x    [        U R                  5      u  p#U R                  R                  X R                  US9$ )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.
)r1   platform)r	   rZ   
collectionpullr+   )r   rd   rI   _s       r   rf   RegistryData.pull   s2     -T__=
##JGGh#OOr   c                    U(       a  [        U[        5      (       ds  UR                  S5      n[        U5      S:  d  [        U5      S:  a  [	        SU S35      eSUS   0n[        U5      S:  a  US   US	'   [        U5      S:  a  US   US
'   [        XR                  R                  5       5      U R                  S   ;   $ )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osr   r   variantarchitecture	Platforms)	r?   dictsplitlenr   normalize_platformr4   versionr!   )r   rd   partss      r   has_platformRegistryData.has_platform   s    " Jx66NN3'E5zA~Ua%z!EF  eAh'H5zA~&+Ah#5zA~+08(!kk))+
ZZ$% 	%r   c                 l    U R                   R                  R                  U R                  5      U l        g rM   )r4   r5   inspect_distributionrZ   r!   r   s    r   reloadRegistryData.reload   s     [[__99$//J
r   )r!   rZ   rM   )r   rN   rO   rP   rQ   rY   rR   r+   r-   rf   rw   r{   r   rS   __classcell__)r   s   @r   rU   rU      s\    % 2 2  P%@K \\))FNNr   rU   c                   |   \ rS rSr\rS rS rSS jrSS jr	S r
SS jrSS	 jr\R                  R                  \l        S
 r\R                   R                  \l        S r\R"                  R                  \l        SS jr\R&                  R                  \l        S r\R(                  R                  \l        Srg)ImageCollection   c                    U R                   R                  R                  " S0 UD6n[        U[        5      (       a  U R                  U5      $ SnSn[        R                  " [        U5      5      u  pVU HR  nSU;   a  [        US   U5      eSU;   a2  [        R                  " SUS   5      nU(       a  UR                  S5      nUnMT     U(       a  U R                  U5      U4$ [        U=(       d    SU5      e)ae  
Build an image and return it. Similar to the ``docker build``
command. Either ``path`` or ``fileobj`` must be set.

If you already have a tar file for the Docker build context (including
a Dockerfile), pass a readable file-like object to ``fileobj``
and also pass ``custom_context=True``. If the stream is also
compressed, 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 built. 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   UnknownrL   )r4   r5   buildr?   r@   r"   	itertoolsteer
   r   researchgroup)	r   rJ   resp
last_eventimage_idresult_streaminternal_streamchunkmatchs	            r   r   ImageCollection.build   s    X {{$$.v.dC  88D>!
)2{47H)I&$E% w??5 		A(O ${{1~HJ % HHX&660y-@@r   c                 j    U R                  U R                  R                  R                  U5      5      $ )a  
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_modelr4   r5   inspect_image)r   names     r   r"   ImageCollection.get?  s(      !!$++//"?"?"EFFr   Nc                 t    [        UU R                  R                  R                  X5      U R                  U S9$ )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.
)rZ   r!   r4   re   )rU   r4   r5   rz   )r   r   auth_configs      r   get_registry_data!ImageCollection.get_registry_dataQ  s4    " ++//66tI;;	
 	
r   c                     U R                   R                  R                  XUS9nU Vs/ s H  oPR                  US   5      PM     sn$ s  snf )a2  
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.
)r   allfiltersId)r4   r5   imagesr"   )r   r   r   r   r   rs         r   listImageCollection.listi  sD    * {{%%4'%J+/04a4!4000s   A	c                 h   U R                   R                  R                  U5      n/ nU H`  nSU;   aC  [        R                  " SUS   5      nU(       a"  UR                  S5      nUR                  U5        SU;   d  MT  [        US   5      e   U Vs/ s H  opR                  U5      PM     sn$ s  snf )aO  
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: )(.+)$r   r   )	r4   r5   
load_imager   r   r   appendr   r"   )r   datar   r   r   r   r   is           r   loadImageCollection.load  s      {{))$/E5 		@(O ${{1~HMM(+%$U7^44  &,,VV,,,s   B/c           	         [        U5      u  pU=(       d    U=(       d    SnSU;   a  [        R                  " S5        US	 U R                  R                  R
                  " U4USUS.UD6nU H  nM     U(       dA  U R                  SR                  XUR                  S5      (       a
  S5      5      $ S	5      5      $ U R                  U5      $ )
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)r1   r   all_tagsz	{0}{2}{1}r(   @:)
r	   warningswarnr4   r5   rf   r"   r   r,   r   )r   rI   r1   r   rJ   	image_tagpull_logrg   s           r   rf   ImageCollection.pull  s    L !5Z @
*Y*(vMM* x ;;??''
x
CI
 A 	 
 88K..y(A(A  GJ   yy$$r   c                 T    U R                   R                  R                  " U4SU0UD6$ )Nr1   )r4   r5   pushrH   s       r   r   ImageCollection.push  s%    {{##JBCB6BBr   c                 P    U R                   R                  R                  " U0 UD6  g rM   )r4   r5   r;   r   r[   rJ   s      r   r<   ImageCollection.remove  s    $$d5f5r   c                 N    U R                   R                  R                  " U0 UD6$ rM   )r4   r5   r   r   s      r   r   ImageCollection.search  s     {{%%t6v66r   c                 H    U R                   R                  R                  US9$ )N)r   )r4   r5   prune_images)r   r   s     r   pruneImageCollection.prune  s    {{++G+<<r   c                 N    U R                   R                  R                  " U0 UD6$ rM   )r4   r5   prune_buildsr   s      r   r   ImageCollection.prune_builds  s     {{++T<V<<r   rL   rM   )NFN)NF)r   rN   rO   rP   r   modelr   r"   r   r   r   rf   r   r   rQ   r<   r;   r   r   r   r   rS   rL   r   r   r   r      s    E_ABG$
010-@<%|C>>))DL6++33FN7%%--FN=**22EM=$1199Lr   r   c                 H    U c  0 n SU ;  a  US   U S'   SU ;  a  US   U S'   U $ )Nrm   Osro   ArchrL   )rd   engine_infos     r   rt   rt     s?    8$T*X%#.v#6 Or   )r   r   r   r5   r   	constantsr   errorsr   r   r   utilsr	   utils.json_streamr
   resourcer   r   r   rU   r   rt   rL   r   r   <module>r      sW     	   / @ @ ( + '@KE @KFH*5 H*VV:j V:rr   