a
G2�]~ � @ s8 d Z ddlZddlZzddlZddlZW n* eyR ddlmZ ddlm Z Y n0 ddl
Z
dd� Zdd� Ze
� ZG dd� dej�ZG d d
� d
ej�ZG dd� dejej�Zed
k�r4ddlZzeejd �ZW n eefy� dZY n0 e�ee
jde��Ze de�!d��"� �#� � e de�!d��"� �#� � dS )z�
SocksiPy + urllib2 handler
version: 0.3
author: e<e@tr0ll.in>
This module provides a Handler which you can use with urllib2 to allow it to tunnel your connection through a socks.sockssocket socket, with out monkey patching the original socket...
� Nc C s | � � }|�|� |S �N)�copy�update)�a�b�d� r �0/usr/lib/python3.9/site-packages/sockshandler.py�
merge_dict s
r
c C sN z6d| v rt �t j| � nd| v r.t �| � nW dS W n Y dS 0 dS d S )N�:�.FT)�socketZ inet_ptonZAF_INET6Z inet_aton)�sr r r �is_ip s
r c @ s e Zd Zddd�Zdd� ZdS )�SocksiPyConnectionNTc O s0 ||||||f| _ tjj| g|�R i |�� d S r )� proxyargs�httplib�HTTPConnection�__init__� �self� proxytype� proxyaddr� proxyport�rdns�username�password�args�kwargsr r r r + s zSocksiPyConnection.__init__c C s� | j \}}}}}}|o|tv}z:t�| j| jf| jd ||||||tjtj dff�
}W q�W q tj
y� } z8|r�dt|�v r�t| j�s�d}t�
|� n� W Y d }~qd }~0 0 q|| _d S )N� Z0x5bF)r �socks4_no_rdns�socksZcreate_connection�host�port�timeoutr
ZIPPROTO_TCPZTCP_NODELAYZSOCKS4Error�strr �add�sock) r r r r r r r r'