
    ,h~                        d Z ddlZddlZ	 ddlZddlZddl
Z
d Zd Z e       Z G d dej                        Z G d dej"                        Z G d	 d
ej&                  ej(                        Zedk(  rddlZ	  eej2                  d         Z ej:                   ee
j<                  de            Z e dejC                  d      jE                         jG                         z           e dejC                  d      jE                         jG                         z          yy# e$ r ddlmZ ddlm	Z Y  w xY w# eef$ r dZY w xY w)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                 H    | j                         }|j                  |       |S N)copyupdate)abds      N/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/sockshandler.py
merge_dictr      s    	AHHQKH    c                     	 d| v r%t        j                  t         j                  |        yd| v rt        j                  |        yy#  Y yxY w)N:.FT)socket	inet_ptonAF_INET6	inet_aton)ss    r
   is_ipr      sR    
!8V__a0  AXQ 	 s   (A A A
c                       e Zd ZddZd Zy)SocksiPyConnectionNc                 d    ||||||f| _         t        j                  j                  | g|i | y r   )	proxyargshttplibHTTPConnection__init__	self	proxytype	proxyaddr	proxyportrdnsusernamepasswordargskwargss	            r
   r   zSocksiPyConnection.__init__+   s4    #Y	48T''>t>v>r   c                    | j                   \  }}}}}}|xr |t        v}	 	 t        j                  | j                  | j
                  f| j                  d ||||||t        j                  t        j                  dff
      }	 || _        y # t        j                  $ rG}|r:dt        |      v r-t        | j                        sd}t        j                  |       n Y d }~nd }~ww xY w)N   0x5bF)r   socks4_no_rdnssockscreate_connectionhostporttimeoutr   IPPROTO_TCPTCP_NODELAYSOCKS4Errorstrr   addsock)	r   r   r    r!   r"   r#   r$   r5   es	            r
   connectzSocksiPyConnection.connect/   s    FJnnCIy$(7	7..YY		*DLL$y)T8X((&*<*<a@BD  	 $$ Fc!f,U4995E !D"&&y1 2 s   AB	 	C#=CC#NTNN__name__
__module____qualname__r   r7    r   r
   r   r   *   s    ?r   r   c                       e Zd ZddZd Zy)SocksiPyConnectionSNc                 d    ||||||f| _         t        j                  j                  | g|i | y r   )r   r   HTTPSConnectionr   r   s	            r
   r   zSocksiPyConnectionS.__init__D   s4    #Y	48T((???r   c                    t         j                  |        | j                  j                  | j                  | j
                        | _        | j                  j                  sG| j                  r:	 t        j                  | j                  j                         | j
                         y y y # t        $ rE | j                  j                  t        j                         | j                  j                           w xY w)N)server_hostname)r   r7   _contextwrap_socketr5   r-   check_hostname_check_hostnamesslmatch_hostnamegetpeercert	Exceptionshutdownr   	SHUT_RDWRclose)r   s    r
   r7   zSocksiPyConnectionS.connectH   s    ""4(MM--dii-S	}}++0D0D""499#8#8#:DIIF 1E+  		""6#3#34		!s   /8B* *AC8r8   r9   r=   r   r
   r?   r?   C   s    @	r   r?   c                       e Zd Zd Zd Zd Zy)SocksiPyHandlerc                 ^    || _         || _        t        j                  j	                  |        y r   )r%   kwurllib2HTTPHandlerr   )r   r%   r&   s      r
   r   zSocksiPyHandler.__init__T   s$    	$$T*r   c                 4     d fd	} j                  ||      S )Nc                 f    t        j                  |      }t        j                  | ||d|}|S N)r-   r.   r/   )r   rR   r   r%   r-   r.   r/   r&   rR   connr   s         r
   buildz(SocksiPyHandler.http_open.<locals>.buildZ   s3    DGGV,B%tyyt$PW^[]^DKr   Nr   do_openr   reqrZ   s   `  r
   	http_openzSocksiPyHandler.http_openY       	 ||E3''r   c                 4     d fd	} j                  ||      S )Nc                 f    t        j                  |      }t        j                  | ||d|}|S rW   )r   rR   r?   r%   rX   s         r
   rZ   z)SocksiPyHandler.https_open.<locals>.builda   s3    DGGV,B&		4QX_\^_DKr   r[   r\   r^   s   `  r
   
https_openzSocksiPyHandler.https_open`   ra   r   N)r:   r;   r<   r   r`   rd   r=   r   r
   rP   rP   S   s    +
((r   rP   __main__r(   iZ#  	localhostzHTTP: zhttp://httpbin.org/ipzHTTPS: zhttps://httpbin.org/ip)$__doc__r   rH   rS   r   ImportErrorurllib.requestrequesthttp.clientclientr+   r   r   setr*   r   r   rA   r?   rT   HTTPSHandlerrP   r:   sysintargvr.   
ValueError
IndexErrorbuild_openerPROXY_TYPE_SOCKS5openerprintopenreaddecoder=   r   r
   <module>r{      sH    
"
 
 // 2'11  (g))7+?+? (( z388A; "W!!/%2I2I;X\"]^F	(V[[!89>>@GGI
IJ	)fkk":;@@BIIK
KL o  "$!!"v 
# s#   D  9D8  D54D58	EE