Շ5ܭxdZddlmZ ddlZn%#e$rddlZddlmZejdewxYwddl Z ddl m Z ddl mZmZdd lmZmZdd lmZmZdd lmZdd lmZ ddlZn #e$rdZYnwxYw dd l mZGddeZn#e$re jee jfZYnwxYwGddeZGddeeZ GddeZ!GddeZ"GddeZ#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://@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://:@proxy-host" ) annotationsN)DependencyWarningzSOCKS 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)HTTPConnectionHTTPSConnection)HTTPConnectionPoolHTTPSConnectionPool)ConnectTimeoutErrorNewConnectionError) PoolManager) parse_url) TypedDictcLeZdZUded<ded<ded<ded<ded<ded <d S) _TYPE_SOCKS_OPTIONSint socks_version str | None proxy_host proxy_portusernamepasswordboolrdnsN)__name__ __module__ __qualname____annotations__/srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/urllib3/contrib/socks.pyrrMsU r rc,eZdZdZd fd Zd d ZxZS)SOCKSConnectionzG A plain-text HTTP connection that connects via a SOCKS proxy. _socks_optionsrargs typing.AnykwargsreturnNonecH||_tj|i|dS)N)r$super__init__)selfr$r%r' __class__s r!r,zSOCKSConnection.__init__^s/ -$)&)))))r socks.socksocketc i}|jr |j|d<|jr |j|d< tj|j|jff|jd|jd|jd|jd|jd|jd|jd |}n#t$r'}t|d |jd |jd |d }~wtj $rq}|j rQ|j }t|tr"t|d |jd |jd |t|d|t|d||d }~wt$r}t|d||d }~wwxYw|S)zA Establish a new connection via the SOCKS proxy. source_addresssocket_optionsrrrrrr) proxy_type proxy_addrrproxy_usernameproxy_password proxy_rdnsrzConnection to z timed out. (connect timeout=)Nz&Failed to establish a new connection: )r1r2sockscreate_connectionhostportr$r SocketTimeoutr ProxyError socket_err isinstancer OSError)r-extra_kwconneerrors r! _new_connzSOCKSConnection._new_conngs+-   =)-)#2:>.v6     DD   %XXXXXX     |  e]33 -```QUQ]```-NuNN)F1FF   $BqBB    s1A-B E$"CE$A,D>> E$ EE$)r$rr%r&r'r&r(r))r(r/)rrr__doc__r,rF __classcell__r.s@r!r#r#Ys[******88888888r r#ceZdZdS)SOCKSHTTPSConnectionN)rrrrr r!rKrKsDr rKceZdZeZdS)SOCKSHTTPConnectionPoolN)rrrr# ConnectionClsrr r!rMrMs#MMMr rMceZdZeZdS)SOCKSHTTPSConnectionPoolN)rrrrKrNrr r!rPrPs(MMMr rPc8eZdZdZeedZ ddfd ZxZS)SOCKSProxyManagerzh A version of the urllib3 ProxyManager that routes connections via the defined SOCKS proxy. )httphttpsN proxy_urlstrrrr num_poolsrheaderstyping.Mapping[str, str] | Noneconnection_pool_kwr&c *t|}|;|9|j2|jd}t|dkr|\}}|jdkrt j} d} n`|jdkrt j} d} nF|jdkrt j} d} n,|jdkrt j} d} ntd |||_ | |j |j ||| d } | |d <tj ||fi|tj|_dS) N:rsocks5Fsocks5hTsocks4socks4az'Unable to determine SOCKS version from )rrrrrrr$)rauthsplitlenschemer9PROXY_TYPE_SOCKS5PROXY_TYPE_SOCKS4 ValueErrorrVr;r<r+r,rRpool_classes_by_scheme) r-rVrrrXrYr[parsedrcrr socks_optionsr.s r!r,zSOCKSProxyManager.__init__sE9%%   0V[5LK%%c**E5zzQ%*"( =H $ $!3MDD ]i ' '!3MDD ]h & &!3MDD ]i ' '!3MDDRyRRSS S"+ + +     0=+,GBB/ABBB&7&N###r )NNrUN) rVrWrrrrrXrrYrZr[r&) rrrrGrMrPrir,rHrIs@r!rRrRsz () $#37 ,O,O,O,O,O,O,O,O,O,O,Or rR)$rG __future__rr9 ImportErrorwarnings exceptionsrwarntypingsocketrr= connectionrrconnectionpoolr r r r poolmanagerr util.urlrsslrrDictrWAnyr#rKrMrPrRrr r!rzs&&P#""""" LLLL    OOO......HM R      ++++++88888888DDDDDDDD@@@@@@@@%%%%%% JJJJ CCC 7      i777 +c6:o67FFFFFnFFFZ     ?O   $$$$$0$$$)))))2)))7O7O7O7O7O 7O7O7O7O7Os,"1#A((A21A26B B'&B'