
    x                     @    S SK r S SKJr  SSKJrJrJr   " S S5      rg)    N)datetime   )authtypesutilsc                   r    \ rS rSr\R
                  " S5      S 5       rSS jrS r  SS jr	S r
SS	 jrS
rg)DaemonApiMixin   z1.25c                 f    U R                  S5      nU R                  U R                  U5      S5      $ )z
Get data usage information.

Returns:
    (dict): A dictionary representing different resource categories
    and their respective data usage.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z
/system/dfT_url_result_get)selfurls     $lib/third_party/docker/api/daemon.pydfDaemonApiMixin.df   s+     ii%||DIIcND11    Nc                    [        U[        5      (       a  [        R                  " U5      n[        U[        5      (       a  [        R                  " U5      nU(       a  [        R                  " U5      nUUUS.nU R                  S5      nU R                  XeSSS9nU R                  XtS9n[        R                  " X5      $ )a  
Get real-time events from the server. Similar to the ``docker events``
command.

Args:
    since (UTC datetime or int): Get events from this point
    until (UTC datetime or int): Get events until this point
    filters (dict): Filter the events by event time, container or image
    decode (bool): If set to true, stream will be decoded into dicts on
        the fly. False by default.

Returns:
    A :py:class:`docker.types.daemon.CancellableStream` generator

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

Example:

    >>> for event in client.events(decode=True)
    ...   print(event)
    {u'from': u'image/with:tag',
     u'id': u'container-id',
     u'status': u'start',
     u'time': 1423339459}
    ...

    or

    >>> events = client.events()
    >>> for event in events:
    ...   print(event)
    >>> # and cancel from another thread
    >>> events.close()
)sinceuntilfiltersz/eventsTN)paramsstreamtimeout)decode)

isinstancer   r   datetime_to_timestampconvert_filtersr   r   _stream_helperr   CancellableStream)	r   r   r   r   r   r   r   responser   s	            r   eventsDaemonApiMixin.events   s    L eX&&//6EeX&&//6E++G4G 

 ii	"99Sd9K$$X$=&&v88r   c                 b    U R                  U R                  U R                  S5      5      S5      $ )z
Display system-wide information. Identical to the ``docker info``
command.

Returns:
    (dict): The info as a dict

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/infoTr   r   r   r   s    r   infoDaemonApiMixin.infoS   s'     ||DIIdii&894@@r   c                    U(       aH  [         R                  R                  U5      (       a$  [        R                  " X`R
                  S9U l        OOU R                  (       a  U R                  R                  (       a#  [        R                  " U R
                  S9U l        U R                  R                  U5      nU(       a  UR                  SS5      U:X  a	  U(       d  U$ UUUUS.nU R                  U R                  S5      US9n	U	R                  S:X  a3  U R                  R                  U=(       d    [        R                  U5        U R                  U	SS	9$ )
a  
Authenticate with a registry. Similar to the ``docker login`` command.

Args:
    username (str): The registry username
    password (str): The plaintext password
    email (str): The email for the registry account
    registry (str): URL to the registry.  E.g.
        ``https://index.docker.io/v1/``
    reauth (bool): Whether or not to refresh existing authentication on
        the Docker server.
    dockercfg_path (str): Use a custom path for the Docker config file
        (default ``$HOME/.docker/config.json`` if present,
        otherwise ``$HOME/.dockercfg``)

Returns:
    (dict): The response from the login request

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
)credstore_envusernameN)r-   passwordemailserveraddressz/auth)data   Tjson)ospathexistsr   load_configr,   _auth_configsis_emptyresolve_authconfigget
_post_jsonr   status_codeadd_auth
INDEX_NAMEr   )
r   r-   r.   r/   registryreauthdockercfg_pathauthcfgreq_datar#   s
             r   loginDaemonApiMixin.logina   s   : bggnn^<<!%!1!1.@.@"D ##t'9'9'B'B!%!1!1"00"D $$77A w{{:t4@N ! %	
 ??499W#5H?E3&''(CDOOXN||H4|00r   c                 f    U R                  U R                  U R                  S5      5      5      S:H  $ )z
Checks the server is responsive. An exception will be raised if it
isn't responding.

Returns:
    (bool) The response from the server.

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/_pingOKr'   r(   s    r   pingDaemonApiMixin.ping   s*     ||DIIdii&9:;tCCr   c                 `    U R                  SUS9nU R                  U R                  U5      SS9$ )z
Returns version information from the server. Similar to the ``docker
version`` command.

Returns:
    (dict): The server version information

Raises:
    :py:class:`docker.errors.APIError`
        If the server returns an error.
z/version)versioned_apiTr3   r   )r   api_versionr   s      r   versionDaemonApiMixin.version   s1     ii
+i>||DIIcN|66r   )r9   )NNNN)NNNFN)T)__name__
__module____qualname____firstlineno__r   minimum_versionr   r$   r)   rF   rJ   rO   __static_attributes__ r   r   r	   r	      sF    
6"2 #299vA CG+/71rD7r   r	   )r5   r    r   r   r   r	   rW   r   r   <module>rY      s    	  ! !n7 n7r   