U
    K7\                     @   s  d dl Z G dd deZdd ZG dd de jjeZG dd	 d	eZG d
d deZG dd deZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deeZG dd deZG dd deZG dd deZG d d! d!eZd"d# ZdS )$    Nc                   @   s   e Zd ZdZdS )DockerExceptionz
    A base class from which all other exceptions inherit.

    If you want to catch all errors that the Docker SDK might raise,
    catch this base exception.
    N)__name__
__module____qualname____doc__ r   r   //usr/lib/python3/dist-packages/docker/errors.pyr      s   r   c                 C   s   | j }z| d }W n" tk
r8   |jp.d }Y nX t}|jdkrz|rvdt|kspdt|kspdt|krvt}nt	}|| ||ddS )	zH
    Create a suitable APIError from requests.exceptions.HTTPError.
    message i  zNo such imagez+not found: does not exist or no pull accesszrepository does not exist)responseexplanationN)
r   Zjson
ValueErrorZcontentstripAPIErrorstatus_codestrImageNotFoundNotFound)er   r   clsr   r   r   $create_api_error_from_http_exception   s"    

r   c                       sR   e Zd ZdZd fdd	Z fddZedd Zd	d
 Zdd Z	dd Z
  ZS )r   z%
    An HTTP error from the API.
    Nc                    s    t t| | || _|| _d S N)superr   __init__r   r   )selfr	   r   r   	__class__r   r   r   &   s    zAPIError.__init__c                    s`   t t|  }|  r,d| jj| jj}n|  rHd| jj| jj}| j	r\d|| j	}|S )Nz{0} Client Error: {1}z{0} Server Error: {1}z{0} ("{1}"))
r   r   __str__is_client_errorformatr   r   reasonis_server_errorr   )r   r	   r   r   r   r   -   s      zAPIError.__str__c                 C   s   | j d k	r| j jS d S r   )r   r   r   r   r   r   r   =   s    
zAPIError.status_codec                 C   s   |   p|  S r   )r   r!   r"   r   r   r   is_errorB   s    zAPIError.is_errorc                 C   s(   | j d krdS d| j   ko"dk S   S )NFi    r   r"   r   r   r   r   E   s    
zAPIError.is_client_errorc                 C   s(   | j d krdS d| j   ko"dk S   S )NFr$   iX  r%   r"   r   r   r   r!   J   s    
zAPIError.is_server_error)NN)r   r   r   r   r   r   propertyr   r#   r   r!   __classcell__r   r   r   r   r   "   s   
r   c                   @   s   e Zd ZdS )r   Nr   r   r   r   r   r   r   r   P   s   r   c                   @   s   e Zd ZdS )r   Nr(   r   r   r   r   r   T   s   r   c                   @   s   e Zd ZdS )InvalidVersionNr(   r   r   r   r   r)   X   s   r)   c                   @   s   e Zd ZdS )InvalidRepositoryNr(   r   r   r   r   r*   \   s   r*   c                   @   s   e Zd ZdS )InvalidConfigFileNr(   r   r   r   r   r+   `   s   r+   c                   @   s   e Zd ZdS )InvalidArgumentNr(   r   r   r   r   r,   d   s   r,   c                   @   s   e Zd ZdS )DeprecatedMethodNr(   r   r   r   r   r-   h   s   r-   c                   @   s   e Zd Zdd Zdd ZdS )TLSParameterErrorc                 C   s
   || _ d S r   msg)r   r0   r   r   r   r   m   s    zTLSParameterError.__init__c                 C   s
   | j d S )Nz. TLS configurations should map the Docker CLI client configurations. See https://docs.docker.com/engine/articles/https/ for API details.r/   r"   r   r   r   r   p   s    zTLSParameterError.__str__N)r   r   r   r   r   r   r   r   r   r.   l   s   r.   c                   @   s   e Zd ZdS )NullResourceNr(   r   r   r   r   r1   w   s   r1   c                       s    e Zd ZdZ fddZ  ZS )ContainerErrorzK
    Represents a container that has exited with a non-zero exit code.
    c                    sX   || _ || _|| _|| _|| _|d k	r0d|nd}d||||}tt| | d S )Nz: {}r
   z=Command '{}' in image '{}' returned non-zero exit status {}{})		containerexit_statuscommandimagestderrr   r   r2   r   )r   r3   r4   r5   r6   r7   errr0   r   r   r   r      s       zContainerError.__init__)r   r   r   r   r   r'   r   r   r   r   r2   {   s   r2   c                   @   s   e Zd Zdd ZdS )StreamParseErrorc                 C   s
   || _ d S r   r/   )r   r    r   r   r   r      s    zStreamParseError.__init__N)r   r   r   r   r   r   r   r   r9      s   r9   c                       s   e Zd Z fddZ  ZS )
BuildErrorc                    s    t t| | || _|| _d S r   )r   r:   r   r0   	build_log)r   r    r;   r   r   r   r      s    zBuildError.__init__)r   r   r   r   r'   r   r   r   r   r:      s   r:   c                   @   s   e Zd ZdS )ImageLoadErrorNr(   r   r   r   r   r<      s   r<   c                 C   s^   dd t |D }d| g}t|dkr6|d n
|d |d| td|S )	Nc                 S   s   g | ]}d  |qS )z'{}')r   ).0kr   r   r   
<listcomp>   s     z2create_unexpected_kwargs_error.<locals>.<listcomp>z{}()    z#got an unexpected keyword argument z!got unexpected keyword arguments z, r
   )sortedr   lenappendjoin	TypeError)namekwargsZquoted_kwargstextr   r   r   create_unexpected_kwargs_error   s    
rI   )Zrequests	Exceptionr   r   
exceptionsZ	HTTPErrorr   r   r   r)   r*   r+   r,   r-   r.   r   r1   r2   RuntimeErrorr9   r:   r<   rI   r   r   r   r   <module>   s"   	.