Format: application/x-python-code
⬇ Download File (9.7 KB)
   1  o
   2  
   3  7'h.5�
   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�)�SyncBackend)�NetworkBackend�
   9  NetworkStream)�ConnectionNotAvailable�
  10  ProxyError)�URL�Origin�Request�Response�
  11  enforce_bytes�enforce_url)�default_ssl_context)�Lock)�Trace�)�ConnectionPool)�HTTP11Connection)�ConnectionInterfacezhttpcore.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�NonecCs�tj��}|durtjjjntjjj}|�tj�|g��|��}|�	|�|j
  12  dd�}|�|�}t|tjj
  13  �s:J�|j|krWt�|d�}	t�|jd�}
  14  td|	�d|
  15  �d���|jtjjjkr�|duseJ�|\}}|�tj�||��|��}|�	|�|j
  16  dd�}|�|�}t|tjj�s�J�|js�td��|�tjj�tjjj||f��|��}|�	|�|j
  17  dd�}|�|�}t|tjj�s�J�|jtjjjkr�t�|jd�}
  18  td	|
  19  �d���dS)
  20  Ni)Z	max_bytes�UNKNOWNz
  21  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�
  22  isinstanceZSOCKS5AuthReply�method�AUTH_METHODS�getrZSOCKS5UsernamePasswordRequestZSOCKS5UsernamePasswordReply�successZSOCKS5CommandRequest�from_addressZ
  23  SOCKS5CommandZCONNECTZSOCKS5Reply�
  24  reply_codeZSOCKS5ReplyCodeZ	SUCCEEDED�REPLY_CODES)r!r"r$r �connZauth_methodZoutgoing_bytesZincoming_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
  25  
  26  ��
  27  
  28  
  29  �
  30  
  31  ��
  32  
  33  �r>cs@eZdZdZ									d"d#�fdd�
  34  Zd$d d!�Z�ZS)%�
  35  SOCKSProxyzB
  36      A connection pool that sends requests via an HTTP proxy.
  37      N�
  38  TFr�	proxy_url�URL | bytes | str�
  39  proxy_auth�&tuple[bytes | str, bytes | str] | None�ssl_context�ssl.SSLContext | None�max_connections�
  40  int | None�max_keepalive_connections�keepalive_expiry�float | None�http1�bool�http2�retriesr%�network_backend�NetworkBackend | Noner'r(c
  41  spt�j|||||||
  42  |	d�||_t|dd�|_|dur3|\}}t|dd�}
  43  t|dd�}|
  44  |f|_dSd|_dS)a&
  45          A connection pool for making HTTP requests.
  46  
  47          Parameters:
  48              proxy_url: The URL to use when connecting to the proxy server.
  49                  For example `"http://127.0.0.1:8080/"`.
  50              ssl_context: An SSL context to use for verifying connections.
  51                  If not specified, the default `httpcore.default_ssl_context()`
  52                  will be used.
  53              max_connections: The maximum number of concurrent HTTP connections that
  54                  the pool should allow. Any attempt to send a request on a pool that
  55                  would exceed this amount will block until a connection is available.
  56              max_keepalive_connections: The maximum number of idle HTTP connections
  57                  that will be maintained in the pool.
  58              keepalive_expiry: The duration in seconds that an idle HTTP connection
  59                  may be maintained for before being expired from the pool.
  60              http1: A boolean indicating if HTTP/1.1 requests should be supported
  61                  by the connection pool. Defaults to True.
  62              http2: A boolean indicating if HTTP/2 requests should be supported by
  63                  the connection pool. Defaults to False.
  64              retries: The maximum number of retries when trying to establish
  65                  a connection.
  66              local_address: Local address to connect from. Can also be used to
  67                  connect using a particular address family. Using
  68                  `local_address="0.0.0.0"` will connect using an `AF_INET` address
  69                  (IPv4), while using `local_address="::"` will connect using an
  70                  `AF_INET6` address (IPv6).
  71              uds: Path to a Unix Domain Socket to use instead of TCP sockets.
  72              network_backend: A backend instance to use for handling network I/O.
  73          )rErGrIrJrLrNrPrOrA)�nameNrC)�super�__init__�_ssl_contextr�
  74  _proxy_urlr
  75  �_proxy_auth)�selfrArCrErGrIrJrLrNrOrPr:r;Zusername_bytesZpassword_bytes��	__class__r<r=rTns(+�
  76  
  77  �
  78  zSOCKSProxy.__init__�originr
  79  rc
  80  Cs(t|jj||j|j|j|j|j|jd�S)N)�proxy_origin�
  81  remote_originrCrErJrLrNrP)	�Socks5ConnectionrVr[rWrU�_keepalive_expiry�_http1�_http2�_network_backend�rXr[r<r<r=�create_connection�s�zSOCKSProxy.create_connection)	NNr@NNTFrN)rArBrCrDrErFrGrHrIrHrJrKrLrMrNrMrOr%rPrQr'r()r[r
  82  r'r)�__name__�
  83  __module__�__qualname__�__doc__rTrd�
  84  __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
  85  d3d)d*�Zd3d+d,�ZdS)4r^NTFr\r
  86  r]rCr&rErFrJrKrLrMrNrPrQr'r(c		CsV||_||_||_||_||_||_||_|durt�n||_t	�|_
  87  d|_d|_dS)NF)
  88  �
  89  _proxy_origin�_remote_originrWrUr_r`rarrbr�
  90  _connect_lock�_connection�_connect_failed)	rXr\r]rCrErJrLrNrPr<r<r=rT�s�
  91  zSocks5Connection.__init__�requestrrcCsh|j�di�}|j�dd�}|�dd�}|j��
  92  |jdu�rz�|jj�d�|jj|d�}tdt	||��}|j
  93  jdi|��}||_Wd�n1sKwY||j
  94  j�d�|j
  95  j|jd�}tdt	||��}tdi|��||_Wd�n1s{wY|j
  96  jd	kr�|jdur�t�n|j}|jr�d
  97  dgnd
  98  g}	|�|	�||p�|j
  99  j�d�|d�}td
 100  t	||��}|jdi|��}||_Wd�n1s�wY|�d�}
 101  |
 102  duo�|
 103  ��dk}|s�|jr�|js�ddlm}||j
 104  ||jd�|_n
 105  t|j
 106  ||jd�|_Wnt�y}
 107  zd|_|
 108  �d}
 109  ~
 110  ww|j���st ��Wd�n	1�s)wY|j�!|�S)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�
 111  ssl_objectr)�HTTP2Connection)r[r!rJTr<)"�
 112  extensionsr2rlrmrjr"�decoder$r�loggerrbrt�return_valuerkrWr>�schemerUrra�set_alpn_protocolsrx�get_extra_info�selected_alpn_protocolr`rNrzr_r�	Exceptionrn�is_availabler�handle_request)rXroZtimeoutsrqrp�kwargs�tracer!rE�alpn_protocolsryZhttp2_negotiatedrz�excr<r<r=r��s�
 113  �����
 114  ���
 115  ��
 116  
 117  ���
 118  �������NzSocks5Connection.handle_requestr[cCs
 119  ||jkS�N)rkrcr<r<r=�can_handle_request-s
 120  z#Socks5Connection.can_handle_requestcCs|jdur|j��dSdSr�)rm�close�rXr<r<r=r�0s
 121  �zSocks5Connection.closecCs6|jdur|jo|jjdkp|jo|jS|j��S)Nru)rmrarkrr`rnr�r�r<r<r=r�4s
 122  ��
 123  zSocks5Connection.is_availablecC�|jdur|jS|j��Sr�)rmrn�has_expiredr�r<r<r=r�@�
 124  
 125  zSocks5Connection.has_expiredcCr�r�)rmrn�is_idler�r<r<r=r�Er�zSocks5Connection.is_idlecCr�r�)rmrn�	is_closedr�r<r<r=r�Jr�zSocks5Connection.is_closed�strcCs"|jdur|jr
 126  dSdS|j��S)NzCONNECTION FAILEDZ
 127  CONNECTING)rmrn�infor�r<r<r=r�Os
 128  
 129  zSocks5Connection.infocCsd|jj�d|���d�S)N�<z [z]>)rZrer�r�r<r<r=�__repr__TszSocks5Connection.__repr__)NNNTFN)r\r
 130  r]r
 131  rCr&rErFrJrKrLrMrNrMrPrQr'r()rorr'r)r[r
 132  r'rM)r'r()r'rM)r'r�)
 133  rerfrgrTr�r�r�r�r�r�r�r�r�r<r<r<r=r^�s"�
 134  
 135  U
 136  
 137  
 138  
 139  
 140  
 141  r^)
 142  r!rr"r#r$r%r r&r'r()'�
 143  __future__r�logging�sslr+Z_backends.syncrZ_backends.baserr�_exceptionsrrZ_modelsr	r
 144  rrr
 145  r�_sslrZ_synchronizationr�_tracerZconnection_poolrZhttp11rZ
 146  interfacesr�	getLoggerr}r1r6r>r?r^r<r<r<r=�<module>sD 
 147  ���?T