Hacked By AnonymousFox

Current Path : /opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/__pycache__/socks.cpython-38.pyc

U

��`��@s0dZddlmZzddlZWn6ek
rRddlZddlmZe�de��YnXddl	m
Zddl	mZ
dd	lmZmZdd
lmZmZddlmZmZddlmZdd
lmZzddlZWnek
r�dZYnXGdd�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://<userid>@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://<username>:<password>@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||�dS)N�_socks_options)�popr�superr�__init__)�self�args�kwargs��	__class__��F/opt/alt/python38/lib/python3.8/site-packages/urllib3/contrib/socks.pyrPszSOCKSConnection.__init__c
CsHi}|jr|j|d<|jr$|j|d<zTtj|j|jff|jd|jd|jd|jd|jd|jd|jd	�|��}Wn�tk
r�t	|d
|j|jf��Yn�tj
k
�r}zP|jr�|j}t|t�r�t	|d
|j|jf��nt
|d|��nt
|d|��W5d}~XYn2tk
�rB}zt
|d|��W5d}~XYnX|S)
zA
        Establish a new connection via the SOCKS proxy.
        �source_address�socket_options�
socks_version�
proxy_host�
proxy_port�username�password�rdns)Z
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�
SocketTimeoutrZ
ProxyErrorZ
socket_err�
isinstancer�SocketError)rZextra_kwZconn�errrr�	_new_connTsd


��	�

��

�����zSOCKSConnection._new_conn)�__name__�
__module__�__qualname__�__doc__rr+�
__classcell__rrrrrKsrc@seZdZdS)�SOCKSHTTPSConnectionN)r,r-r.rrrrr1�sr1c@seZdZeZdS)�SOCKSHTTPConnectionPoolN)r,r-r.r�
ConnectionClsrrrrr2�sr2c@seZdZeZdS)�SOCKSHTTPSConnectionPoolN)r,r-r.r1r3rrrrr4�sr4cs,eZdZdZeed�Zd�fdd�	Z�ZS)�SOCKSProxyManagerzh
    A version of the urllib3 ProxyManager that routes connections via the
    defined SOCKS proxy.
    )�http�httpsN�
cs�t|�}|dkrB|dkrB|jdk	rB|j�d�}t|�dkrB|\}}|jdkrXtj}	d}
nN|jdkrntj}	d}
n8|jdkr�tj}	d}
n"|jdkr�tj}	d}
ntd	|��||_	|	|j
|j|||
d
�}||d<tt
|�j||f|�t
j|_dS)N�:rZsocks5FZsocks5hTZsocks4Zsocks4az)Unable to determine SOCKS version from %s)rrrr r!r"r)rZauth�split�len�schemer#ZPROXY_TYPE_SOCKS5ZPROXY_TYPE_SOCKS4�
ValueError�	proxy_urlr%r&rr5r�pool_classes_by_scheme)rr>r r!Z	num_pools�headersZconnection_pool_kw�parsedr:rr"Z
socks_optionsrrrr�sD	



�
��zSOCKSProxyManager.__init__)NNr8N)	r,r-r.r/r2r4r?rr0rrrrr5�s��r5) r/�
__future__rr#�ImportError�warnings�
exceptionsr�warn�socketrr)rr'Z
connectionrrZconnectionpoolr	r
rrZpoolmanagerr
Zutil.urlrZsslrr1r2r4r5rrrr�<module>s6'�
H

Hacked By AnonymousFox1.0, Coded By AnonymousFox