a
    Tf3                     @  s  d Z ddlmZ ddlZddlZddlmZ ddlZddlm	Z	m
Z
mZmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZ dd	lm Z m!Z!m"Z"m#Z#m$Z$ dd
l%m&Z& ddl'm(Z(m)Z) ej*dddZ+ej*dddZ,ej-ej.e/e/e/f ej.e/e/ej-e0e1f f ej.e/e/de/f f Z2ej3ddddZ4ejeejeejeejeejeejeejeejeejeejeejeejeejeejeiZ5G dd de#Z6G dd de)Z7G dd de Z8G dd de(Z9dS )a  
Custom transports, with nicely configured defaults.

The following additional keyword arguments are currently supported by httpcore...

* uds: str
* local_address: str
* retries: int

Example usages...

# Disable HTTP/2 on a single specific domain.
mounts = {
    "all://": httpx.HTTPTransport(http2=True),
    "all://*example.org": httpx.HTTPTransport()
}

# Using advanced httpcore configuration, with connection retries.
transport = httpx.HTTPTransport(retries=1)
client = httpx.Client(transport=transport)

# Using advanced httpcore configuration, with unix domain sockets.
transport = httpx.HTTPTransport(uds="socket.uds")
client = httpx.Client(transport=transport)
    )annotationsN)TracebackType   )DEFAULT_LIMITSLimitsProxycreate_ssl_context)ConnectErrorConnectTimeoutLocalProtocolErrorNetworkErrorPoolTimeoutProtocolError
ProxyError	ReadErrorReadTimeoutRemoteProtocolErrorTimeoutExceptionUnsupportedProtocol
WriteErrorWriteTimeout)RequestResponse)AsyncByteStream	CertTypes
ProxyTypesSyncByteStreamVerifyTypes)URL   )AsyncBaseTransportBaseTransportTHTTPTransport)boundAAsyncHTTPTransportztyping.Iterator[None]returnc               
   c  s   z
d V  W nx t y }  z`d }t D ]*\}}t| |s:q&|d u sLt||r&|}q&|d u r\ t| }||| W Y d } ~ n
d } ~ 0 0 d S N)	ExceptionHTTPCORE_EXC_MAPitems
isinstance
issubclassstr)excZ
mapped_excZfrom_excZto_excmessage r2   R/var/www/ai-form-bot/venv/lib/python3.9/site-packages/httpx/_transports/default.pymap_httpcore_exceptionsB   s    

r4   c                   @  s8   e Zd ZdddddZdddd	Zddd
dZdS )ResponseStreamztyping.Iterable[bytes]Nonehttpcore_streamr(   c                 C  s
   || _ d S r)   _httpcore_streamselfr8   r2   r2   r3   __init__l   s    zResponseStream.__init__ztyping.Iterator[bytes]r'   c                 c  s<   t  " | jD ]
}|V  qW d    n1 s.0    Y  d S r)   r4   r:   r<   partr2   r2   r3   __iter__o   s    
zResponseStream.__iter__c                 C  s   t | jdr| j  d S )Nclose)hasattrr:   rB   r<   r2   r2   r3   rB   t   s    zResponseStream.closeN)__name__
__module____qualname__r=   rA   rB   r2   r2   r2   r3   r5   k   s   r5   c                   @  s   e Zd Zddddeddddddfddddddd	d
d
ddddddZdddddZd#dddddddZdddddZdd d!d"ZdS )$r#   TNFr   r   CertTypes | Noneboolr   ProxyTypes | None
str | Noneint%typing.Iterable[SOCKET_OPTION] | Noner6   verifycerthttp1http2limits	trust_envproxyudslocal_addressretriessocket_optionsr(   c                 C  sJ  t |||d}t|ttfr&t|dn|}|d u rZtj||j|j|j	||||	|
|d
| _
n|jjdv rtjtj|jj|jj|jj|jjd|j|jj||j|j|j|j	|||d| _
n|jjdkr2zdd l}W n ty   td	d Y n0 tjtj|jj|jj|jj|jjd|j||j|j|j	||d
| _
ntd|jjdd S )NrO   rP   rT   url
ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryrQ   rR   rV   rW   rX   rY   httphttpsschemehostporttarget)	proxy_url
proxy_authproxy_headersr^   proxy_ssl_contextr_   r`   ra   rQ   rR   rY   socks5r   {Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.rj   rk   r^   r_   r`   ra   rQ   rR   zDProxy protocol must be either 'http', 'https', or 'socks5', but got .)r   r-   r/   r   r   httpcoreConnectionPoolr_   r`   ra   _poolr\   rf   Z	HTTPProxy
raw_schemeraw_hostrh   raw_pathraw_authheadersrawr^   socksioImportErrorZ
SOCKSProxy
ValueErrorr<   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   r^   r{   r2   r2   r3   r=   z   s~    


zHTTPTransport.__init__r"   r<   r(   c                 C  s   | j   | S r)   )rt   	__enter__rD   r2   r2   r3   r      s    
zHTTPTransport.__enter__type[BaseException] | NoneBaseException | NoneTracebackType | Noneexc_type	exc_value	tracebackr(   c                 C  s:   t    | j||| W d    n1 s,0    Y  d S r)   )r4   rt   __exit__r<   r   r   r   r2   r2   r3   r      s    zHTTPTransport.__exit__r   r   requestr(   c                 C  s   t |jtsJ tj|jtj|jj|jj	|jj
|jjd|jj|j|jd}t  | j|}W d    n1 st0    Y  t |jtjsJ t|j|jt|j|jdS Nre   )methodr\   ry   content
extensions)status_codery   streamr   )r-   r   r   rr   r   r   r   r\   ru   rv   rh   rw   ry   rz   r   r4   rt   handle_requesttypingIterabler   statusr5   r<   r   reqrespr2   r2   r3   r      s,    *zHTTPTransport.handle_requestr'   c                 C  s   | j   d S r)   )rt   rB   rD   r2   r2   r3   rB      s    zHTTPTransport.close)NNN)	rE   rF   rG   r   r=   r   r   r   rB   r2   r2   r2   r3   r#   y   s&   &O   	c                   @  s8   e Zd ZdddddZdddd	Zddd
dZdS )AsyncResponseStreamztyping.AsyncIterable[bytes]r6   r7   c                 C  s
   || _ d S r)   r9   r;   r2   r2   r3   r=      s    zAsyncResponseStream.__init__ztyping.AsyncIterator[bytes]r'   c                 C sF   t  , | j2 z3 d H W }|V  q6 W d    n1 s80    Y  d S r)   r>   r?   r2   r2   r3   	__aiter__   s    zAsyncResponseStream.__aiter__c                   s    t | jdr| j I d H  d S )Naclose)rC   r:   r   rD   r2   r2   r3   r     s    zAsyncResponseStream.acloseN)rE   rF   rG   r=   r   r   r2   r2   r2   r3   r      s   r   c                   @  s   e Zd Zddddeddddddfddddddd	d
d
ddddddZdddddZd#dddddddZdddddZdd d!d"ZdS )$r&   TNFr   r   rH   rI   r   rJ   rK   rL   rM   r6   rN   c                 C  s:  t |||d}t|ttfr&t|dn|}|d u rZtj||j|j|j	||||	|
|d
| _
n|jjdv rtjtj|jj|jj|jj|jjd|j|jj||j|j|j	|||d
| _
n|jjdkr.zdd l}W n ty   td	d Y n0 tjtj|jj|jj|jj|jjd|j||j|j|j	||d
| _
ntdd S )NrZ   r[   r]   rb   re   )
rj   rk   rl   r^   r_   r`   ra   rQ   rR   rY   rn   r   ro   rp   zYProxy protocol must be either 'http', 'https', or 'socks5', but got {proxy.url.scheme!r}.)r   r-   r/   r   r   rr   ZAsyncConnectionPoolr_   r`   ra   rt   r\   rf   ZAsyncHTTPProxyru   rv   rh   rw   rx   ry   rz   r{   r|   ZAsyncSOCKSProxyr}   r~   r2   r2   r3   r=     sx    


zAsyncHTTPTransport.__init__r%   r   c                   s   | j  I d H  | S r)   )rt   
__aenter__rD   r2   r2   r3   r   U  s    zAsyncHTTPTransport.__aenter__r   r   r   r   c                   s@   t  & | j|||I d H  W d    n1 s20    Y  d S r)   )r4   rt   	__aexit__r   r2   r2   r3   r   Y  s    zAsyncHTTPTransport.__aexit__r   r   r   c                   s   t |jtsJ tj|jtj|jj|jj	|jj
|jjd|jj|j|jd}t " | j|I d H }W d    n1 sz0    Y  t |jtjsJ t|j|jt|j|jdS r   )r-   r   r   rr   r   r   r   r\   ru   rv   rh   rw   ry   rz   r   r4   rt   handle_async_requestr   AsyncIterabler   r   r   r   r2   r2   r3   r   b  s,    0z'AsyncHTTPTransport.handle_async_requestr'   c                   s   | j  I d H  d S r)   )rt   r   rD   r2   r2   r3   r     s    zAsyncHTTPTransport.aclose)NNN)	rE   rF   rG   r   r=   r   r   r   r   r2   r2   r2   r3   r&     s&   &N   	):__doc__
__future__r   
contextlibr   typesr   rr   _configr   r   r   r   _exceptionsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Z_modelsr   r   _typesr   r   r   r   r   Z_urlsr   baser    r!   TypeVarr"   r%   UnionTuplerL   bytes	bytearrayZSOCKET_OPTIONcontextmanagerr4   r+   r5   r#   r   r&   r2   r2   r2   r3   <module>   sP   @