
    NgS4                       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          Z+ ej*        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j4        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Z6 G d de#          Z7 G d de)          Z8 G d de           Z9 G 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               #     K   	 d V  d S # t           $ ri} d }t                                          D ]*\  }}t          | |          s|t	          ||          r|}+| t          |           } ||          | d } ~ ww xY wN)	ExceptionHTTPCORE_EXC_MAPitems
isinstance
issubclassstr)exc
mapped_excfrom_excto_excmessages        U/var/www/html/ai-engine/env/lib/python3.11/site-packages/httpx/_transports/default.pymap_httpcore_exceptionsr8   E   s      + + + +
 0 6 6 8 8 	$ 	$Hfc8,,  !Z
%C%C!#
c((j!!s*!+s   
 
A=A$A88A=c                  &    e Zd Zd
dZddZddZd	S )ResponseStreamhttpcore_streamtyping.Iterable[bytes]r(   Nonec                    || _         d S r+   _httpcore_streamselfr;   s     r7   __init__zResponseStream.__init__o        /    typing.Iterator[bytes]c              #  v   K   t                      5  | j        D ]}|V  	 d d d            d S # 1 swxY w Y   d S r+   r8   r@   rB   parts     r7   __iter__zResponseStream.__iter__r   s      $&& 	 	-  



	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .22c                f    t          | j        d          r| j                                         d S d S )Nclose)hasattrr@   rM   rB   s    r7   rM   zResponseStream.closew   s<    4('22 	*!'')))))	* 	*rE   N)r;   r<   r(   r=   )r(   rF   r(   r=   )__name__
__module____qualname__rC   rK   rM    rE   r7   r:   r:   n   sP        0 0 0 0   
* * * * * *rE   r:   c                  V    e Zd Zddddeddddddfd*dZd+dZ	 	 	 d,d-d$Zd.d(Zd/d)ZdS )0r$   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                   t          |||          }t          |t          t          f          rt	          |          n|}|4t          j        ||j        |j        |j	        ||||	|
|
  
        | _
        d S |j        j        dv rt          j        t          j        |j        j        |j        j        |j        j        |j        j                  |j        |j        j        ||j        |j        |j        |j	        |||          | _
        d S |j        j        dk    r	 dd l}n# t.          $ r t/          d	          d w xY wt          j        t          j        |j        j        |j        j        |j        j        |j        j                  |j        ||j        |j        |j	        ||
          | _
        d S t3          d|j        j        d          )NrV   rW   r]   url
ssl_contextmax_connectionsmax_keepalive_connectionskeepalive_expiryrY   r[   r`   rb   rc   re   httphttpsschemehostporttarget)	proxy_url
proxy_authproxy_headersrl   proxy_ssl_contextrm   rn   ro   rY   r[   re   socks5r   {Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.rx   ry   rl   rm   rn   ro   rY   r[   zDProxy protocol must be either 'http', 'https', or 'socks5', but got .)r	   r/   r1   r   r   httpcoreConnectionPoolrm   rn   ro   _poolrj   rt   	HTTPProxy
raw_schemeraw_hostrv   raw_pathraw_authheadersrawrl   socksioImportError
SOCKSProxy
ValueErrorrB   rV   rW   rY   r[   r\   r]   r^   r`   rb   rc   re   rl   r   s                 r7   rC   zHTTPTransport.__init__}   s    )TYWWW$.usCj$A$AL%    u=!0' & 6*0*J!'!8+-  DJJJ Y!222!+", 9/+ 9-	   !>#m/'"'"3 & 6*0*J!'!8-!  DJJJ$ Y))   !S   ",", 9/+ 9-	   !>' & 6*0*J!'!8  DJJJ  2!I,2 2 2     D" "D=rB   r#   c                8    | j                                          | S r+   )r   	__enter__rO   s    r7   r   zHTTPTransport.__enter__   s    
rE   exc_typetype[BaseException] | None	exc_valueBaseException | None	tracebackTracebackType | Nonec                    t                      5  | j                            |||           d d d            d S # 1 swxY w Y   d S r+   )r8   r   __exit__rB   r   r   r   s       r7   r   zHTTPTransport.__exit__   s     %&& 	@ 	@J)Y???	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@ 	@s   9= =requestr   r   c           	     D   t          |j        t                    sJ t          j        |j        t          j        |j        j        |j        j	        |j        j
        |j        j                  |j        j        |j        |j                  }t                      5  | j                            |          }d d d            n# 1 swxY w Y   t          |j        t$          j                  sJ t)          |j        |j        t-          |j                  |j                  S Nrs   )methodrj   r   content
extensions)status_coder   streamr   )r/   r   r   r   r   r   r   rj   r   r   rv   r   r   r   r   r8   r   handle_requesttypingIterabler   statusr:   rB   r   reqresps       r7   r   zHTTPTransport.handle_request   sH    '..99999>{-[)[%{+	   O'N)
 
 
 %&& 	2 	2:,,S11D	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 $+v77777L!$+..	
 
 
 	
s   CC	Cc                8    | j                                          d S r+   )r   rM   rO   s    r7   rM   zHTTPTransport.close   s    
rE   rV   r   rW   rX   rY   rZ   r[   rZ   r\   r   r]   rZ   r^   r_   r`   ra   rb   ra   rc   rd   re   rf   r(   r=   )rB   r#   r(   r#   NNNr   r   r   r   r   r   r(   r=   r   r   r(   r   rP   )	rQ   rR   rS   r   rC   r   r   r   rM   rT   rE   r7   r$   r$   |   s         #!%'#'$(@DM M M M M^    04*.*.	@ @ @ @ @
 
 
 
<     rE   c                  &    e Zd Zd
dZddZddZd	S )AsyncResponseStreamr;   typing.AsyncIterable[bytes]r(   r=   c                    || _         d S r+   r?   rA   s     r7   rC   zAsyncResponseStream.__init__   rD   rE   typing.AsyncIterator[bytes]c                  K   t                      5  | j        2 3 d {V }|W V  6 	 d d d            d S # 1 swxY w Y   d S r+   rH   rI   s     r7   	__aiter__zAsyncResponseStream.__aiter__   s      $&& 	 	"3       d




 43	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   5&599c                v   K   t          | j        d          r!| j                                         d {V  d S d S )Naclose)rN   r@   r   rO   s    r7   r   zAsyncResponseStream.aclose  sR      4((33 	1'..00000000000	1 	1rE   N)r;   r   r(   r=   )r(   r   rP   )rQ   rR   rS   rC   r   r   rT   rE   r7   r   r      sP        0 0 0 0   
1 1 1 1 1 1rE   r   c                  V    e Zd Zddddeddddddfd*dZd+dZ	 	 	 d,d-d$Zd.d(Zd/d)ZdS )0r'   TNFr   rV   r   rW   rX   rY   rZ   r[   r\   r   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   r(   r=   c                   t          |||          }t          |t          t          f          rt	          |          n|}|4t          j        ||j        |j        |j	        ||||	|
|
  
        | _
        d S |j        j        dv rt          j        t          j        |j        j        |j        j        |j        j        |j        j                  |j        |j        j        |j        ||j        |j        |j	        |||          | _
        d S |j        j        dk    r	 dd l}n# t.          $ r t/          d	          d w xY wt          j        t          j        |j        j        |j        j        |j        j        |j        j                  |j        ||j        |j        |j	        ||
          | _
        d S t3          d          )Nrh   ri   rk   rp   rs   )rx   ry   rz   r{   rl   rm   rn   ro   rY   r[   re   r|   r   r}   r~   zYProxy protocol must be either 'http', 'https', or 'socks5', but got {proxy.url.scheme!r}.)r	   r/   r1   r   r   r   AsyncConnectionPoolrm   rn   ro   r   rj   rt   AsyncHTTPProxyr   r   rv   r   r   r   r   rl   r   r   AsyncSOCKSProxyr   r   s                 r7   rC   zAsyncHTTPTransport.__init__
  s    )TYWWW$.usCj$A$AL%    u=!5' & 6*0*J!'!8+-  DJJJ Y!222!0", 9/+ 9-	   !>#m/"'"3' & 6*0*J!'!8-!  DJJJ$ Y))   !S   "1", 9/+ 9-	   !>' & 6*0*J!'!8  DJJJ  1  r   rB   r&   c                H   K   | j                                          d {V  | S r+   )r   
__aenter__rO   s    r7   r   zAsyncHTTPTransport.__aenter__Y  s1      j##%%%%%%%%%rE   r   r   r   r   r   r   c                   K   t                      5  | j                            |||           d {V  d d d            d S # 1 swxY w Y   d S r+   )r8   r   	__aexit__r   s       r7   r   zAsyncHTTPTransport.__aexit__]  s       %&& 	G 	G*&&xIFFFFFFFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   #AAAr   r   r   c           	     T  K   t          |j        t                    sJ t          j        |j        t          j        |j        j        |j        j	        |j        j
        |j        j                  |j        j        |j        |j                  }t                      5  | j                            |           d {V }d d d            n# 1 swxY w Y   t          |j        t$          j                  sJ t)          |j        |j        t-          |j                  |j                  S r   )r/   r   r   r   r   r   r   rj   r   r   rv   r   r   r   r   r8   r   handle_async_requestr   AsyncIterabler   r   r   r   s       r7   r   z'AsyncHTTPTransport.handle_async_requestf  s_      './:::::>{-[)[%{+	   O'N)
 
 
 %&& 	> 	>88========D	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> $+v';<<<<<L&t{33	
 
 
 	
s   !C

CCc                H   K   | j                                          d {V  d S r+   )r   r   rO   s    r7   r   zAsyncHTTPTransport.aclose  s2      j!!!!!!!!!!!rE   r   )rB   r&   r(   r&   r   r   r   rP   )	rQ   rR   rS   r   rC   r   r   r   r   rT   rE   r7   r'   r'   	  s         #!%'#'$(@DM M M M M^    04*.*.	G G G G G
 
 
 
<" " " " " "rE   )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Tuplerd   bytes	bytearraySOCKET_OPTION__all__contextmanagerr8   r-   r:   r$   r   r'   rT   rE   r7   <module>r      sw   4 # " " " " "             G G G G G G G G G G G G                                 ( ' ' ' ' ' ' ' X X X X X X X X X X X X X X       3 3 3 3 3 3 3 3FN3o...FN32333
Lc3
Lc6<y(899:
Lc4$%'  
1 + + + +. /^+<+<<	 "5M!3 "5 $* * * * *^ * * *| | | | |M | | |~1 1 1 1 1/ 1 1 1|" |" |" |" |"+ |" |" |" |" |"rE   