U
    —ùi±$  ã                   @  s
  d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ	 ej
rrddlmZ ddlmZ ddlmZ dd	lmZ G d
d„ deƒZG dd„ deƒZejejdef ejedf f 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 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'eƒZ(G d)d*„ d*e(ƒZ)G d+d,„ d,eƒZ*G d-d.„ d.eƒZ+G d/d0„ d0eƒZ,G d1d2„ d2e-eƒZ.G d3d4„ d4e.ƒZ/G d5d6„ d6e.ƒZ0G d7d8„ d8eƒZ1G d9d:„ d:eƒZ2G d;d<„ d<e2ƒZ3G d=d>„ d>e2ƒZ4G d?d@„ d@e2ƒZ5G dAdB„ dBe2ƒZ6G dCdD„ dDeƒZ7G dEdF„ dFe e-ƒZ8G dGdH„ dHeƒZ9G dIdJ„ dJee	ƒZG dKdL„ dLee	ƒZ:G dMdN„ dNeƒZ;G dOdP„ dPe<e0ƒZ=G dQdR„ dRe-ƒZ>G dSdT„ dTeƒZ?G dUdV„ dVeƒZ@dS )Wé    )ÚannotationsN)ÚMessageDefect)ÚIncompleteReadé   )ÚHTTPConnection)ÚConnectionPool)ÚHTTPResponse)ÚRetryc                   @  s   e Zd ZdZdS )Ú	HTTPErrorz#Base exception used by this module.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú6/tmp/pip-unpacked-wheel-z24cd2a5/urllib3/exceptions.pyr
      s   r
   c                   @  s   e Zd ZdZdS )ÚHTTPWarningz!Base warning used by this module.Nr   r   r   r   r   r      s   r   .c                      s8   e Zd ZdZddddœ‡ fdd„Zdd	œd
d„Z‡  ZS )Ú	PoolErrorz/Base exception for errors caused within a pool.r   ÚstrÚNone)ÚpoolÚmessageÚreturnc                   s    || _ tƒ  |› d|› �¡ d S ©Nz: )r   ÚsuperÚ__init__)Úselfr   r   ©Ú	__class__r   r   r   "   s    zPoolError.__init__Ú_TYPE_REDUCE_RESULT©r   c                 C  s
   | j dfS )N)NNr   ©r   r   r   r   Ú
__reduce__&   s    zPoolError.__reduce__©r   r   r   r   r   r"   Ú__classcell__r   r   r   r   r      s   r   c                      s:   e Zd ZdZdddddœ‡ fdd„Zdd	œd
d„Z‡  ZS )ÚRequestErrorz8Base exception for PoolErrors that have associated URLs.r   r   r   )r   Úurlr   r   c                   s   || _ tƒ  ||¡ d S ©N)r&   r   r   )r   r   r&   r   r   r   r   r   .   s    zRequestError.__init__r   r    c                 C  s   | j d | jd ffS r'   )r   r&   r!   r   r   r   r"   2   s    zRequestError.__reduce__r#   r   r   r   r   r%   +   s   r%   c                   @  s   e Zd ZdZdS )ÚSSLErrorz9Raised when SSL certificate fails in an HTTPS connection.Nr   r   r   r   r   r(   7   s   r(   c                      s4   e Zd ZU dZded< ddddœ‡ fdd„Z‡  ZS )	Ú
ProxyErrorz,Raised when the connection to a proxy fails.Ú	ExceptionÚoriginal_errorr   r   )r   Úerrorr   c                   s   t ƒ  ||¡ || _d S r'   )r   r   r+   )r   r   r,   r   r   r   r   A   s    zProxyError.__init__)r   r   r   r   Ú__annotations__r   r$   r   r   r   r   r)   ;   s   
r)   c                   @  s   e Zd ZdZdS )ÚDecodeErrorz;Raised when automatic decoding based on Content-Type fails.Nr   r   r   r   r   r.   F   s   r.   c                   @  s   e Zd ZdZdS )ÚProtocolErrorz>Raised when something unexpected happens mid-request/response.Nr   r   r   r   r   r/   J   s   r/   c                      s.   e Zd ZdZd
dddddœ‡ fdd	„Z‡  ZS )ÚMaxRetryErrora  Raised when the maximum number of retries is exceeded.

    :param pool: The connection pool
    :type pool: :class:`~urllib3.connectionpool.HTTPConnectionPool`
    :param str url: The requested Url
    :param reason: The underlying error
    :type reason: :class:`Exception`

    Nr   r   zException | Noner   )r   r&   Úreasonr   c                   s,   || _ d|› d|›d�}tƒ  |||¡ d S )NzMax retries exceeded with url: z (Caused by ú))r1   r   r   )r   r   r&   r1   r   r   r   r   r   `   s    zMaxRetryError.__init__)N©r   r   r   r   r   r$   r   r   r   r   r0   U   s    ÿr0   c                      s.   e Zd ZdZd
dddddœ‡ fdd	„Z‡  ZS )ÚHostChangedErrorz?Raised when an existing pool gets a request for a foreign host.é   r   r   zRetry | intr   )r   r&   Úretriesr   c                   s$   d|› �}t ƒ  |||¡ || _d S )Nz'Tried to open a foreign host with url: )r   r   r6   )r   r   r&   r6   r   r   r   r   r   m   s    
zHostChangedError.__init__)r5   r3   r   r   r   r   r4   j   s    ÿr4   c                   @  s   e Zd ZdZdS )ÚTimeoutStateErrorz1Raised when passing an invalid state to a timeoutNr   r   r   r   r   r7   u   s   r7   c                   @  s   e Zd ZdZdS )ÚTimeoutErrorz¿Raised when a socket timeout error occurs.

    Catching this error will catch both :exc:`ReadTimeoutErrors
    <ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.
    Nr   r   r   r   r   r8   y   s   r8   c                   @  s   e Zd ZdZdS )ÚReadTimeoutErrorzFRaised when a socket timeout occurs while receiving data from a serverNr   r   r   r   r   r9   �   s   r9   c                   @  s   e Zd ZdZdS )ÚConnectTimeoutErrorz@Raised when a socket timeout occurs while connecting to a serverNr   r   r   r   r   r:   ‡   s   r:   c                      s<   e Zd ZdZddddœ‡ fdd„Zeddœd	d
„ƒZ‡  ZS )ÚNewConnectionErrorzHRaised when we fail to establish a new connection. Usually ECONNREFUSED.r   r   r   )Úconnr   r   c                   s    || _ tƒ  |› d|› �¡ d S r   )r<   r   r   )r   r<   r   r   r   r   r   Ž   s    zNewConnectionError.__init__r    c                 C  s   t jdtdd� | jS )Nz\The 'pool' property is deprecated and will be removed in urllib3 v2.1.0. Use 'conn' instead.é   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarningr<   r!   r   r   r   r   ’   s    üzNewConnectionError.pool)r   r   r   r   r   Úpropertyr   r$   r   r   r   r   r;   ‹   s   r;   c                      s*   e Zd ZdZddddœ‡ fdd„Z‡  ZS )ÚNameResolutionErrorz'Raised when host name resolution fails.r   r   zsocket.gaierror)Úhostr<   r1   c                   s$   d|› d|› d�}t ƒ  ||¡ d S )NzFailed to resolve 'z' (r2   ©r   r   )r   rD   r<   r1   r   r   r   r   r   ¡   s    zNameResolutionError.__init__r3   r   r   r   r   rC   ž   s   rC   c                   @  s   e Zd ZdZdS )ÚEmptyPoolErrorzCRaised when a pool runs out of connections and no more are allowed.Nr   r   r   r   r   rF   ¦   s   rF   c                   @  s   e Zd ZdZdS )ÚFullPoolErrorzGRaised when we try to add a connection to a full pool in blocking mode.Nr   r   r   r   r   rG   ª   s   rG   c                   @  s   e Zd ZdZdS )ÚClosedPoolErrorzCRaised when a request enters a pool after the pool has been closed.Nr   r   r   r   r   rH   ®   s   rH   c                   @  s   e Zd ZdZdS )ÚLocationValueErrorz<Raised when there is something wrong with a given URL input.Nr   r   r   r   r   rI   ²   s   rI   c                      s(   e Zd ZdZdddœ‡ fdd„Z‡  ZS )ÚLocationParseErrorz=Raised when get_host or similar fails to parse the URL input.r   r   )Úlocationr   c                   s    d|› �}t ƒ  |¡ || _d S )NzFailed to parse: )r   r   rK   )r   rK   r   r   r   r   r   ¹   s    
zLocationParseError.__init__r3   r   r   r   r   rJ   ¶   s   rJ   c                      s&   e Zd ZdZddœ‡ fdd„Z‡  ZS )ÚURLSchemeUnknownz2Raised when a URL input has an unsupported scheme.r   )Úschemec                   s    d|› �}t ƒ  |¡ || _d S )NzNot supported URL scheme )r   r   rM   ©r   rM   r   r   r   r   r   Ã   s    
zURLSchemeUnknown.__init__r3   r   r   r   r   rL   À   s   rL   c                   @  s   e Zd ZdZdZdZdS )ÚResponseErrorzDUsed as a container for an error reason supplied in a MaxRetryError.ztoo many error responsesz&too many {status_code} error responsesN)r   r   r   r   ÚGENERIC_ERRORÚSPECIFIC_ERRORr   r   r   r   rO   Ê   s   rO   c                   @  s   e Zd ZdZdS )ÚSecurityWarningz0Warned when performing security reducing actionsNr   r   r   r   r   rR   Ñ   s   rR   c                   @  s   e Zd ZdZdS )ÚInsecureRequestWarningz/Warned when making an unverified HTTPS request.Nr   r   r   r   r   rS   Õ   s   rS   c                   @  s   e Zd ZdZdS )ÚNotOpenSSLWarningz)Warned when using unsupported SSL libraryNr   r   r   r   r   rT   Ù   s   rT   c                   @  s   e Zd ZdZdS )ÚSystemTimeWarningz0Warned when system time is suspected to be wrongNr   r   r   r   r   rU   Ý   s   rU   c                   @  s   e Zd ZdZdS )ÚInsecurePlatformWarningzIWarned when certain TLS/SSL configuration is not available on a platform.Nr   r   r   r   r   rV   á   s   rV   c                   @  s   e Zd ZdZdS )ÚDependencyWarningzc
    Warned when an attempt is made to import a module with missing optional
    dependencies.
    Nr   r   r   r   r   rW   å   s   rW   c                   @  s   e Zd ZdZdS )ÚResponseNotChunkedz;Response needs to be chunked in order to read it as chunks.Nr   r   r   r   r   rX   ì   s   rX   c                   @  s   e Zd ZdZdS )ÚBodyNotHttplibCompatiblez‡
    Body should be :class:`http.client.HTTPResponse` like
    (have an fp attribute which returns raw chunks) for read_chunked().
    Nr   r   r   r   r   rY   ð   s   rY   c                   @  sB   e Zd ZU dZded< ded< ddddœdd„Zd	d
œdd„ZdS )r   zÎ
    Response length doesn't match expected Content-Length

    Subclass of :class:`http.client.IncompleteRead` to allow int value
    for ``partial`` to avoid creating large objects on streamed reads.
    ÚintÚpartialÚexpectedr   )r[   r\   r   c                 C  s   || _ || _d S r'   ©r[   r\   )r   r[   r\   r   r   r   r     s    zIncompleteRead.__init__r   r    c                 C  s   d| j | jf S )Nz/IncompleteRead(%i bytes read, %i more expected)r]   r!   r   r   r   Ú__repr__  s    þzIncompleteRead.__repr__N)r   r   r   r   r-   r   r^   r   r   r   r   r   ÷   s
   
r   c                   @  s0   e Zd ZdZddddœdd„Zdd	œd
d„ZdS )ÚInvalidChunkLengthz+Invalid chunk length in a chunked response.r   Úbytesr   )ÚresponseÚlengthr   c                 C  s"   |  ¡ | _|j| _|| _|| _d S r'   )Útellr[   Úlength_remainingr\   ra   rb   )r   ra   rb   r   r   r   r     s    
zInvalidChunkLength.__init__r   r    c                 C  s   d| j | jf S )Nz0InvalidChunkLength(got length %r, %i bytes read))rb   r[   r!   r   r   r   r^     s    þzInvalidChunkLength.__repr__N)r   r   r   r   r   r^   r   r   r   r   r_     s   r_   c                   @  s   e Zd ZdZdS )ÚInvalidHeaderz(The header provided was somehow invalid.Nr   r   r   r   r   re     s   re   c                      s(   e Zd ZdZdddœ‡ fdd„Z‡  ZS )ÚProxySchemeUnknownz1ProxyManager does not support the supplied schemez
str | Noner   )rM   r   c                   s6   |dkrd }|d krd}nd|› d�}t ƒ  |¡ d S )NÚ	localhostz>Proxy URL had no scheme, should start with http:// or https://z!Proxy URL had unsupported scheme z , should use http:// or https://rE   rN   r   r   r   r   &  s    zProxySchemeUnknown.__init__r3   r   r   r   r   rf   !  s   rf   c                   @  s   e Zd ZdZdS )ÚProxySchemeUnsupportedz=Fetching HTTPS resources through HTTPS proxies is unsupportedNr   r   r   r   r   rh   2  s   rh   c                      s*   e Zd ZdZddddœ‡ fdd„Z‡  ZS )ÚHeaderParsingErrorzNRaised by assert_header_parsing, but we convert it to a log.warning statement.zlist[MessageDefect]zbytes | str | Noner   )ÚdefectsÚunparsed_datar   c                   s"   |pd› d|›�}t ƒ  |¡ d S )NÚUnknownz, unparsed data: rE   )r   rj   rk   r   r   r   r   r   9  s    zHeaderParsingError.__init__r3   r   r   r   r   ri   6  s   ri   c                   @  s   e Zd ZdZdS )ÚUnrewindableBodyErrorz9urllib3 encountered an error when trying to rewind a bodyNr   r   r   r   r   rm   @  s   rm   )AÚ
__future__r   ÚsocketÚtypingr?   Zemail.errorsr   Úhttp.clientr   Úhttplib_IncompleteReadÚTYPE_CHECKINGÚ
connectionr   Úconnectionpoolr   ra   r   Z
util.retryr	   r*   r
   ÚWarningr   ÚTupleÚCallableÚobjectr   r   r%   r(   r)   r.   r/   ÚConnectionErrorr0   r4   r7   r8   r9   r:   r;   rC   rF   rG   rH   Ú
ValueErrorrI   rJ   rL   rO   rR   rS   rT   rU   rV   rW   rX   rY   r_   re   ÚAssertionErrorrf   rh   ri   rm   r   r   r   r   Ú<module>   sh   ÿ


