o
    2.ax                     @   s:   d dl Z d dlmZ ddlmZmZmZ G dd dZdS )    N)datetime   )authtypesutilsc                   @   sP   e Zd Zeddd ZdddZdd Z		dd
dZdd Z	dddZ
dS )DaemonApiMixinz1.25c                 C   s   |  d}| | |dS )a(  
        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url r   3/usr/lib/python3/dist-packages/docker/api/daemon.pydf   s   
zDaemonApiMixin.dfNc           	      C   sx   t |tr
t|}t |trt|}|rt|}|||d}| d}| j||ddd}| j||d}t	||S )ar  
        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streamZtimeout)decode)

isinstancer   r   Zdatetime_to_timestampZconvert_filtersr	   r   Z_stream_helperr   ZCancellableStream)	r   r   r   r   r   r   r   responser   r   r   r   events   s   
&




zDaemonApiMixin.eventsc                 C   s   |  | | ddS )a  
        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   r   r   r   infoS   s   zDaemonApiMixin.infoFc           
      C   s   |rt j|rtj|| jd| _n| jr| jjr!tj| jd| _| j|}|r5|	dd|kr5|s5|S ||||d}| j
| d|d}	|	jdkrU| j|pRtj| | j|	dd	S )
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emailZserveraddressz/auth)data   TZjson)ospathexistsr   Zload_configr   Z_auth_configsZis_emptyZresolve_authconfiggetZ
_post_jsonr	   Zstatus_codeZadd_authZ
INDEX_NAMEr
   )
r   r   r   r    registryZreauthZdockercfg_pathZauthcfgZreq_datar   r   r   r   logina   s,   

zDaemonApiMixin.loginc                 C   s   |  | | ddkS )a!  
        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/_pingZOKr   r   r   r   r   ping   s   zDaemonApiMixin.pingTc                 C   s"   | j d|d}| j| |ddS )a&  
        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)Zversioned_apiTr#   r   )r   api_versionr   r   r   r   version   s   zDaemonApiMixin.version)NNNN)NNNFN)T)__name__
__module____qualname__r   Zminimum_versionr   r   r   r)   r*   r,   r   r   r   r   r      s    

;
9r   )r$   r    r   r   r   r   r   r   r   r   <module>   s    