o
    2.a&                     @   sT  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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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y   |jpd }Y nw t}|jdkr<|r:dt|v s7dt|v s7dt|v r:t}nt	}|| ||d)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explanation)
r   json
ValueError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  | || _|| _d S N)super__init__r   r   )selfr	   r   r   	__class__r   r   r   &   s   
zAPIError.__init__c                    sl   t   }|  rd| jj| jj| jj}n|  r(d| jj| jj| jj}| j	r4| d| j	 d}|S )Nz{} Client Error for {}: {}z{} Server Error for {}: {}z ("z"))
r   __str__is_client_errorformatr   r   urlreasonis_server_errorr   )r   r	   r   r   r   r   -   s   
zAPIError.__str__c                 C   s   | j d u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_errorD   s   zAPIError.is_errorc                 C   (   | j d u rdS d| j   kodk S   S )NFi    r   r%   r   r   r   r    G      
zAPIError.is_client_errorc                 C   r'   )NFr(   iX  r)   r%   r   r   r   r$   L   r*   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                   @      e Zd ZdS )r   Nr   r   r   r   r   r   r   r   R       r   c                   @   r-   )r   Nr.   r   r   r   r   r   V   r/   r   c                   @   r-   )InvalidVersionNr.   r   r   r   r   r0   Z   r/   r0   c                   @   r-   )InvalidRepositoryNr.   r   r   r   r   r1   ^   r/   r1   c                   @   r-   )InvalidConfigFileNr.   r   r   r   r   r2   b   r/   r2   c                   @   r-   )InvalidArgumentNr.   r   r   r   r   r3   f   r/   r3   c                   @   r-   )DeprecatedMethodNr.   r   r   r   r   r4   j   r/   r4   c                   @      e Zd Zdd Zdd ZdS )TLSParameterErrorc                 C   
   || _ d S r   msgr   r9   r   r   r   r   o      
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.r8   r%   r   r   r   r   r   r;   zTLSParameterError.__str__Nr   r   r   r   r   r   r   r   r   r6   n       r6   c                   @   r-   )NullResourceNr.   r   r   r   r   r>   y   r/   r>   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                    sT   || _ || _|| _|| _|| _|d urd| nd}d||||}t | d S )Nz: r
   z=Command '{}' in image '{}' returned non-zero exit status {}{})	containerexit_statuscommandimagestderrr!   r   r   )r   r@   rA   rB   rC   rD   errr9   r   r   r   r      s   zContainerError.__init__)r   r   r   r   r   r,   r   r   r   r   r?   }   s    r?   c                   @   s   e Zd Zdd ZdS )StreamParseErrorc                 C   r7   r   r8   )r   r#   r   r   r   r      r;   zStreamParseError.__init__N)r   r   r   r   r   r   r   r   rF      s    rF   c                       s   e Zd Z fddZ  ZS )
BuildErrorc                    s   t  | || _|| _d S r   )r   r   r9   	build_log)r   r#   rH   r   r   r   r      s   
zBuildError.__init__)r   r   r   r   r,   r   r   r   r   rG      s    rG   c                   @   r-   )ImageLoadErrorNr.   r   r   r   r   rI      r/   rI   c                 C   s^   dd t |D }|  dg}t|dkr|d n|d |d| td|S )	Nc                 S   s   g | ]}d | d qS )'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
   )sortedlenappendjoin	TypeError)namekwargsquoted_kwargstextr   r   r   create_unexpected_kwargs_error   s   
rX   c                   @   r5   )MissingContextParameterc                 C   r7   r   param)r   r[   r   r   r   r      r;   z MissingContextParameter.__init__c                 C   s   d| j  S )Nzmissing parameter: rZ   r%   r   r   r   r      s   zMissingContextParameter.__str__Nr<   r   r   r   r   rY      r=   rY   c                   @   r5   )ContextAlreadyExistsc                 C   r7   r   rT   r   rT   r   r   r   r      r;   zContextAlreadyExists.__init__c                 C      d| j  dS )Nzcontext z already existsr]   r%   r   r   r   r         zContextAlreadyExists.__str__Nr<   r   r   r   r   r\      r=   r\   c                   @   r5   )ContextExceptionc                 C   r7   r   r8   r:   r   r   r   r      r;   zContextException.__init__c                 C   s   | j S r   r8   r%   r   r   r   r      s   zContextException.__str__Nr<   r   r   r   r   ra      r=   ra   c                   @   r5   )ContextNotFoundc                 C   r7   r   r]   r^   r   r   r   r      r;   zContextNotFound.__init__c                 C   r_   )Nz	context 'z' not foundr]   r%   r   r   r   r      r`   zContextNotFound.__str__Nr<   r   r   r   r   rb      r=   rb   )requests	Exceptionr   r   
exceptions	HTTPErrorr   r   r   r0   r1   r2   r3   r4   r6   r   r>   r?   RuntimeErrorrF   rG   rI   rX   rY   r\   ra   rb   r   r   r   r   <module>   s,    	0