U f}@s>dZddlmZz ddlZWn6ek rRddlZddlmZedeYnXddl Z ddl m Z ddl mZmZdd lmZmZdd lmZmZdd lmZdd lmZz ddlZWnek rdZYnXGd dde jZGdddeZGdddeeZGdddeZGdddeZGdddeZ 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/advanced-usage.html#socks-proxies)timeout)HTTPConnectionHTTPSConnection)HTTPConnectionPoolHTTPSConnectionPool)ConnectTimeoutErrorNewConnectionError) PoolManager) parse_urlc@s>eZdZUded<ded<ded<ded<ded<ded <d S) _TYPE_SOCKS_OPTIONSint socks_version str | None proxy_host proxy_portusernamepasswordboolrdnsN)__name__ __module__ __qualname____annotations__rrF/opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/socks.pyrKs rcs:eZdZdZdddddfdd Zdd d d ZZS) SOCKSConnectionzG A plain-text HTTP connection that connects via a SOCKS proxy. r typing.AnyNone)_socks_optionsargskwargsreturncs||_tj||dS)N)r!super__init__)selfr!r"r# __class__rrr&YszSOCKSConnection.__init__zsocks.socksocket)r$c Csti}|jr|j|d<|jr$|j|d<zTtj|j|jff|jd|jd|jd|jd|jd|jd|jd |}Wntk r}z"t |d |jd |jd |W5d }~XYntj k r:}zb|j r|j }t |trt |d |jd |jd |nt |d|nt |d||W5d }~XYn6tk rn}zt |d||W5d }~XYnX|S)zA Establish a new connection via the SOCKS proxy. source_addresssocket_optionsrrrrrr) proxy_typeZ proxy_addrrZproxy_usernameZproxy_passwordZ proxy_rdnsrzConnection to z timed out. (connect timeout=)Nz&Failed to establish a new connection: )r*r+sockscreate_connectionhostportr!r SocketTimeoutr ProxyErrorZ socket_err isinstancer OSError)r'extra_kwconneerrorrrr _new_connbsl      zSOCKSConnection._new_conn)rrr__doc__r&r: __classcell__rrr(rrTs rc@s eZdZdS)SOCKSHTTPSConnectionN)rrrrrrrr=sr=c@seZdZeZdS)SOCKSHTTPConnectionPoolN)rrrr ConnectionClsrrrrr>sr>c@seZdZeZdS)SOCKSHTTPSConnectionPoolN)rrrr=r?rrrrr@sr@cs<eZdZdZeedZd dddddd d fd d ZZS)SOCKSProxyManagerzh A version of the urllib3 ProxyManager that routes connections via the defined SOCKS proxy. )httphttpsN strrrztyping.Mapping[str, str] | Noner) proxy_urlrr num_poolsheadersconnection_pool_kwc  st|}|dkrB|dkrB|jdk rB|jd}t|dkrB|\}}|jdkrXtj} d} nP|jdkrntj} d} n:|jdkrtj} d} n$|jdkrtj} d} ntd |||_ | |j |j ||| d } | |d <t j ||f|tj|_dS) N:rZsocks5FZsocks5hTZsocks4Zsocks4az'Unable to determine SOCKS version from )rrrrrrr!)r authsplitlenschemer.ZPROXY_TYPE_SOCKS5ZPROXY_TYPE_SOCKS4 ValueErrorrFr0r1r%r&rApool_classes_by_scheme) r'rFrrrGrHrIparsedrLrrZ socks_optionsr(rrr&s:       zSOCKSProxyManager.__init__)NNrDN) rrrr;r>r@rPr&r<rrr(rrAsrA)!r; __future__rr. ImportErrorwarnings exceptionsrwarntypingsocketrr2 connectionrrconnectionpoolrr r r poolmanagerr Zutil.urlr ssl TypedDictrrr=r>r@rArrrrs8(         M