o
    S`B                     @   sD  d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z d dl	mZ d dl	mZ d dlmZ d	d
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ eeZG dd deZG dd deZ
e jdd Zdd Zdd Z dd Z!dd Z"dd  Z#d!d" Z$d#d$ Z%d%Z&d&Z'd'Z(d(Z)d)Z*d*Z+d+Z,dS ),    N)find_executable)dedent)APIError)ConnectionError)ReadTimeout)SSLError)ReadTimeoutError   )API_VERSION_TO_ENGINE_VERSION   )binarystr_to_unicode)is_docker_for_mac_installed)is_mac)	is_ubuntu)
is_windowsc                   @   s   e Zd Zdd Zdd ZdS )	UserErrorc                 C   s   t | | _d S N)r   stripmsg)selfr    r   4/usr/lib/python3/dist-packages/compose/cli/errors.py__init__   s   zUserError.__init__c                 C   s   | j S r   r   )r   r   r   r   __str__   s   zUserError.__str__N)__name__
__module____qualname__r   r   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   !   s    r   c              
   c   s   zd V  W d S  t y } z
td|  t d }~w tyI } z!|jr7t|jd tr7t| j	 t t
t| j W Y d }~d S d }~w ty] } z	t|| j t d }~w ttj	fyn   t| j	 t  ty } zt rdd l}t||jrt| t  d }~ww )NzSSL error: %sr   )r   logerrorr   RequestsConnectionErrorargs
isinstancer   log_timeout_errortimeoutexit_with_errorget_conn_error_messagebase_urlr   log_api_errorapi_versionr   socket	Exceptionr   
pywintypeslog_windows_pipe_error)clienter,   r   r   r   handle_connection_errors%   s:   

r0   c                 C   sN   | j dkrtd d S | j dkrtd d S tdt| j| j  d S )Nr	   zNCouldn't connect to Docker daemon. You might need to start Docker for Windows.   zThe current Compose file version is not compatible with your engine version. Please upgrade your Compose file to a more recent version, or set a COMPOSE_API_VERSION in your environment.z'Windows named pipe error: {} (code: {}))winerrorr   r   formatr   strerror)excr   r   r   r-   @   s   

r-   c                 C   s   t d|   d S )NzAn HTTP request took too long to complete. Retry with --verbose to obtain debug information.
If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: %s).)r   r   )r$   r   r   r   r#   Q   s
   r#   c                 C   sR   t | j}d|vrt| d S t|}|st| d S tdj|d d S )Nzclient is newer than serverzThe Docker Engine version is less than the minimum required by Compose. Your current project requires a Docker Engine of version {version} or greater.)version)r   explanationr   r   r
   getr3   )r/   client_versionr7   r6   r   r   r   r(   Z   s   



r(   c                 C   s   t t|   t r   )r   r   r   r   r   r   r   r   r   r%   n   s   r%   c                 C   sX   zt dd u rtdW S t rtW S t dd urtW S W n	 ty%   Y nw tj| dS )Ndockerz"Couldn't connect to Docker daemon.zdocker-machineurl)r   docker_not_found_msgr   conn_error_docker_for_macconn_error_docker_machineUnicodeDecodeErrorconn_error_genericr3   r;   r   r   r   r&   s   s   
r&   c                 C   s   d | t S )Nz({} You might need to install Docker:

{})r3   docker_install_url)problemr   r   r   r=      s   r=   c                   C   s"   t  rtS t r
tS t rtS tS r   )r   docker_install_url_macr   docker_install_url_ubuntur   docker_install_url_windowsdocker_install_url_genericr   r   r   r   rB      s   rB   z0https://docs.docker.com/engine/installation/mac/z8https://docs.docker.com/engine/installation/ubuntulinux/z4https://docs.docker.com/engine/installation/windows/z,https://docs.docker.com/engine/installation/z_
    Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
zP
    Couldn't connect to Docker daemon. You might need to start Docker for Mac.
z
    Couldn't connect to Docker daemon at {url} - is it running?

    If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
)-
contextlibloggingr*   distutils.spawnr   textwrapr   docker.errorsr   requests.exceptionsr   r    r   r   $requests.packages.urllib3.exceptionsr   constr
   utilsr   r   r   r   r   	getLoggerr   r   r+   r   contextmanagerr0   r-   r#   r(   r%   r&   r=   rB   rD   rE   rF   rG   r?   r>   rA   r   r   r   r   <module>   sF    
	
	