o âÄd¹ã@s(dZddlmZzddlZWney&ddlZddlmZe de¡‚wddl m Z ddl m Z dd lmZmZdd lmZmZdd lmZmZdd lmZdd lmZzddlZWn eyhdZYnwGdd„deƒZGdd„deeƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)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é)ÚDependencyWarningzÂSOCKS 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)ÚHTTPConnectionÚHTTPSConnection)ÚHTTPConnectionPoolÚHTTPSConnectionPool)ÚConnectTimeoutErrorÚNewConnectionError)Ú PoolManager)Ú parse_urlcs(eZdZdZ‡fdd„Zdd„Z‡ZS)ÚSOCKSConnectionzG A plain-text HTTP connection that connects via a SOCKS proxy. cs&| d¡|_tt|ƒj|i|¤ŽdS)NÚ_socks_options)ÚpoprÚsuperrÚ__init__)ÚselfÚargsÚkwargs©Ú __class__©úp/private/var/folders/v1/_jykv66s6qd26_69j1njbrl80000gr/T/pip-target-p1gutpg6/lib/python/urllib3/contrib/socks.pyrPs zSOCKSConnection.__init__c Cs$i}|jr |j|d<|jr|j|d<z+tj|j|jff|jd|jd|jd|jd|jd|jd|jd œ|¤Ž}W|StyOt |d |j|jfƒ‚tj y}z$|j rt|j }t |tƒrmt |d |j|jfƒ‚t |d |ƒ‚t |d |ƒ‚d }~wty‘}zt |d |ƒ‚d }~ww) zA Establish a new connection via the SOCKS proxy. Úsource_addressÚsocket_optionsÚ socks_versionÚ proxy_hostÚ proxy_portÚusernameÚpasswordÚrdns)Ú proxy_typeZ proxy_addrrZproxy_usernameZproxy_passwordZ proxy_rdnsrz0Connection to %s timed out. (connect timeout=%s)z(Failed to establish a new connection: %sN)rrÚsocksÚcreate_connectionÚhostÚportrrÚ SocketTimeoutr Ú ProxyErrorZ socket_errÚ isinstancer Ú SocketError)rÚextra_kwÚconnÚerrrrÚ _new_connTsd   ÿø ÷, à ÿþ  ÿþÿÿ€ÿ€ÿzSOCKSConnection._new_conn)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr/Ú __classcell__rrrrrKs rc@s eZdZdS)ÚSOCKSHTTPSConnectionN)r0r1r2rrrrr5“sr5c@óeZdZeZdS)ÚSOCKSHTTPConnectionPoolN)r0r1r2rÚ ConnectionClsrrrrr7—ór7c@r6)ÚSOCKSHTTPSConnectionPoolN)r0r1r2r5r8rrrrr:›r9r:cs4eZdZdZeedœZ    d‡fdd„ Z‡ZS)ÚSOCKSProxyManagerzh A version of the urllib3 ProxyManager that routes connections via the defined SOCKS proxy. )ÚhttpÚhttpsNé c  sðt|ƒ}|dur!|dur!|jdur!|j d¡}t|ƒdkr!|\}}|jdkr,tj} d} n'|jdkr7tj} d} n|jdkrBtj} d} n|jdkrMtj} d} ntd |ƒ‚||_ | |j |j ||| d œ} | |d <t t |ƒj||fi|¤Žt j|_dS) Nú:rZsocks5FZsocks5hTZsocks4Zsocks4az)Unable to determine SOCKS version from %s)rrrr r!r"r)rÚauthÚsplitÚlenÚschemer$ZPROXY_TYPE_SOCKS5ZPROXY_TYPE_SOCKS4Ú ValueErrorÚ proxy_urlr&r'rr;rÚpool_classes_by_scheme) rrEr r!Ú num_poolsÚheadersÚconnection_pool_kwÚparsedrArr"Z socks_optionsrrrrªsB        ú ÿÿ zSOCKSProxyManager.__init__)NNr>N) r0r1r2r3r7r:rFrr4rrrrr;Ÿsþúr;) r3Ú __future__rr$Ú ImportErrorÚwarningsÚ exceptionsrÚwarnÚsocketrr+rr(Ú connectionrrÚconnectionpoolr r r r Ú poolmanagerr Zutil.urlrÚsslrr5r7r:r;rrrrÚs< '   úó      ÿH