Format: application/x-python-code
⬇ Download File (10.0 KB)
   1  o
   2  
   3  7'h6�
   4  @sddlmZddlZddlZddlZddlmZddlmZm	Z	ddl
   5  mZmZddl
   6  mZmZmZmZmZmZddlmZdd	lmZdd
   7  lmZddlmZdd
   8  lmZddlmZe� d�Z!ddddd�Z"dddddddddd�	Z#dd�d0d*d+�Z$Gd,d-�d-e�Z%Gd.d/�d/e�Z&dS)1�)�annotationsN�)�AutoBackend)�AsyncNetworkBackend�AsyncNetworkStream)�ConnectionNotAvailable�
   9  ProxyError)�URL�Origin�Request�Response�
  10  enforce_bytes�enforce_url)�default_ssl_context)�	AsyncLock)�Trace�)�AsyncConnectionPool)�AsyncHTTP11Connection)�AsyncConnectionInterfacezhttpcore.sockszNO AUTHENTICATION REQUIREDZGSSAPIzUSERNAME/PASSWORDzNO ACCEPTABLE METHODS)�����Z	SucceededzGeneral SOCKS server failurez!Connection not allowed by rulesetzNetwork unreachablezHost unreachablezConnection refusedzTTL expiredzCommand not supportedzAddress type not supported)	rrr������)�auth�streamr�host�bytes�port�intr �tuple[bytes, bytes] | None�return�Nonec�s��tj��}|durtjjjntjjj}|�tj�|g��|��}|�	|�IdH|j
  11  dd�IdH}|�|�}t|tjj
  12  �sAJ�|j|kr^t�|d�}	t�|jd�}
  13  td|	�d|
  14  �d���|jtjjjkr�|duslJ�|\}}|�tj�||��|��}|�	|�IdH|j
  15  dd�IdH}|�|�}t|tjj�s�J�|js�td��|�tjj�tjjj||f��|��}|�	|�IdH|j
  16  dd�IdH}|�|�}t|tjj�s�J�|jtjjjkr�t�|jd�}
  17  td	|
  18  �d���dS)
  19  Ni)Z	max_bytes�UNKNOWNz
  20  Requested z from proxy server, but got �.zInvalid username/passwordZUNKOWNz Proxy Server could not connect: )�socksioZsocks5ZSOCKS5ConnectionZSOCKS5AuthMethodZNO_AUTH_REQUIREDZUSERNAME_PASSWORD�sendZSOCKS5AuthMethodsRequestZdata_to_send�write�readZreceive_data�
  21  isinstanceZSOCKS5AuthReply�method�AUTH_METHODS�getrZSOCKS5UsernamePasswordRequestZSOCKS5UsernamePasswordReply�successZSOCKS5CommandRequest�from_addressZ
  22  SOCKS5CommandZCONNECTZSOCKS5Reply�
  23  reply_codeZSOCKS5ReplyCodeZ	SUCCEEDED�REPLY_CODES)r!r"r$r �connZauth_methodZoutgoing_bytesZincoming_bytes�response�	requestedZ	responded�username�passwordr5�r<�QC:\Users\shubh\Videos\agent\nova\Lib\site-packages\httpcore/_async/socks_proxy.py�_init_socks5_connection*sV�
  24  
  25  ��
  26  
  27  �
  28  ��
  29  �r>cs@eZdZdZ									d"d#�fdd�
  30  Zd$d d!�Z�ZS)%�AsyncSOCKSProxyzB
  31      A connection pool that sends requests via an HTTP proxy.
  32      N�
  33  TFr�	proxy_url�URL | bytes | str�
  34  proxy_auth�&tuple[bytes | str, bytes | str] | None�ssl_context�ssl.SSLContext | None�max_connections�
  35  int | None�max_keepalive_connections�keepalive_expiry�float | None�http1�bool�http2�retriesr%�network_backend�AsyncNetworkBackend | Noner'r(c
  36  spt�j|||||||
  37  |	d�||_t|dd�|_|dur3|\}}t|dd�}
  38  t|dd�}|
  39  |f|_dSd|_dS)a&
  40          A connection pool for making HTTP requests.
  41  
  42          Parameters:
  43              proxy_url: The URL to use when connecting to the proxy server.
  44                  For example `"http://127.0.0.1:8080/"`.
  45              ssl_context: An SSL context to use for verifying connections.
  46                  If not specified, the default `httpcore.default_ssl_context()`
  47                  will be used.
  48              max_connections: The maximum number of concurrent HTTP connections that
  49                  the pool should allow. Any attempt to send a request on a pool that
  50                  would exceed this amount will block until a connection is available.
  51              max_keepalive_connections: The maximum number of idle HTTP connections
  52                  that will be maintained in the pool.
  53              keepalive_expiry: The duration in seconds that an idle HTTP connection
  54                  may be maintained for before being expired from the pool.
  55              http1: A boolean indicating if HTTP/1.1 requests should be supported
  56                  by the connection pool. Defaults to True.
  57              http2: A boolean indicating if HTTP/2 requests should be supported by
  58                  the connection pool. Defaults to False.
  59              retries: The maximum number of retries when trying to establish
  60                  a connection.
  61              local_address: Local address to connect from. Can also be used to
  62                  connect using a particular address family. Using
  63                  `local_address="0.0.0.0"` will connect using an `AF_INET` address
  64                  (IPv4), while using `local_address="::"` will connect using an
  65                  `AF_INET6` address (IPv6).
  66              uds: Path to a Unix Domain Socket to use instead of TCP sockets.
  67              network_backend: A backend instance to use for handling network I/O.
  68          )rErGrIrJrLrNrPrOrA)�nameNrC)�super�__init__�_ssl_contextr�
  69  _proxy_urlr
  70  �_proxy_auth)�selfrArCrErGrIrJrLrNrOrPr:r;Zusername_bytesZpassword_bytes��	__class__r<r=rTns(+�
  71  
  72  �
  73  zAsyncSOCKSProxy.__init__�originr
  74  rc
  75  Cs(t|jj||j|j|j|j|j|jd�S)N)�proxy_origin�
  76  remote_originrCrErJrLrNrP)	�AsyncSocks5ConnectionrVr[rWrU�_keepalive_expiry�_http1�_http2�_network_backend�rXr[r<r<r=�create_connection�s�z!AsyncSOCKSProxy.create_connection)	NNr@NNTFrN)rArBrCrDrErFrGrHrIrHrJrKrLrMrNrMrOr%rPrQr'r()r[r
  77  r'r)�__name__�
  78  __module__�__qualname__�__doc__rTrd�
  79  __classcell__r<r<rYr=r?is�Br?c@s~eZdZ						d-d.dd�Zd/dd�Zd0dd�Zd1dd�Zd2d d!�Zd2d"d#�Zd2d$d%�Z	d2d&d'�Z
  80  d3d)d*�Zd3d+d,�ZdS)4r^NTFr\r
  81  r]rCr&rErFrJrKrLrMrNrPrQr'r(c		CsV||_||_||_||_||_||_||_|durt�n||_t	�|_
  82  d|_d|_dS)NF)
  83  �
  84  _proxy_origin�_remote_originrWrUr_r`rarrbr�
  85  _connect_lock�_connection�_connect_failed)	rXr\r]rCrErJrLrNrPr<r<r=rT�s�
  86  zAsyncSocks5Connection.__init__�requestrrc�s��|j�di�}|j�dd�}|�dd�}|j4IdH��<|jdu�rF�z|jj�d�|jj|d�}tdt	||�4IdH�}|j
  87  jdi|��IdH}||_Wd�IdHn1IdHs^wY||j
  88  j�d�|j
  89  j|jd�}tdt	||�4IdH�}tdi|��IdH||_Wd�IdHn1IdHs�wY|j
  90  jd	kr�|jdur�t�n|j}|jr�d
  91  dgnd
  92  g}	|�|	�||p�|j
  93  j�d�|d�}td
  94  t	||�4IdH�}|jdi|��IdH}||_Wd�IdHn1IdHs�wY|�d�}
  95  |
  96  du�o|
  97  ��dk}|�s|j�r(|j�s(ddlm}||j
  98  ||jd�|_n
  99  t|j
 100  ||jd�|_Wnt�yE}
 101  zd|_|
 102  �d}
 103  ~
 104  ww|j���sOt ��Wd�IdHn1IdH�s`wY|j�!|�IdHS)N�timeout�sni_hostname�connect�ascii)r"r$rp�connect_tcp)r!r"r$r Zsetup_socks5_connection�httpszhttp/1.1�h2)rE�server_hostnamerp�	start_tls�
 105  ssl_objectr)�AsyncHTTP2Connection)r[r!rJTr<)"�
 106  extensionsr2rlrmrjr"�decoder$r�loggerrbrt�return_valuerkrWr>�schemerUrra�set_alpn_protocolsrx�get_extra_info�selected_alpn_protocolr`rNrzr_r�	Exceptionrn�is_availabler�handle_async_request)rXroZtimeoutsrqrp�kwargs�tracer!rE�alpn_protocolsryZhttp2_negotiatedrz�excr<r<r=r��s���(���(�
 107  ���
 108  �(�
 109  
 110  
 111  ���
 112  �����*�Nz*AsyncSocks5Connection.handle_async_requestr[cCs
 113  ||jkS�N)rkrcr<r<r=�can_handle_request-s
 114  z(AsyncSocks5Connection.can_handle_requestc�s$�|jdur|j��IdHdSdSr�)rm�aclose�rXr<r<r=r�0s�
 115  �zAsyncSocks5Connection.aclosecCs6|jdur|jo|jjdkp|jo|jS|j��S)Nru)rmrarkrr`rnr�r�r<r<r=r�4s
 116  ��
 117  z"AsyncSocks5Connection.is_availablecC�|jdur|jS|j��Sr�)rmrn�has_expiredr�r<r<r=r�@�
 118  
 119  z!AsyncSocks5Connection.has_expiredcCr�r�)rmrn�is_idler�r<r<r=r�Er�zAsyncSocks5Connection.is_idlecCr�r�)rmrn�	is_closedr�r<r<r=r�Jr�zAsyncSocks5Connection.is_closed�strcCs"|jdur|jr
 120  dSdS|j��S)NzCONNECTION FAILEDZ
 121  CONNECTING)rmrn�infor�r<r<r=r�Os
 122  
 123  zAsyncSocks5Connection.infocCsd|jj�d|���d�S)N�<z [z]>)rZrer�r�r<r<r=�__repr__TszAsyncSocks5Connection.__repr__)NNNTFN)r\r
 124  r]r
 125  rCr&rErFrJrKrLrMrNrMrPrQr'r()rorr'r)r[r
 126  r'rM)r'r()r'rM)r'r�)
 127  rerfrgrTr�r�r�r�r�r�r�r�r�r<r<r<r=r^�s"�
 128  
 129  U
 130  
 131  
 132  
 133  
 134  
 135  r^)
 136  r!rr"r#r$r%r r&r'r()'�
 137  __future__r�logging�sslr+Z_backends.autorZ_backends.baserr�_exceptionsrrZ_modelsr	r
 138  rrr
 139  r�_sslrZ_synchronizationr�_tracerZconnection_poolrZhttp11rZ
 140  interfacesr�	getLoggerr}r1r6r>r?r^r<r<r<r=�<module>sD 
 141  ���?T