RedZddlmZ ddlZn%#e$rddlZddlmZejdewxYwddl m Z ddl m Z dd lmZmZdd lmZmZdd lmZmZdd lmZdd lmZ ddlZn #e$rdZYnwxYwGddeZGddeeZGddeZGddeZGddeZdS)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" )absolute_importN)DependencyWarningzSOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks. For more information, see https://urllib3.readthedocs.io/en/1.26.x/contrib.html#socks-proxies)error)timeout)HTTPConnectionHTTPSConnection)HTTPConnectionPoolHTTPSConnectionPool)ConnectTimeoutErrorNewConnectionError) PoolManager) parse_urlc(eZdZdZfdZdZxZS)SOCKSConnectionzG A plain-text HTTP connection that connects via a SOCKS proxy. c||d|_tt|j|i|dS)N_socks_options)poprsuperr__init__)selfargskwargs __class__s /builddir/build/BUILDROOT/alt-python311-pip-21.3.1-3.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/urllib3/contrib/socks.pyrzSOCKSConnection.__init__Ps@$jj)9::-ot$$-t>v>>>>>c i}|jr |j|d<|jr |j|d< tj|j|jff|jd|jd|jd|jd|jd|jd|jd |}n#t$r"t|d |jd |jd tj $ro}|j rP|j }t|tr!t|d |jd |jd t|d |zt|d |zd}~wt$r}t|d |zd}~wwxYw|S)zA Establish a new connection via the SOCKS proxy. source_addresssocket_options socks_version proxy_host proxy_portusernamepasswordrdns) proxy_type proxy_addrr"proxy_usernameproxy_password proxy_rdnsrzConnection to z timed out. (connect timeout=)z(Failed to establish a new connection: %sN)rrsockscreate_connectionhostportrr SocketTimeoutr ProxyError socket_err isinstancer SocketError)rextra_kwconners r _new_connzSOCKSConnection._new_connTs   =)-)#2:>.v6     DD   %999dlll,     |  e]33 -999dlll4 -H5P)DqH   $@1D    s%A-B9E A*D77 EEE)__name__ __module__ __qualname____doc__rr8 __classcell__rs@rrrKsQ?????8888888rrceZdZdS)SOCKSHTTPSConnectionN)r9r:r;rrr@r@sDrr@ceZdZeZdS)SOCKSHTTPConnectionPoolN)r9r:r;r ConnectionClsrArrrCrCs#MMMrrCceZdZeZdS)SOCKSHTTPSConnectionPoolN)r9r:r;r@rDrArrrFrFs(MMMrrFc6eZdZdZeedZ dfd ZxZS)SOCKSProxyManagerzh A version of the urllib3 ProxyManager that routes connections via the defined SOCKS proxy. )httphttpsN c 8t|}|;|9|j2|jd}t|dkr|\}}|jdkrt j} d} n`|jdkrt j} d} nF|jdkrt j} d} n,|jdkrt j} d} ntd |z||_ | |j |j ||| d } | |d <tt|j||fi|tj|_dS) N:rsocks5Fsocks5hTsocks4socks4az)Unable to determine SOCKS version from %s)r r!r"r#r$r%r)rauthsplitlenschemer,PROXY_TYPE_SOCKS5PROXY_TYPE_SOCKS4 ValueError proxy_urlr.r/rrHrpool_classes_by_scheme) rrYr#r$ num_poolsheadersconnection_pool_kwparsedrSr r% socks_optionsrs rrzSOCKSProxyManager.__init__sV9%%   0V[5LK%%c**E5zzQ%*"( =H $ $!3MDD ]i ' '!3MDD ]h & &!3MDD ]i ' '!3MDDH9TUU U"+ + +     0=+,/&&/ w  "4   '8&N###r)NNrKN) r9r:r;r<rCrFrZrr=r>s@rrHrHst () .O.O.O.O.O.O.O.O.O.OrrH) r< __future__rr, ImportErrorwarnings exceptionsrwarnsocketrr4rr0 connectionrr connectionpoolr r r r poolmanagerrutil.urlrsslrr@rCrFrHrArrrksI&&N'&&&&& LLLL    OOO......HM R     ('''''++++++88888888DDDDDDDD@@@@@@@@%%%%%% JJJJ CCCAAAAAnAAAP     ?O   $$$$$0$$$)))))2)))9O9O9O9O9O 9O9O9O9O9Os"1%A**A43A4