Format: application/x-python-code
1 o
2
3 7'h.5 �
4 @ s d dl mZ d dlZd dlZd dlZddlmZ ddlmZm Z ddl
5 mZmZ ddl
6 mZmZmZmZmZmZ ddlmZ dd lmZ dd
7 lmZ ddlmZ dd
8 lmZ ddlmZ e� d�Z!ddddd�Z"dddddddddd� Z#dd�d0d*d+�Z$G d,d-� d-e�Z%G d.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) r r r � � � � � � )�auth�streamr �host�bytes�port�intr �tuple[bytes, bytes] | None�return�Nonec C s� t j�� }|d u rt jjjnt jjj}|�t j�|g�� |�� }| � |� | j
12 dd�}|�|�}t|t jj
13 �s:J �|j|krWt�|d�} t�|jd�}
14 td| � d|
15 � d���|jt jjjkr�|d useJ �|\}}|�t j�||�� |�� }| � |� | j
16 dd�}|�|�}t|t jj�s�J �|js�td��|�t jj�t jjj||f�� |�� }| � |� | j
17 dd�}|�|�}t|t jj�s�J �|jt jjjkr�t�|jd�}
18 td |
19 � d���d S )
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�sendZSOCKS5AuthMethodsRequestZdata_to_send�write�readZreceive_data�
22 isinstanceZSOCKS5AuthReply�method�AUTH_METHODS�getr ZSOCKS5UsernamePasswordRequestZSOCKS5UsernamePasswordReply�successZSOCKS5CommandRequest�from_addressZ
23 SOCKS5CommandZCONNECTZSOCKS5Reply�
24 reply_codeZSOCKS5ReplyCodeZ SUCCEEDED�REPLY_CODES)r! r"