
    O                         S SK r S SKrSSKJrJrJr  SSKJr  \ R                  " \	5      r
 " S S5      rS r  S	S jrg)
    N   )autherrorsutils)DEFAULT_DATA_CHUNK_SIZEc                   2   \ rS rSr\R
                  " S5      \4S j5       r\R
                  " S5      S 5       rSS jr	  SS jr
  SS jr  SS	 jr  SS
 jr  SS jr  SS jr\R
                  " S5      S 5       r\R"                  " S5      \R
                  " S5      SS j5       5       rSS jr\R"                  " S5      SS j5       r  SS jr  SS jr\R
                  " S5      SS j5       rSS jr\R
                  " S5      S S j5       rSrg)!ImageApiMixin
   imagec                 f    U R                  U R                  SU5      SS9nU R                  X2S5      $ )ae  
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ress       #lib/third_party/docker/api/image.py	get_imageImageApiMixin.get_image   s5    4 ii		"3U;DiI&&s>>    c                 h    U R                  U R                  SU5      5      nU R                  US5      $ )z
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   r   r   s      r   historyImageApiMixin.history)   s/     ii		"7?@||C&&r   Nc                    U(       a  SOSU(       a  SOSS.nU(       a;  [         R                  " U R                  S5      (       a  XS'   OU(       a  XS'   OSU0nU(       a  [         R                  " U5      US'   U R	                  U R                  U R                  S5      US	9S
5      nU(       a  U Vs/ s H  owS   PM	     sn$ U$ s  snf )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paramsTId)r   
version_lt_versionconvert_filtersr   r   r   )r   namequietr   r#   r%   r   xs           r   imagesImageApiMixin.images;   s    . #1
 v66#'x +/K(*D1G % 5 5g >F9ll499TYY~%>v9N!%()SdGS))
 *s   4Cc                 @   U(       d  U(       d  [         R                  " S5      eU R                  S5      n[        X#U[	        U[
        5      (       a  UOSUS9nSS0n	U(       d  UR                  S5      S:w  a   U R                  U R                  USUS	95      $ [	        U[
        5      (       a6  [        US
5       n
U R                  U R                  XzXSS95      sSSS5        $ U(       a  SU	S'   U R                  U R                  XqXS95      $ ! , (       d  f       g= f)a  
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r8   r%   headerstimeoutchunkedzTransfer-Encoding)r8   r%   r;   )
r   DockerExceptionr   _import_image_params
isinstancestrgetr   _postopen)r   r2   
repositorytagr   r3   
stream_srcur%   r;   fs              r   import_imageImageApiMixin.import_imagef   s   * u((:  II&'%U"3,,$

 "#45FJJy)S0<<

14
7  S!!c4A||JJ&4   ! /8+,<<

1v
G  !s   : D
Dc           
          U R                  S5      n[        X#SUS9nSS0nU R                  U R                  XQXgSS95      $ )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
r0   r7   r1   r4   r5   Nr:   )r   r?   r   rC   )r   r8   rE   rF   r3   rH   r%   r;   s           r   import_image_from_data$ImageApiMixin.import_image_from_data   sZ     II&'%g
 "#45||JJVd  
 	
r   c                 "    U R                  XX4S9$ )a"  
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.
r2   rE   rF   r3   rJ   )r   filenamerE   rF   r3   s        r   import_image_from_file$ImageApiMixin.import_image_from_file   s!       S ! 
 	
r   c                 &    U R                  USX#US9$ )NT)r2   rG   rE   rF   r3   rQ   )r   r   rE   rF   r3   s        r   import_image_from_stream&ImageApiMixin.import_image_from_stream   s$      4J ! 
 	
r   c                 "    U R                  XX4S9$ )z
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
rP   rQ   )r   urlrE   rF   r3   s        r   import_image_from_url#ImageApiMixin.import_image_from_url   s!        ! 
 	
r   c                 "    U R                  XX4S9$ )a  
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
)r   rE   rF   r3   rQ   )r   r   rE   rF   r3   s        r   import_image_from_image%ImageApiMixin.import_image_from_image   s!       C ! 
 	
r   c                 d    U R                  U R                  U R                  SU5      5      S5      $ )aG  
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r   r   r   )r   r   s     r   inspect_imageImageApiMixin.inspect_image   s/    " ||IIdii 2E:;T
 	
r   z1.30c                 >   [         R                  " U5      u  p40 nUc"  [         R                  " X5      nU(       a  XeS'   O.[        R	                  S5        [         R
                  " U5      US'   U R                  SU5      nU R                  U R                  XuS9S5      $ )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.
X-Registry-AuthSending supplied auth configz/distribution/{0}/json)r;   T)	r   resolve_repository_nameget_config_headerlogdebugencode_headerr   r   r   )r   r   auth_configregistry_r;   headerrY   s           r   inspect_distribution"ImageApiMixin.inspect_distribution   s    & 2259++D;F-3)*II45)-););K)HG%&ii0%8||IIcI+T
 	
r   c                 \   0 nUb@  [         R                  " U R                  S5      (       a  [        R                  " S5      eX#S'   U R                  U R                  S5      XSS9n[         R                  " U R                  S5      (       a  U R                  USS9$ U R                  U5        g)	a  
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.
Nz1.23z,quiet is not supported in API version < 1.23r+   z/images/loadT)r8   r%   r   decode)
r   r'   r(   r   InvalidVersionrC   r   version_gte_stream_helper_raise_for_status)r   r8   r+   r%   r   s        r   
load_imageImageApiMixin.load_image#  s    $ v66++B  $7OjjIIn%D  
 T]]F33&&s4&88s#r   r    c                     U R                  S5      n0 nUb  [        R                  " U5      US'   U R                  U R	                  X#S9S5      $ )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/pruner#   r$   T)r   r   r)   r   rC   )r   r#   rY   r%   s       r   prune_imagesImageApiMixin.prune_imagesF  sN    & ii( % 5 5g >F9||DJJsJ:DAAr   c                    [         R                  " U5      u  pU=(       d    U=(       d    SnU(       a  Sn[        R                  " U5      u  pUUS.n0 nUc"  [        R                  " X	5      nU(       a  XS'   O.[
        R                  S5        [        R                  " U5      US'   Ub@  [         R                  " U R                  S5      (       a  [        R                  " S5      eXkS'   U R                  U R                  S	5      XUSS
9nU R                  U5        U(       a  U R                  XS9$ U R!                  U5      $ )aI  
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:

    >>> resp = client.api.pull('busybox', stream=True, decode=True)
    ... for line in resp:
    ...     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)rF   	fromImagerd   re   z1.32z0platform was only introduced in API version 1.32platformr0   )r%   r;   r   r<   rr   )r   parse_repository_tagr   rf   rg   rh   ri   rj   r'   r(   r   rt   rC   r   rw   rv   r   )r   rE   rF   r   rk   rs   r   all_tags	image_tagrl   	repo_namer%   r;   rn   responses                  r   pullImageApiMixin.pull_  s8   X !& : :: F
*Y*(C":::F #
 ++D;F-3)*II45)-););K)HG%&v66++F  "*:::II&'4  

 	x(&&x&??||H%%r   c                    U(       d  [         R                  " U5      u  p[        R                  " U5      u  pgU R	                  SU5      nSU0n	0 n
Uc"  [        R
                  " X5      nU(       a  XS'   O.[        R                  S5        [        R                  " U5      U
S'   U R                  USXU	S9nU R                  U5        U(       a  U R                  XS9$ U R                  U5      $ )aW  
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:
    >>> resp = client.api.push(
    ...     'yourname/app',
    ...     stream=True,
    ...     decode=True,
    ... )
    ... for line in resp:
    ...   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}/pushrF   Nrd   re   )r;   r   r%   rr   )r   r   r   rf   r   rg   rh   ri   rj   
_post_jsonrw   rv   r   )r   rE   rF   r   rk   rs   rl   r   rH   r%   r;   rn   r   s                r   pushImageApiMixin.push  s    L #88DOJ":::FII(*53
 ++D;F-3)*II45)-););K)HG%&??tWF # 
 	x(&&x&??||H%%r   c                 n    X#S.nU R                  U R                  SU5      US9nU R                  US5      $ )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}r$   T)_deleter   r   )r   r   r   r   r%   r   s         r   remove_imageImageApiMixin.remove_image  s:     !5ll499]E:6lJ||C&&r   c                 v    SU0nUb  X#S'   U R                  U R                  U R                  S5      US9S5      $ )aF  
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.
termlimitz/images/searchr$   Tr`   )r   r   r   r%   s       r   searchImageApiMixin.search  sH      $#7O||IIdii 01&IA
 	
r   c                     UUU(       a  SOSS.nU R                  SU5      nU R                  XeS9nU R                  U5        UR                  S:H  $ )a  
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)
r   r   )rF   repor   z/images/{0}/tagr$      )r   rC   rw   status_code)r   r   rE   rF   r   r%   rY   r   s           r   rF   ImageApiMixin.tag  sX    0 QQ

 ii)51jjj,s##%%r    )NFFN)NNNNNFNNN)N)NFNFNF)NFNF)FFNF)__name__
__module____qualname____firstlineno__r   check_resourcer   r   r   r-   rJ   rM   rS   rV   rZ   r]   ra   minimum_versionro   rx   r{   r   r   r   r   rF   __static_attributes__r   r   r   r	   r	   
   s   
'"*A ? #?8 '"' #'")V GK.32h AE'+
. EI'+
& EI)-
 ?C&*
 CG(,
  '"
 #
( 6"
'" 
 # # 
D!$F 6"B #B0 DH38S&j DH@&D '"' #'
2 '"& #&r   r	   c                      [        U [        5      =(       a    [        R                  R	                  U 5      $ ! [
         a     gf = fr   )r@   rA   ospathisfile	TypeError)r2   s    r   is_filer   ?  s?    sC   GGNN3	
  s   58 
AAc                     U US.nU(       a  X%S'   O!U(       a  [        U5      (       d  X5S'   OSUS'   U(       a  XES'   U$ )N)r   rF   r   r6   r7   r3   )r   )r   rF   r   r2   r3   r%   s         r   r?   r?   I  sK     F #{	WS\\yy#yMr   r   )loggingr    r   r   r   	constantsr   	getLoggerr   rh   r	   r   r?   r   r   r   <module>r      sC     	 " " /!r& r&j 59!%r   