o
    "`^hS4                     @  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 Z2ddgZ3ej4dddZ5e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Z6G dd de#Z7G dd de)Z8G dd de Z9G dd de(Z:d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AsyncHTTPTransportreturntyping.Iterator[None]c               
   c  s|    zd V  W d S  t y= }  z*d }t D ]\}}t| |sq|d u s(t||r*|}q|d u r0 t| }||| d } ~ ww N)	ExceptionHTTPCORE_EXC_MAPitems
isinstance
issubclassstr)exc
mapped_excfrom_excto_excmessage r5   W/home/air/shanriGPT/back/venv/lib/python3.10/site-packages/httpx/_transports/default.pymap_httpcore_exceptionsE   s"   

r7   c                   @  *   e Zd ZdddZddd	Zdd
dZdS )ResponseStreamhttpcore_streamtyping.Iterable[bytes]r'   Nonec                 C  
   || _ d S r)   _httpcore_streamselfr:   r5   r5   r6   __init__o      
zResponseStream.__init__typing.Iterator[bytes]c                 c  s@    t   | jD ]}|V  qW d    d S 1 sw   Y  d S r)   r7   r?   rA   partr5   r5   r6   __iter__r   s   
"zResponseStream.__iter__c                 C  s   t | jdr| j  d S d S )Nclose)hasattrr?   rI   rA   r5   r5   r6   rI   w   s   zResponseStream.closeN)r:   r;   r'   r<   )r'   rD   r'   r<   )__name__
__module____qualname__rB   rH   rI   r5   r5   r5   r6   r9   n       

r9   c                   @  ^   e Zd Zddddeddddddfd/ddZd0ddZ			d1d2d&d'Zd3d+d,Zd4d-d.ZdS )5r#   TNFr   verifyr   certCertTypes | Nonehttp1boolhttp2limitsr   	trust_envproxyProxyTypes | Noneuds
str | Nonelocal_addressretriesintsocket_options%typing.Iterable[SOCKET_OPTION] | Noner'   r<   c                 C  sF  t |||d}t|ttfrt|dn|}|d u r.tj||j|j|j	||||	|
|d
| _
d S |jjdv r]tjtj|jj|jj|jj|jjd|j|jj||j|j|j|j	|||d| _
d S |jjdkrzdd l}W n tyu   td	d w tjtj|jj|jj|jj|jjd|j||j|j|j	||d
| _
d S td|jjd)NrR   rS   rY   url
ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryrU   rW   r\   r^   r_   ra   httphttpsschemehostporttarget)	proxy_url
proxy_authproxy_headersrg   proxy_ssl_contextrh   ri   rj   rU   rW   ra   socks5r   {Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.rs   rt   rg   rh   ri   rj   rU   rW   zDProxy protocol must be either 'http', 'https', or 'socks5', but got .)r   r-   r/   r   r   httpcoreConnectionPoolrh   ri   rj   _poolre   ro   	HTTPProxy
raw_schemeraw_hostrq   raw_pathraw_authheadersrawrg   socksioImportError
SOCKSProxy
ValueErrorrA   rR   rS   rU   rW   rX   rY   rZ   r\   r^   r_   ra   rg   r   r5   r5   r6   rB   }   s   zHTTPTransport.__init__rA   r"   c                 C  s   | j   | S r)   )r}   	__enter__rK   r5   r5   r6   r      s   
zHTTPTransport.__enter__exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                 C  s<   t   | j||| W d    d S 1 sw   Y  d S r)   )r7   r}   __exit__rA   r   r   r   r5   r5   r6   r      s   "zHTTPTransport.__exit__requestr   r   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 s:w   Y  t |jtjsHJ t|j|jt|j|jdS Nrn   )methodre   r   content
extensions)status_coder   streamr   )r-   r   r   r{   r   r   r   re   r   r   rq   r   r   r   r   r7   r}   handle_requesttypingIterabler   statusr9   rA   r   reqrespr5   r5   r6   r      s.   zHTTPTransport.handle_requestc                 C  s   | j   d S r)   )r}   rI   rK   r5   r5   r6   rI      s   zHTTPTransport.closerR   r   rS   rT   rU   rV   rW   rV   rX   r   rY   rV   rZ   r[   r\   r]   r^   r]   r_   r`   ra   rb   r'   r<   )rA   r"   r'   r"   NNNr   r   r   r   r   r   r'   r<   r   r   r'   r   rL   )	rM   rN   rO   r   rB   r   r   r   rI   r5   r5   r5   r6   r#   |   (    
O
	c                   @  r8   )AsyncResponseStreamr:   typing.AsyncIterable[bytes]r'   r<   c                 C  r=   r)   r>   r@   r5   r5   r6   rB      rC   zAsyncResponseStream.__init__typing.AsyncIterator[bytes]c                 C sJ   t   | j2 z	3 d H W }|V  q6 W d    d S 1 sw   Y  d S r)   rE   rF   r5   r5   r6   	__aiter__   s   "zAsyncResponseStream.__aiter__c                   s&   t | jdr| j I d H  d S d S )Naclose)rJ   r?   r   rK   r5   r5   r6   r     s   zAsyncResponseStream.acloseN)r:   r   r'   r<   )r'   r   rL   )rM   rN   rO   rB   r   r   r5   r5   r5   r6   r      rP   r   c                   @  rQ   )5r&   TNFr   rR   r   rS   rT   rU   rV   rW   rX   r   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   r'   r<   c                 C  s:  t |||d}t|ttfrt|dn|}|d u r.tj||j|j|j	||||	|
|d
| _
d S |jjdv r]tjtj|jj|jj|jj|jjd|j|jj|j||j|j|j	|||d| _
d S |jjdkrzdd l}W n tyu   td	d w tjtj|jj|jj|jj|jjd|j||j|j|j	||d
| _
d S td)Nrc   rd   rf   rk   rn   )rs   rt   ru   rv   rg   rh   ri   rj   rU   rW   ra   rw   r   rx   ry   zYProxy protocol must be either 'http', 'https', or 'socks5', but got {proxy.url.scheme!r}.)r   r-   r/   r   r   r{   AsyncConnectionPoolrh   ri   rj   r}   re   ro   AsyncHTTPProxyr   r   rq   r   r   r   r   rg   r   r   AsyncSOCKSProxyr   r   r5   r5   r6   rB   
  s|   zAsyncHTTPTransport.__init__rA   r%   c                   s   | j  I d H  | S r)   )r}   
__aenter__rK   r5   r5   r6   r   Y  s   zAsyncHTTPTransport.__aenter__r   r   r   r   r   r   c                   sD   t   | j|||I d H  W d    d S 1 sw   Y  d S r)   )r7   r}   	__aexit__r   r5   r5   r6   r   ]  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 s>w   Y  t |jtjsLJ t|j|jt|j|jdS r   )r-   r   r   r{   r   r   r   re   r   r   rq   r   r   r   r   r7   r}   handle_async_requestr   AsyncIterabler   r   r   r   r5   r5   r6   r   f  s0   z'AsyncHTTPTransport.handle_async_requestc                   s   | j  I d H  d S r)   )r}   r   rK   r5   r5   r6   r     s   zAsyncHTTPTransport.acloser   )rA   r%   r'   r%   r   r   r   rL   )	rM   rN   rO   r   rB   r   r   r   r   r5   r5   r5   r6   r&   	  r   )r'   r(   );__doc__
__future__r   
contextlibr   typesr   r{   _configr   r   r   r   _exceptionsr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   _modelsr   r   _typesr   r   r   r   r   _urlsr   baser    r!   TypeVarr"   r%   UnionTupler`   bytes	bytearraySOCKET_OPTION__all__contextmanagerr7   r+   r9   r#   r   r&   r5   r5   r5   r6   <module>   sT    @