o
    7'h.5  ã                
   @  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m	Z	 ddl
mZmZ ddlmZmZmZmZmZ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¡Z!dddddœZ"ddddddddddœ	Z#ddœd0d*d+„Z$G d,d-„ d-eƒZ%G d.d/„ d/eƒZ&dS )1é    )ÚannotationsNé   )ÚSyncBackend)ÚNetworkBackendÚNetworkStream)ÚConnectionNotAvailableÚ
ProxyError)ÚURLÚOriginÚRequestÚResponseÚenforce_bytesÚenforce_url)Údefault_ssl_context)ÚLock)ÚTraceé   )ÚConnectionPool)ÚHTTP11Connection)ÚConnectionInterfacezhttpcore.sockszNO AUTHENTICATION REQUIREDZGSSAPIzUSERNAME/PASSWORDzNO ACCEPTABLE METHODS)ó    ó   ó   ó   ÿZ	SucceededzGeneral SOCKS server failurez!Connection not allowed by rulesetzNetwork unreachablezHost unreachablezConnection refusedzTTL expiredzCommand not supportedzAddress type not supported)	r   r   r   ó   ó   ó   ó   ó   ó   )ÚauthÚstreamr   ÚhostÚbytesÚportÚintr    útuple[bytes, bytes] | NoneÚreturnÚNonec                C  sº  t j ¡ }|d u rt jjjnt jjj}| t j |g¡¡ | ¡ }|  	|¡ | j
dd�}| |¡}t|t jjƒs:J ‚|j|krWt |d¡}	t |jd¡}
td|	› d|
› d�ƒ‚|jt jjjkr—|d useJ ‚|\}}| t j ||¡¡ | ¡ }|  	|¡ | j
dd�}| |¡}t|t jjƒs�J ‚|js—tdƒ‚| t jj t jjj||f¡¡ | ¡ }|  	|¡ | j
dd�}| |¡}t|t jjƒsÄJ ‚|jt jjjkrÛt |jd¡}td	|› d�ƒ‚d S )
Ni   )Z	max_bytesÚUNKNOWNz
Requested z from proxy server, but got Ú.zInvalid username/passwordZUNKOWNz Proxy Server could not connect: )ÚsocksioZsocks5ZSOCKS5ConnectionZSOCKS5AuthMethodZNO_AUTH_REQUIREDZUSERNAME_PASSWORDÚsendZSOCKS5AuthMethodsRequestZdata_to_sendÚwriteÚreadZreceive_dataÚ
isinstanceZSOCKS5AuthReplyÚmethodÚAUTH_METHODSÚgetr   ZSOCKS5UsernamePasswordRequestZSOCKS5UsernamePasswordReplyÚsuccessZSOCKS5CommandRequestÚfrom_addressZSOCKS5CommandZCONNECTZSOCKS5ReplyÚ
reply_codeZSOCKS5ReplyCodeZ	SUCCEEDEDÚREPLY_CODES)r!   r"   r$   r    ÚconnZauth_methodZoutgoing_bytesZincoming_bytesÚresponseÚ	requestedZ	respondedÚusernameÚpasswordr5   © r<   úPC:\Users\shubh\Videos\agent\nova\Lib\site-packages\httpcore/_sync/socks_proxy.pyÚ_init_socks5_connection*   sT   

ÿý


ÿ

ÿÿ

þr>   c                      s@   e Zd ZdZ									d"d#‡ fdd„Zd$d d!„Z‡  ZS )%Ú
SOCKSProxyzB
    A connection pool that sends requests via an HTTP proxy.
    Né
   TFr   Ú	proxy_urlúURL | bytes | strÚ
proxy_authú&tuple[bytes | str, bytes | str] | NoneÚssl_contextússl.SSLContext | NoneÚmax_connectionsú
int | NoneÚmax_keepalive_connectionsÚkeepalive_expiryúfloat | NoneÚhttp1ÚboolÚhttp2Úretriesr%   Únetwork_backendúNetworkBackend | Noner'   r(   c              
     sp   t ƒ j|||||||
|	d� || _t|dd�| _|dur3|\}}t|dd�}t|dd�}||f| _dS d| _dS )a&  
        A connection pool for making HTTP requests.

        Parameters:
            proxy_url: The URL to use when connecting to the proxy server.
                For example `"http://127.0.0.1:8080/"`.
            ssl_context: An SSL context to use for verifying connections.
                If not specified, the default `httpcore.default_ssl_context()`
                will be used.
            max_connections: The maximum number of concurrent HTTP connections that
                the pool should allow. Any attempt to send a request on a pool that
                would exceed this amount will block until a connection is available.
            max_keepalive_connections: The maximum number of idle HTTP connections
                that will be maintained in the pool.
            keepalive_expiry: The duration in seconds that an idle HTTP connection
                may be maintained for before being expired from the pool.
            http1: A boolean indicating if HTTP/1.1 requests should be supported
                by the connection pool. Defaults to True.
            http2: A boolean indicating if HTTP/2 requests should be supported by
                the connection pool. Defaults to False.
            retries: The maximum number of retries when trying to establish
                a connection.
            local_address: Local address to connect from. Can also be used to
                connect using a particular address family. Using
                `local_address="0.0.0.0"` will connect using an `AF_INET` address
                (IPv4), while using `local_address="::"` will connect using an
                `AF_INET6` address (IPv6).
            uds: Path to a Unix Domain Socket to use instead of TCP sockets.
            network_backend: A backend instance to use for handling network I/O.
        )rE   rG   rI   rJ   rL   rN   rP   rO   rA   )ÚnameNrC   )ÚsuperÚ__init__Ú_ssl_contextr   Ú
_proxy_urlr   Ú_proxy_auth)ÚselfrA   rC   rE   rG   rI   rJ   rL   rN   rO   rP   r:   r;   Zusername_bytesZpassword_bytes©Ú	__class__r<   r=   rT   n   s(   +ø

þ
zSOCKSProxy.__init__Úoriginr
   r   c              
   C  s(   t | jj|| j| j| j| j| j| jd�S )N)Úproxy_originÚremote_originrC   rE   rJ   rL   rN   rP   )	ÚSocks5ConnectionrV   r[   rW   rU   Ú_keepalive_expiryÚ_http1Ú_http2Ú_network_backend©rX   r[   r<   r<   r=   Úcreate_connection°   s   øzSOCKSProxy.create_connection)	NNr@   NNTFr   N)rA   rB   rC   rD   rE   rF   rG   rH   rI   rH   rJ   rK   rL   rM   rN   rM   rO   r%   rP   rQ   r'   r(   )r[   r
   r'   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rT   rd   Ú__classcell__r<   r<   rY   r=   r?   i   s    õBr?   c                   @  s~   e Zd Z						d-d.dd„Zd/dd„Zd0dd„Zd1dd„Zd2d d!„Zd2d"d#„Zd2d$d%„Z	d2d&d'„Z
d3d)d*„Zd3d+d,„ZdS )4r^   NTFr\   r
   r]   rC   r&   rE   rF   rJ   rK   rL   rM   rN   rP   rQ   r'   r(   c	           	      C  sV   || _ || _|| _|| _|| _|| _|| _|d u rtƒ n|| _t	ƒ | _
d | _d| _d S )NF)Ú_proxy_originÚ_remote_originrW   rU   r_   r`   ra   r   rb   r   Ú_connect_lockÚ_connectionÚ_connect_failed)	rX   r\   r]   rC   rE   rJ   rL   rN   rP   r<   r<   r=   rT   ¾   s   ÿ
zSocks5Connection.__init__Úrequestr   r   c                 C  sh  |j  di ¡}|j  dd ¡}| dd ¡}| j�� | jd u �rzã| jj d¡| jj|dœ}tdt	||ƒ�}| j
jdi |¤Ž}||_W d   ƒ n1 sKw   Y  || jj d¡| jj| jdœ}tdt	||ƒ�}tdi |¤Ž ||_W d   ƒ n1 s{w   Y  | jjd	krÏ| jd u rŽtƒ n| j}| jr˜d
dgnd
g}	| |	¡ ||p©| jj d¡|dœ}tdt	||ƒ�}|jdi |¤Ž}||_W d   ƒ n1 sÊw   Y  | d¡}
|
d uoÝ|
 ¡ dk}|sæ| jr÷| js÷ddlm} || j|| jd�| _n
t| j|| jd�| _W n t�y } zd| _|‚d }~ww | j ¡ �st ƒ ‚W d   ƒ n	1 �s)w   Y  | j !|¡S )NÚtimeoutÚsni_hostnameÚconnectÚascii)r"   r$   rp   Úconnect_tcp)r!   r"   r$   r    Zsetup_socks5_connectionó   httpszhttp/1.1Úh2)rE   Úserver_hostnamerp   Ú	start_tlsÚ
ssl_objectr   )ÚHTTP2Connection)r[   r!   rJ   Tr<   )"Ú
extensionsr2   rl   rm   rj   r"   Údecoder$   r   Úloggerrb   rt   Úreturn_valuerk   rW   r>   ÚschemerU   r   ra   Úset_alpn_protocolsrx   Úget_extra_infoÚselected_alpn_protocolr`   rN   rz   r_   r   Ú	Exceptionrn   Úis_availabler   Úhandle_request)rX   ro   Ztimeoutsrq   rp   ÚkwargsÚtracer!   rE   Úalpn_protocolsry   Zhttp2_negotiatedrz   Úexcr<   r<   r=   r…   Ø   s”   
ýþüÿü
ÿýÿ
üþ

þÿÿ
ýý€€þ€´NzSocks5Connection.handle_requestr[   c                 C  s
   || j kS ©N)rk   rc   r<   r<   r=   Úcan_handle_request-  s   
z#Socks5Connection.can_handle_requestc                 C  s   | j d ur| j  ¡  d S d S rŠ   )rm   Úclose©rX   r<   r<   r=   rŒ   0  s   
ÿzSocks5Connection.closec                 C  s6   | j d u r| jo| jjdkp| j o| j S | j  ¡ S )Nru   )rm   ra   rk   r   r`   rn   r„   r�   r<   r<   r=   r„   4  s   
ÿý
zSocks5Connection.is_availablec                 C  ó   | j d u r| jS | j  ¡ S rŠ   )rm   rn   Úhas_expiredr�   r<   r<   r=   r�   @  ó   

zSocks5Connection.has_expiredc                 C  rŽ   rŠ   )rm   rn   Úis_idler�   r<   r<   r=   r‘   E  r�   zSocks5Connection.is_idlec                 C  rŽ   rŠ   )rm   rn   Ú	is_closedr�   r<   r<   r=   r’   J  r�   zSocks5Connection.is_closedÚstrc                 C  s"   | j d u r| jr
dS dS | j  ¡ S )NzCONNECTION FAILEDZ
CONNECTING)rm   rn   Úinfor�   r<   r<   r=   r”   O  s   

zSocks5Connection.infoc                 C  s   d| j j› d|  ¡ › d�S )Nú<z [z]>)rZ   re   r”   r�   r<   r<   r=   Ú__repr__T  s   zSocks5Connection.__repr__)NNNTFN)r\   r
   r]   r
   rC   r&   rE   rF   rJ   rK   rL   rM   rN   rM   rP   rQ   r'   r(   )ro   r   r'   r   )r[   r
   r'   rM   )r'   r(   )r'   rM   )r'   r“   )re   rf   rg   rT   r…   r‹   rŒ   r„   r�   r‘   r’   r”   r–   r<   r<   r<   r=   r^   ½   s"    ÷

U





r^   )
r!   r   r"   r#   r$   r%   r    r&   r'   r(   )'Ú
__future__r   ÚloggingÚsslr+   Z_backends.syncr   Z_backends.baser   r   Ú_exceptionsr   r   Z_modelsr	   r
   r   r   r   r   Ú_sslr   Z_synchronizationr   Ú_tracer   Zconnection_poolr   Zhttp11r   Z
interfacesr   Ú	getLoggerr}   r1   r6   r>   r?   r^   r<   r<   r<   r=   Ú<module>   sD     
ü÷û?T