CYh#dZddlmZ ddlZddl Z ddl m Z ddl mZmZdd lmZmZdd lmZmZdd lmZdd lmZ ddlZ dd l mZGddeZGddeZGddeeZ GddeZ!GddeZ"GddeZ#y#e$rddlZddlmZejdewxYw#e$rdZY{wxYw#e$re j8ee j<fZYwxYw)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) TypedDictcJeZdZUded<ded<ded<ded<ded<ded <y ) _TYPE_SOCKS_OPTIONSint socks_version str | None proxy_host proxy_portusernamepasswordboolrdnsN)__name__ __module__ __qualname____annotations__7/usr/lib/python3/dist-packages/urllib3/contrib/socks.pyrrMs% r rc<eZdZdZ dfd ZddZxZS)SOCKSConnectionzG A plain-text HTTP connection that connects via a SOCKS proxy. c2||_t||i|y)N)_socks_optionssuper__init__)selfr%argskwargs __class__s r!r'zSOCKSConnection.__init__^s - $)&)r c Di}|jr|j|d<|jr|j|d< tj|j|j ff|j d|j d|j d|j d|j d|j d|jd |}|S#t$r-}t|d |jd |jd |d }~wtj$rt}|jrS|j}t|tr(t|d |jd |jd |t|d|t|d||d }~wt$r}t|d||d }~wwxYw)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: )r-r.sockscreate_connectionhostportr%r SocketTimeoutr ProxyError socket_err isinstancer OSError)r(extra_kwconneerrors r! _new_connzSOCKSConnection._new_conngs+-   )-)<)#22:>..v6   DX A %  +HVWX   || e]3-( 3PQUQ]Q]P^^_`- FugN)B1#F $>qcB  s1B C F(C99FA/E>> F FF)r%rr) typing.Anyr*rCreturnNone)rDzsocks.socksocket)rrr__doc__r'rB __classcell__r+s@r!r#r#Ys8*+** *  *8r r#c eZdZy)SOCKSHTTPSConnectionN)rrrrr r!rJrJsr rJceZdZeZy)SOCKSHTTPConnectionPoolN)rrrr# ConnectionClsrr r!rLrLs#Mr rLceZdZeZy)SOCKSHTTPSConnectionPoolN)rrrrJrMrr r!rOrOs(Mr rOcNeZdZdZeedZ d dfd ZxZS)SOCKSProxyManagerzh A version of the urllib3 ProxyManager that routes connections via the defined SOCKS proxy. )httphttpsc bt|}|<|:|j.|jjd}t|dk(r|\}}|jdk(rt j } d} nt|jdk(rt j } d} nR|jdk(rt j} d} n0|jdk(rt j} d} ntd |||_ | |j|j||| d } | |d <t |4||fi|tj|_y) N:rsocks5Fsocks5hTsocks4socks4az'Unable to determine SOCKS version from )rrrrrrr%)rauthsplitlenschemer5PROXY_TYPE_SOCKS5PROXY_TYPE_SOCKS4 ValueError proxy_urlr7r8r&r'rQpool_classes_by_scheme) r(rarr num_poolsheadersconnection_pool_kwparsedr[rr socks_optionsr+s r!r'zSOCKSProxyManager.__init__s*9%   0V[[5LKK%%c*E5zQ%*"( ==H $!33MD ]]i '!33MD ]]h &!33MD ]]i '!33MDFykRS S"+ ++ ++    0=+, GB/AB&7&N&N#r )NN N) rastrrrrrrcrrdztyping.Mapping[str, str] | NonererC) rrrrFrLrOrbr'rGrHs@r!rQrQsr () $#37 ,O,O,O ,O  ,O 1 ,O),O,Or rQ)$rF __future__rr5 ImportErrorwarnings exceptionsrwarntypingsocketrr9 connectionrrconnectionpoolr r r r poolmanagerr util.urlrsslrrDictriAnyr#rJrLrOrQrr r!rxs&P#  +8D@%  7 iFnFZ ?O $0$)2)7O 7OK  .HMM R     4 C7 ++c6::o67s.B B3C $B03B=<B= C#"C#