o
    .j*                     @  s  d dl mZ d dlZd dlZd dlmZ ejrMd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dur[ejZn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 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/d0 d0e/Z0G d1d2 d2e#Z1G d3d4 d4e#Z2G d5d6 d6e#Z3G d7d8 d8e4e Z5G d9d: d:e5Z6G d;d< d<e5Z7G d=d> d>e Z8G d?d@ d@e"Z9G dAdB dBe9Z:G dCdD dDe9Z;G dEdF dFe9Z<G dGdH dHe9Z=G dIdJ dJe"Z>G dKdL dLe'e4Z?G dMdN dNe Z@G dOdP dPe'ZAG dQdR dRe'ZBG dSdT dTe ZCG dUdV dVeDe7ZEG dWdX dXe4ZFG dYdZ dZe ZGG d[d\ d\e ZHG d]d^ d^e ZIG d_d` d`e ZJG dadb dbe ZKG dcdd ddeKZLG dedf dfeKZMdS )g    )annotationsN)MessageDefect   )AsyncHTTPConnection)AsyncConnectionPool)AsyncHTTPResponse)_TYPE_REDUCE_RESULT)ResponsePromise)HTTPConnection)ConnectionPool)HTTPResponse)Retry)
stdlib_sslc                   @  s   e Zd ZdS )BaseSSLErrorN)__name__
__module____qualname__ r   r   G/home/thesage/.local/lib/python3.10/site-packages/urllib3/exceptions.pyr      s    r   c                   @     e Zd ZdZdS )	HTTPErrorz#Base exception used by this module.Nr   r   r   __doc__r   r   r   r   r           r   c                   @  r   )HTTPWarningz!Base warning used by this module.Nr   r   r   r   r   r   $   r   r   c                      ,   e Zd ZdZd fdd	ZdddZ  ZS )	PoolErrorz/Base exception for errors caused within a pool.pool$ConnectionPool | AsyncConnectionPoolmessagestrreturnNonec                       || _ t | d|  d S Nz: )r   super__init__)selfr   r   	__class__r   r   r&   +   s   zPoolError.__init__r   c                 C  
   | j dfS N)NNr(   r'   r   r   r   
__reduce__1      
zPoolError.__reduce__)r   r   r   r    r!   r"   r!   r   r   r   r   r   r&   r-   __classcell__r   r   r(   r   r   (       r   c                      s,   e Zd ZdZd fd	d
ZdddZ  ZS )RequestErrorz8Base exception for PoolErrors that have associated URLs.r   r   urlr    r   r!   r"   c                   s   || _ t || d S N)r4   r%   r&   )r'   r   r4   r   r(   r   r   r&   9   s   zRequestError.__init__r   c                 C  s   | j d | jd ffS r5   )r)   r4   r,   r   r   r   r-   ?   s   zRequestError.__reduce__)r   r   r4   r    r   r    r!   r"   r/   r0   r   r   r(   r   r3   6   r2   r3   c                   @  r   )SSLErrorz9Raised when SSL certificate fails in an HTTPS connection.Nr   r   r   r   r   r6   D   r   r6   c                      s,   e Zd ZU dZded< d fd	d
Z  ZS )
ProxyErrorz,Raised when the connection to a proxy fails.	Exceptionoriginal_errorr   r    errorr!   r"   c                   s   t  || || _d S r5   )r%   r&   r9   )r'   r   r:   r(   r   r   r&   N   s   
zProxyError.__init__)r   r    r:   r8   r!   r"   )r   r   r   r   __annotations__r&   r1   r   r   r(   r   r7   H   s   
 r7   c                   @  r   )DecodeErrorz;Raised when automatic decoding based on Content-Type fails.Nr   r   r   r   r   r<   S   r   r<   c                   @  r   )ProtocolErrorz>Raised when something unexpected happens mid-request/response.Nr   r   r   r   r   r=   W   r   r=   c                      &   e Zd ZdZ	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   r4   r    reasonException | Noner!   r"   c                   s,   || _ d| d|d}t ||| d S )NzMax retries exceeded with url: z (Caused by ))r@   r%   r&   )r'   r   r4   r@   r   r(   r   r   r&   m   s   zMaxRetryError.__init__r5   )r   r   r4   r    r@   rA   r!   r"   r   r   r   r   r&   r1   r   r   r(   r   r?   b   s    r?   c                      r>   )HostChangedErrorz?Raised when an existing pool gets a request for a foreign host.   r   r   r4   r    retriesRetry | intr!   r"   c                   s$   d| }t  ||| || _d S )Nz'Tried to open a foreign host with url: )r%   r&   rF   )r'   r   r4   rF   r   r(   r   r   r&   }   s   

zHostChangedError.__init__)rE   )r   r   r4   r    rF   rG   r!   r"   rC   r   r   r(   r   rD   z   s    rD   c                   @  r   )TimeoutStateErrorz1Raised when passing an invalid state to a timeoutNr   r   r   r   r   rH      r   rH   c                   @  r   )TimeoutErrorzRaised when a socket timeout error occurs.

    Catching this error will catch both :exc:`ReadTimeoutErrors
    <ReadTimeoutError>` and :exc:`ConnectTimeoutErrors <ConnectTimeoutError>`.
    Nr   r   r   r   r   rI      r   rI   c                   @  r   )ReadTimeoutErrorzFRaised when a socket timeout occurs while receiving data from a serverNr   r   r   r   r   rJ      r   rJ   c                   @  r   )ConnectTimeoutErrorz@Raised when a socket timeout occurs while connecting to a serverNr   r   r   r   r   rK      r   rK   c                      r   )NewConnectionErrorzHRaised when we fail to establish a new connection. Usually ECONNREFUSED.connKHTTPConnection | AsyncHTTPConnection | ConnectionPool | AsyncConnectionPoolr   r    r!   r"   c                   r#   r$   )rM   r%   r&   )r'   rM   r   r(   r   r   r&      s   zNewConnectionError.__init__r   c                 C  r*   r+   r(   r,   r   r   r   r-      r.   zNewConnectionError.__reduce__)rM   rN   r   r    r!   r"   r/   r0   r   r   r(   r   rL      s    rL   c                      s,   e Zd ZdZd fdd	ZdddZ  ZS )NameResolutionErrorz'Raised when host name resolution fails.hostr    rM   rN   r@   socket.gaierrorc                   s$   d| d| d}t  || d S )NzFailed to resolve 'z' (rB   r%   r&   )r'   rP   rM   r@   r   r(   r   r   r&      s   	zNameResolutionError.__init__r!   r   c                 C  r*   )N)NNNr(   r,   r   r   r   r-      r.   zNameResolutionError.__reduce__)rP   r    rM   rN   r@   rQ   r/   r0   r   r   r(   r   rO      s    rO   c                   @  r   )EmptyPoolErrorzCRaised when a pool runs out of connections and no more are allowed.Nr   r   r   r   r   rS      r   rS   c                   @  r   )FullPoolErrorzGRaised when we try to add a connection to a full pool in blocking mode.Nr   r   r   r   r   rT      r   rT   c                   @  r   )ClosedPoolErrorzCRaised when a request enters a pool after the pool has been closed.Nr   r   r   r   r   rU      r   rU   c                   @  r   )LocationValueErrorz<Raised when there is something wrong with a given URL input.Nr   r   r   r   r   rV      r   rV   c                      "   e Zd ZdZd fddZ  ZS )	LocationParseErrorz=Raised when get_host or similar fails to parse the URL input.locationr    r!   r"   c                       d| }t  | || _d S )NzFailed to parse: )r%   r&   rY   )r'   rY   r   r(   r   r   r&         

zLocationParseError.__init__)rY   r    r!   r"   rC   r   r   r(   r   rX          rX   c                      s"   e Zd ZdZd fddZ  ZS )URLSchemeUnknownz2Raised when a URL input has an unsupported scheme.schemer    c                   rZ   )NzNot supported URL scheme )r%   r&   r^   r'   r^   r   r(   r   r   r&      r[   zURLSchemeUnknown.__init__)r^   r    rC   r   r   r(   r   r]      r\   r]   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   r`      s    r`   c                   @  r   )SecurityWarningz0Warned when performing security reducing actionsNr   r   r   r   r   rc      r   rc   c                   @  r   )InsecureRequestWarningz/Warned when making an unverified HTTPS request.Nr   r   r   r   r   rd      r   rd   c                   @  r   )NotOpenSSLWarningz)Warned when using unsupported SSL libraryNr   r   r   r   r   re      r   re   c                   @  r   )SystemTimeWarningz0Warned when system time is suspected to be wrongNr   r   r   r   r   rf      r   rf   c                   @  r   )InsecurePlatformWarningzIWarned when certain TLS/SSL configuration is not available on a platform.Nr   r   r   r   r   rg      r   rg   c                   @  r   )DependencyWarningzc
    Warned when an attempt is made to import a module with missing optional
    dependencies.
    Nr   r   r   r   r   rh     r   rh   c                   @  r   )ResponseNotChunkedz;Response needs to be chunked in order to read it as chunks.Nr   r   r   r   r   ri     r   ri   c                   @  r   )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   rj     r   rj   c                   @  s,   e Zd ZdZddd	d
ZdddZejZdS )IncompleteReadz
    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.
    Npartialintexpected
int | Noner!   r"   c                 C  s   || _ || _d S r5   )rl   rn   )r'   rl   rn   r   r   r   r&     s   
zIncompleteRead.__init__r    c                 C  s.   | j d urd| j d| j  dS d| j dS )NzIncompleteRead(z bytes read, z more expected)z bytes read))rn   rl   r,   r   r   r   __repr__"  s   
zIncompleteRead.__repr__r5   )rl   rm   rn   ro   r!   r"   r!   r    )r   r   r   r   r&   rp   object__str__r   r   r   r   rk     s
    

rk   c                   @  s$   e Zd ZdZddd	ZdddZdS )InvalidChunkLengthz+Invalid chunk length in a chunked response.response HTTPResponse | AsyncHTTPResponselengthbytesr!   r"   c                 C  s"   |  | _|j| _|| _|| _d S r5   )tellrl   length_remainingrn   ru   rw   )r'   ru   rw   r   r   r   r&   -  s   

zInvalidChunkLength.__init__r    c                 C  s   d| j | jf S )Nz0InvalidChunkLength(got length %r, %i bytes read))rw   rl   r,   r   r   r   rp   5  s   zInvalidChunkLength.__repr__N)ru   rv   rw   rx   r!   r"   rq   )r   r   r   r   r&   rp   r   r   r   r   rt   *  s    
rt   c                   @  r   )InvalidHeaderz(The header provided was somehow invalid.Nr   r   r   r   r   r{   <  r   r{   c                      rW   )	ProxySchemeUnknownz1ProxyManager does not support the supplied schemer^   
str | Noner!   r"   c                   s6   |dkrd }|d u 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://rR   r_   r(   r   r   r&   E  s   zProxySchemeUnknown.__init__)r^   r}   r!   r"   rC   r   r   r(   r   r|   @  s    r|   c                   @  r   )ProxySchemeUnsupportedz=Fetching HTTPS resources through HTTPS proxies is unsupportedNr   r   r   r   r   r   Q  r   r   c                      s"   e Zd ZdZd
 fdd	Z  ZS )HeaderParsingErrorzNRaised by assert_header_parsing, but we convert it to a log.warning statement.defectslist[MessageDefect]unparsed_databytes | str | Noner!   r"   c                   s"   |pd d|}t  | d S )NUnknownz, unparsed data: rR   )r'   r   r   r   r(   r   r   r&   X  s   zHeaderParsingError.__init__)r   r   r   r   r!   r"   rC   r   r   r(   r   r   U  r\   r   c                   @  r   )UnrewindableBodyErrorz9urllib3 encountered an error when trying to rewind a bodyNr   r   r   r   r   r   _  r   r   c                   @  s   e Zd ZdZd	ddZdS )
EarlyResponsez;urllib3 received a response prior to sending the whole bodypromiser	   r!   r"   c                 C  s
   || _ d S r5   )r   )r'   r   r   r   r   r&   f  s   
zEarlyResponse.__init__N)r   r	   r!   r"   )r   r   r   r   r&   r   r   r   r   r   c  s    r   c                   @  r   )ResponseNotReadyzKept for BCNr   r   r   r   r   r   j  r   r   c                   @  r   )RecoverableErrorzRThis error is never leaked in the upper stack, it serves only an internal purpose.Nr   r   r   r   r   r   n  r   r   c                   @  r   )MustDowngradeErrorzRAn error occurred with a protocol and can be circumvented using an older protocol.Nr   r   r   r   r   r   r  r   r   c                   @  r   )MustRedialErrorz3Unused legacy exception. Remove it in a next major.Nr   r   r   r   r   r   v  r   r   )N
__future__r   sockettypingemail.errorsr   TYPE_CHECKING_async.connectionr   _async.connectionpoolr   _async.responser   _typingr   backendr	   
connectionr
   connectionpoolr   ru   r   
util.retryr   contrib.anytlsr   _stdlib_sslr6   r   BaseExceptionr8   r   Warningr   r   r3   r7   r<   r=   ConnectionErrorr?   rD   rH   rI   rJ   rK   rL   rO   rS   rT   rU   
ValueErrorrV   rX   r]   r`   rc   rd   re   rf   rg   rh   ri   rj   rk   rt   r{   AssertionErrorr|   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s|    


