zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
U
 ý°d#ã@stdZddlmZz ddlZWn6ek
rRddlZddlmZe de¡‚YnXddl    Z    ddl
m Z ddl mZmZdd    lmZmZdd
lmZmZdd lmZdd lmZz ddlZWnek
rÔdZYnXz dd l    mZGdd„deƒZWn&ek
re    jee    jfZYnXGdd„deƒZGdd„deeƒZ Gdd„deƒZ!Gdd„deƒZ"Gdd„deƒZ#dS)a‰
This module contains provisional support for SOCKS proxies from within
urllib3. This module supports SOCKS4, SOCKS4A (an extension of SOCKS4), and
SOCKS5. To enable its functionality, either install PySocks or install this
module with the ``socks`` extra.
 
The SOCKS implementation supports the full range of urllib3 features. It also
supports the following SOCKS features:
 
- SOCKS4A (``proxy_url='socks4a://...``)
- SOCKS4 (``proxy_url='socks4://...``)
- SOCKS5 with remote DNS (``proxy_url='socks5h://...``)
- SOCKS5 with local DNS (``proxy_url='socks5://...``)
- Usernames and passwords for the SOCKS proxy
 
.. note::
   It is recommended to use ``socks5h://`` or ``socks4a://`` schemes in
   your ``proxy_url`` to ensure that DNS resolution is done from the remote
   server instead of client-side when connecting to a domain name.
 
SOCKS4 supports IPv4 and domain names with the SOCKS4A extension. SOCKS5
supports IPv4, IPv6, and domain names.
 
When connecting to a SOCKS4 proxy the ``username`` portion of the ``proxy_url``
will be sent as the ``userid`` section of the SOCKS request:
 
.. code-block:: python
 
    proxy_url="socks4a://<userid>@proxy-host"
 
When connecting to a SOCKS5 proxy the ``username`` and ``password`` portion
of the ``proxy_url`` will be sent as the username/password to authenticate
with the proxy:
 
.. code-block:: python
 
    proxy_url="socks5h://<username>:<password>@proxy-host"
 
é)Ú annotationsNé)ÚDependencyWarningzÂSOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks.  For more information, see https://urllib3.readthedocs.io/en/latest/contrib.html#socks-proxies)Útimeout)ÚHTTPConnectionÚHTTPSConnection)ÚHTTPConnectionPoolÚHTTPSConnectionPool)ÚConnectTimeoutErrorÚNewConnectionError)Ú PoolManager)Ú    parse_url)Ú    TypedDictc@s>eZdZUded<ded<ded<ded<ded<ded    <d
S) Ú_TYPE_SOCKS_OPTIONSÚintÚ socks_versionú
str | NoneÚ
proxy_hostÚ
proxy_portÚusernameÚpasswordÚboolÚrdnsN)Ú__name__Ú
__module__Ú __qualname__Ú__annotations__©rrúLd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\urllib3/contrib/socks.pyrMs
rcs:eZdZdZdddddœ‡fdd„ Zdd    œd
d „Z‡ZS) ÚSOCKSConnectionzG
    A plain-text HTTP connection that connects via a SOCKS proxy.
    rú
typing.AnyÚNone)Ú_socks_optionsÚargsÚkwargsÚreturncs||_tƒj||ŽdS)N)r"ÚsuperÚ__init__)Úselfr"r#r$©Ú    __class__rrr'^szSOCKSConnection.__init__zsocks.socksocket)r%c
Csti}|jr|j|d<|jr$|j|d<zTtj|j|jff|jd|jd|jd|jd|jd|jd|jd    œ|—Ž}Wnötk
r¸}z"t    |d
|j›d |j›d ƒ|‚W5d }~XYn¸tj
k
r:}zb|j r|j }t |tƒrt    |d
|j›d |j›d ƒ|‚nt |d|›ƒ‚nt |d|›ƒ|‚W5d }~XYn6tk
rn}zt |d|›ƒ|‚W5d }~XYnX|S)zA
        Establish a new connection via the SOCKS proxy.
        Úsource_addressÚsocket_optionsrrrrrr)Ú
proxy_typeZ
proxy_addrrZproxy_usernameZproxy_passwordZ
proxy_rdnsrzConnection to z timed out. (connect timeout=ú)Nz&Failed to establish a new connection: )r+r,ÚsocksÚcreate_connectionÚhostÚportr"rÚ SocketTimeoutr
Ú
ProxyErrorZ
socket_errÚ
isinstancer ÚOSError)r(Úextra_kwÚconnÚeÚerrorrrrÚ    _new_conngsl
 
 
ÿø    ÷
þý þýÿÿþÿþzSOCKSConnection._new_conn)rrrÚ__doc__r'r;Ú __classcell__rrr)rrYs    rc@s eZdZdS)ÚSOCKSHTTPSConnectionN)rrrrrrrr>¦sr>c@seZdZeZdS)ÚSOCKSHTTPConnectionPoolN)rrrrÚ ConnectionClsrrrrr?ªsr?c@seZdZeZdS)ÚSOCKSHTTPSConnectionPoolN)rrrr>r@rrrrrA®srAcs<eZdZdZeedœZd dddddd    d
œ‡fd d „ Z‡ZS)ÚSOCKSProxyManagerzh
    A version of the urllib3 ProxyManager that routes connections via the
    defined SOCKS proxy.
    )ÚhttpÚhttpsNé
Ústrrrztyping.Mapping[str, str] | Noner )Ú    proxy_urlrrÚ    num_poolsÚheadersÚconnection_pool_kwc  sêt|ƒ}|dkrB|dkrB|jdk    rB|j d¡}t|ƒdkrB|\}}|jdkrXtj}    d}
nP|jdkrntj}    d}
n:|jdkr„tj}    d}
n$|jdkrštj}    d}
ntd    |›ƒ‚||_    |    |j
|j |||
d
œ} | |d <t ƒj ||f|Žtj|_dS) Nú:rZsocks5FZsocks5hTZsocks4Zsocks4az'Unable to determine SOCKS version from )rrrrrrr")r ÚauthÚsplitÚlenÚschemer/ZPROXY_TYPE_SOCKS5ZPROXY_TYPE_SOCKS4Ú
ValueErrorrGr1r2r&r'rBÚpool_classes_by_scheme) r(rGrrrHrIrJÚparsedrMrrZ socks_optionsr)rrr'½s:      
 
 
 
úzSOCKSProxyManager.__init__)NNrEN)    rrrr<r?rArQr'r=rrr)rrB²sþúrB)$r<Ú
__future__rr/Ú ImportErrorÚwarningsÚ
exceptionsrÚwarnÚtypingÚsocketrr3Ú
connectionrrÚconnectionpoolrr    r
r Ú poolmanagerr Zutil.urlr ÚsslrrÚDictrFÚAnyrr>r?rArBrrrrÚ<module>s@(   ú    
 M