a
   ^41wlBh                   @   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   1/usr/lib/python3.9/site-packages/docker/errors.pyr      s   r   c                 C   s   | j }z| d }W n  ty6   |jp,d }Y n0 t}|jdkrx|rtdt|v sndt|v sndt|v rtt}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                    sl   t t|  }|  r2d| jj| jj| jj}n"| 	 rTd| jj| jj| jj}| j
rhd|| j
}|S )Nz{0} Client Error for {1}: {2}z{0} Server Error for {1}: {2}z{0} ("{1}"))r   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   s(   | j d u rdS d| j   ko"dk S   S )NFi    r   r#   r   r   r   r   G   s    
zAPIError.is_client_errorc                 C   s(   | j d u rdS d| j   ko"dk S   S )NFr%   iX  r&   r#   r   r   r   r"   L   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   R   s   r   c                   @   s   e Zd ZdS )r   Nr)   r   r   r   r   r   V   s   r   c                   @   s   e Zd ZdS )InvalidVersionNr)   r   r   r   r   r*   Z   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,   b   s   r,   c                   @   s   e Zd ZdS )InvalidArgumentNr)   r   r   r   r   r-   f   s   r-   c                   @   s   e Zd ZdS )DeprecatedMethodNr)   r   r   r   r   r.   j   s   r.   c                   @   s   e Zd Zdd Zdd ZdS )TLSParameterErrorc                 C   s
   || _ d S r   msgr   r1   r   r   r   r   o   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.r0   r#   r   r   r   r   r   s    zTLSParameterError.__str__Nr   r   r   r   r   r   r   r   r   r/   n   s   r/   c                   @   s   e Zd ZdS )NullResourceNr)   r   r   r   r   r4   y   s   r4   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 u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   r5   r   )r   r6   r7   r8   r9   r:   errr1   r   r   r   r      s    zContainerError.__init__)r   r   r   r   r   r(   r   r   r   r   r5   }   s   r5   c                   @   s   e Zd Zdd ZdS )StreamParseErrorc                 C   s
   || _ d S r   r0   )r   r!   r   r   r   r      s    zStreamParseError.__init__N)r   r   r   r   r   r   r   r   r<      s   r<   c                       s   e Zd Z fddZ  ZS )
BuildErrorc                    s    t t| | || _|| _d S r   )r   r=   r   r1   	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>       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    
rM   c                   @   s   e Zd Zdd Zdd ZdS )MissingContextParameterc                 C   s
   || _ d S r   )param)r   rO   r   r   r   r      s    z MissingContextParameter.__init__c                 C   s   d | jS )Nzmissing parameter: {})r   rO   r#   r   r   r   r      s    zMissingContextParameter.__str__Nr3   r   r   r   r   rN      s   rN   c                   @   s   e Zd Zdd Zdd ZdS )ContextAlreadyExistsc                 C   s
   || _ d S r   rJ   r   rJ   r   r   r   r      s    zContextAlreadyExists.__init__c                 C   s   d | jS )Nzcontext {} already existsr   rJ   r#   r   r   r   r      s    zContextAlreadyExists.__str__Nr3   r   r   r   r   rP      s   rP   c                   @   s   e Zd Zdd Zdd ZdS )ContextExceptionc                 C   s
   || _ d S r   r0   r2   r   r   r   r      s    zContextException.__init__c                 C   s   | j S r   r0   r#   r   r   r   r      s    zContextException.__str__Nr3   r   r   r   r   rT      s   rT   c                   @   s   e Zd Zdd Zdd ZdS )ContextNotFoundc                 C   s
   || _ d S r   rQ   rR   r   r   r   r      s    zContextNotFound.__init__c                 C   s   d | jS )Nzcontext '{}' not foundrS   r#   r   r   r   r      s    zContextNotFound.__str__Nr3   r   r   r   r   rU      s   rU   )Zrequests	Exceptionr   r   
exceptionsZ	HTTPErrorr   r   r   r*   r+   r,   r-   r.   r/   r   r4   r5   RuntimeErrorr<   r=   r?   rM   rN   rP   rT   rU   r   r   r   r   <module>   s*   	0