
    t{              	          S SK Jr  S SKr\R                  (       a  S SKrOS SKJr  S SKJ	r	J
r
Jr  S SKrS SKJr  S SKrS SKrS SKJr  S SKrS SKrS SKrSr\R,                  S:X  a  \R.                  S:  a   S SKr\R4                  " \5      rS
=rrS=rr S=r!r"\\ \"S.r#\$" \%" \#RM                  5       \#RO                  5       5      5      r(\R$                  =r)r*S r+ " S S\,5      r- " S S\-5      r. " S S\-5      r/ " S S\-5      r0 " S S\-5      r1 " S S\-5      r2 " S S\-5      r3SSSS .r4S!S"S#S$S%S&S'S(S).r5\S*\ S*\"S+0r6  S7S, jr7S- r8S. r9\9r:S/ r;\;r<     S8S0 jr= " S1 S2\R$                  5      r>S3 r?S4 HR  r\@" \>\S5      rA\B" \A\R                  5      (       a  M'  \>R                  R                  \5        \F" \>\\?" \5      5        MT      " S5 S6\>5      rGg! \ a	    \" S	5      ef = f)9    )	b64encodeN)
EOPNOTSUPPEINVALEAGAIN)BytesIO)SEEK_CURz1.7.1nt)   r   z8To run PySocks on Windows you must install win_inet_pton      r
   )SOCKS4SOCKS5HTTPc                 F   ^  [         R                  " T 5      U 4S j5       nU$ )Nc                     > U S   n UR                  5       nUS:X  a  UR                  S5        T" U 0 UD6US:X  a  UR                  S5        $ $ ! [         a  ne S nAff = f! WS:X  a  UR                  S5        f f = f)Nr   TF)
gettimeoutsetblocking	Exception)argskwargsself_is_blockingefunctions        )platform/bq/third_party/socks/__init__.pywrapper"set_self_blocking.<locals>.wrapper.   s    Aw
	(??,Lq   &T,V,
 q   ' !	  		 q   ' !s#   .A 
AAAA" "A<)	functoolswraps)r   r   s   ` r   set_self_blockingr    ,   s%    __X( ( N    c                   (    \ rS rSrSrSS jrS rSrg)
ProxyError?   z4Socket_err contains original socket.error exception.Nc                 t    Xl         X l        U(       a%  U =R                   SR                  U5      -  sl         g g )Nz: {})msg
socket_errformat)r   r&   r'   s      r   __init__ProxyError.__init__A   s+    $HHj11H r!   c                     U R                   $ N)r&   r   s    r   __str__ProxyError.__str__H   s    xxr!   )r&   r'   r,   )__name__
__module____qualname____firstlineno____doc__r)   r.   __static_attributes__ r!   r   r#   r#   ?   s    >2r!   r#   c                       \ rS rSrSrg)GeneralProxyErrorL   r6   Nr0   r1   r2   r3   r5   r6   r!   r   r8   r8   L       r!   r8   c                       \ rS rSrSrg)ProxyConnectionErrorP   r6   Nr:   r6   r!   r   r=   r=   P   r;   r!   r=   c                       \ rS rSrSrg)SOCKS5AuthErrorT   r6   Nr:   r6   r!   r   r@   r@   T   r;   r!   r@   c                       \ rS rSrSrg)SOCKS5ErrorX   r6   Nr:   r6   r!   r   rC   rC   X   r;   r!   rC   c                       \ rS rSrSrg)SOCKS4Error\   r6   Nr:   r6   r!   r   rF   rF   \   r;   r!   rF   c                       \ rS rSrSrg)	HTTPError`   r6   Nr:   r6   r!   r   rI   rI   `   r;   r!   rI   zRequest rejected or failedzLRequest rejected because SOCKS server cannot connect to identd on the clientzPRequest rejected because the client program and identd report different user-ids)[   rG   ]   zGeneral SOCKS server failurez!Connection not allowed by rulesetzNetwork unreachablezHost unreachablezConnection refusedzTTL expiredz(Command not supported, or protocol errorzAddress type not supported)r   r   r
                  i8  i  c                     [        US5      (       a  UR                  5       n[        US5      (       a  UR                  5       nXX#U(       a  UOSU(       a  UOS4[        l        g)zSets a default proxy.

All further socksocket objects will use the default unless explicitly
changed. All parameters are as for socket.set_proxy().encodeN)hasattrrS   
socksocketdefault_proxy)
proxy_typeaddrportrdnsusernamepasswords         r   set_default_proxyr]   y   sT     x"""hx"""h *$,4$,4$ @Jr!   c                  L    SU;   a  UR                  S5      US'   [        U 0 UD6$ N	proxytyperW   )popr]   )r   r   s     r   setdefaultproxyrb      s-    f%zz+6|d-f--r!   c                  "    [         R                  $ )z4Returns the default proxy, set by set_default_proxy.)rU   rV   r6   r!   r   get_default_proxyrd      s    ###r!   c                 n    [         R                  (       a  [         U R                  l        g[        S5      e)a  Attempts to replace a module's socket library with a SOCKS socket.

Must set a default proxy using set_default_proxy(...) first. This will
only work on modules that import socket directly into the namespace;
most of the Python Standard Library falls into this category.zNo default proxy specifiedN)rU   rV   socketr8   )modules    r   wrap_modulerh      s%     ) <==r!   c
           	      4   U u  pU
R                  S5      (       a  U
R                  S5      n
U(       a'  UR                  S5      (       a  UR                  S5      nSn[        R                  " XES[        R                  5       H  nUu  pnnnSn [        XU5      nU	(       a  U	 H  nUR                  " U6   M     [        U[        [        45      (       a  UR                  U5        U(       a  UR                  X4XVXx5        U(       a  UR                  U5        UR                  X45        Us  $    U(       a  Ue[        R                  " S5      e! [        R                  [        4 a.  nUnU(       a  UR!                  5         Sn SnAGM	   SnAGM  SnAff = f)a  create_connection(dest_pair, *[, timeout], **proxy_args) -> socket object

Like socket.create_connection(), but connects to proxy
before returning the socket object.

dest_pair - 2-tuple of (IP/hostname, port).
**proxy_args - Same args passed to socksocket.set_proxy() if present.
timeout - Optional socket timeout value, in seconds.
source_address - tuple (host, port) for the socket to bind to as its source
address before connecting (only for compatibility)
[z[]Nr   zgai returned empty list.)
startswithstriprf   getaddrinfoSOCK_STREAMrU   
setsockopt
isinstanceintfloat
settimeout	set_proxybindconnecterrorr#   close)	dest_pairtimeoutsource_addressrW   
proxy_addr
proxy_port
proxy_rdnsproxy_usernameproxy_passwordsocket_optionsremote_hostremote_porterrrfamilysocket_typeproto	canonnamesasockoptr   s                         r   create_connectionr      s\   $  )Kc""!''-j++C00%%d+

C 
6;M;MN451UIr	f59D)COOS) * 'C<00(zz-?		.)LL+34K) O8 	
,,1
22 j) 	C

 	s   BEF)FFc                   ,    \ rS rSrSrS r\" 5       rSrg)_BaseSocket   zBAllows Python 2 delegated methods such as send() to be overridden.c                     [         R                  " U /UQ70 UD6  [        5       U l        U R                   H&  n[        X5      U R                  U'   [        X5        M(     g r,   )_orig_socketr)   dict_savedmethods
_savenamesgetattrdelattrr   poskwnames       r   r)   _BaseSocket.__init__   sO    d/S/B/!VOOD'.t':Dt$D $r!   r   N)	r0   r1   r2   r3   r4   r)   listr   r5   r6   r!   r   r   r      s    L  Jr!   r   c                    ^  U 4S j$ )Nc                 .   > U R                   T   " U0 UD6$ r,   r   r   s      r   <lambda>_makemethod.<locals>.<lambda>   s    D$6$6t$<c$HR$Hr!   r6   )r   s   `r   _makemethodr      s	    HHr!   )sendtosendrecvfromrecvc                   f  ^  \ rS rSrSrSr\R                  \R                  S4U 4S jjr	S r
U 4S jrS rS	 r  SS
 jrS rU 4S jrU 4S jrS U 4S jjrS U 4S jjrS rU 4S jrS r\rS r\rS r\rS rU 4S jrS rS rS r S r!\"\ \#\\$\!0r%\&S!U 4S jj5       r'\&S 5       r(S r)Sr*U =r+$ )"rU      a  socksocket([family[, type[, proto]]]) -> socket object

Open a SOCKS enabled socket. The parameters are the same as
those of the standard socket init. In order for SOCKS to work,
you must specify family=AF_INET and proto=0.
The "type" argument must be either SOCK_STREAM or SOCK_DGRAM.
Nr   c                 D  > U[         R                  [         R                  4;  a  Sn[        UR	                  U5      5      e[
        [        U ]  " XU/UQ70 UD6  S U l        U R                  (       a  U R                  U l
        OSU l
        S U l        S U l        S U l        g )Nz0Socket type must be stream or datagram, not {!r})NNNNNN)rf   rn   
SOCK_DGRAM
ValueErrorr(   superrU   r)   
_proxyconnrV   proxyproxy_socknameproxy_peername_timeout)r   r   typer   r   r   r&   	__class__s          r   r)   socksocket.__init__  s    **F,=,=>>DCSZZ-..j$(uNtNvN++DJ=DJ""r!   c                     Sn[        U5      U:  aD  UR                  U[        U5      -
  5      nU(       d  [        S5      eX4-  n[        U5      U:  a  MD  U$ )zReceive EXACTLY the number of bytes requested from the file object.

Blocks until the required number of bytes have been received.r!   Connection closed unexpectedly)lenreadr8   )r   filecountdatads        r   _readallsocksocket._readall  sW     $i%		%#d)+,A'(HIIID	 $i%
 r!   c                    > Xl          U R                  5       n[        [        U ]  U R                   5        g ! [
        R                   a     g f = fr,   )r   get_proxy_peernamer   rU   rs   rf   rw   )r   rz   peerr   s      r   rs   socksocket.settimeout$  sD    	**,D*d.t}}=|| 		s   -7 AAc                     U R                   $ r,   )r   r-   s    r   r   socksocket.gettimeout-  s    }}r!   c                 X    U(       a  U R                  S 5        g U R                  S5        g )Ng        )rs   )r   vs     r   r   socksocket.setblocking0  s    OOD!OOC r!   c                     [        US5      (       a  UR                  5       n[        US5      (       a  UR                  5       nXX4U(       a  UOSU(       a  UOS4U l        g)a&  Sets the proxy to be used.

proxy_type -  The type of the proxy to be used. Three types
                are supported: PROXY_TYPE_SOCKS4 (including socks4a),
                PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP
addr -        The address of the server (IP or DNS).
port -        The port of the server. Defaults to 1080 for SOCKS
                servers and 8080 for HTTP proxy servers.
rdns -        Should DNS queries be performed on the remote side
               (rather than the local side). The default is True.
               Note: This has no effect with SOCKS4 servers.
username -    Username to authenticate with to the server.
               The default is no authentication.
password -    Password to authenticate with to the server.
               Only relevant when username is also provided.rS   N)rT   rS   r   )r   rW   rX   rY   rZ   r[   r\   s          r   rt   socksocket.set_proxy6  sR    " 8X&&__&(8X&&__&( "*h"*h6
r!   c                 Z    SU;   a  UR                  S5      US'   U R                  " U0 UD6$ r_   )ra   rt   )r   r   r   s      r   setproxysocksocket.setproxyO  s1    & #)::k#:F< ~~t.v..r!   c                   > U R                   u  p4pVnnU(       a  U R                  [        R                  :w  a  [        R
                  " U /UQ70 UD6$ U R                  (       a  [        R                  " [        S5      eU[        :w  a  Sn	[        R                  " [        U	5      e[        [        U ]  " U0 UD6  U R                  5       u  pSU4n[	        5       U l        U R                  5       nU R                  R                  U5        SnU R!                  U R                  X5      u  pUu  nn
Uu  p[        [        U ]?  UU45        [        [        U ]G  U R$                  5        SU l        g)zNImplements proxy connection for UDP sockets.

Happens during the bind() phase.z"Socket already bound to an addressz'UDP only supported by SOCKS5 proxy type0   )0.0.0.0r   N)r   r   rf   r   r   ru   r   rw   r   r   r   r   rU   getsockname_proxy_addrrv   _SOCKS5_requestrs   r   r   )r   r   r   rW   r|   r}   rZ   r[   r\   r&   _rY   dstr   UDP_ASSOCIATErelayhostr   s                    r   ru   socksocket.bindT  s5   
 ZZ	8	TYY&*;*;;$$T6C6266??,,v'KLL;C,,z3//j$$c0R0
 ""$Dk&.  "&''L aj$'t5j$*4==9,r!   c                   > U R                   [        R                  :w  a  [        [        U ]  " U/UQ70 UD6$ U R                  (       d  U R                  S5        US   nUS S n[        5       nSnUR                  U5        SnUR                  U5        U R                  XF5        [        [        U ].  " UR                  5       U-   /UQ70 UD6n	XR                  5       -
  $ )N r   s         )r   rf   r   r   rU   r   r   ru   r   write_write_SOCKS5_addressr   getvaluetell)r   bytesr   r   addressflagsheaderRSV
STANDALONEsentr   s             r   r   socksocket.sendtoy  s    99)))T1%I$I&IIIIgr(Sb	S
Z ""73Z+FOO,=,E 6 6.46kkm##r!   c                    > U R                   [        R                  :X  a  U R                  " XU R                  40 UD6$ [
        [        U ]  " X40 UD6$ r,   )r   rf   r   r   r   r   rU   r   )r   r   r   r   r   s       r   r   socksocket.send  sH    99)));;uT-@-@KFKKT/GGGr!   c                 J  > U R                   [        R                  :w  a  [        [        U ]  X5      $ U R                  (       d  U R                  S5        [        [        [        U ]'  US-   U5      5      nUR                  S[        5        UR                  S5      n[        U5      (       a  [        S5      eU R                  U5      u  pVU R                   (       a6  U R                   u  pxXW:w  d  USU4;  a  [        R"                  " [$        S5      eUR                  U5      XV44$ )Nr   i   r   r   zReceived UDP packet fragmentr   zPacket filtered)r   rf   r   r   rU   r   r   ru   r   r   seekr   r   ordNotImplementedError_read_SOCKS5_addressr   rw   r   )
r   bufsizer   buffragfromhostfromportpeerhostpeerportr   s
            r   r   socksocket.recvfrom  s    99)))T3GCCIIgeJ27T>5IJHxx{t99%&DEE!66s;!%!4!4H#x8}'Dll6+<==!H#788r!   c                 .    U R                   " U0 UD6u  p4U$ r,   )r   )r   r   r   r   r   s        r   r   socksocket.recv  s    ==#,,r!   c                 ~   > U R                   (       a  U R                   R                  5         [        [        U ]  5       $ r,   )r   rx   r   rU   )r   r   s    r   rx   socksocket.close  s*    ??OO!!#Z,..r!   c                     U R                   $ )z:Returns the bound IP address and port number at the proxy.)r   r-   s    r   get_proxy_socknamesocksocket.get_proxy_sockname  s    """r!   c                 "    U R                  5       $ )z.
Returns the IP and port number of the proxy.
)getpeernamer-   s    r   r   socksocket.get_proxy_peername  s     !!r!   c                     U R                   $ )zoReturns the IP address and port number of the destination machine.

Note: get_proxy_peername returns the proxy.)r   r-   s    r   get_peernamesocksocket.get_peername  s     """r!   c                 F    SnU R                  XU5      u  U l        U l        g)z7Negotiates a stream connection through a SOCKS5 server.   N)r   r   r   )r   	dest_addrCONNECTs      r   _negotiate_SOCKS5socksocket._negotiate_SOCKS5  s'    373G3G94&0T0r!   c                 R  > U R                   u  pEpgpUR                  S5      n
UR                  SS5      n U(       a  U	(       a  U
R                  S5        OU
R                  S5        U
R                  5         U R	                  US5      nUSS S:w  a  [        S	5      eUSS S
:X  a  U(       a  U	(       d  [        S5      eU
R                  S[        [        U5      5      R                  5       -   U-   [        [        U	5      5      R                  5       -   U	-   5        U
R                  5         U R	                  US5      nUSS S:w  a  [        S	5      eUSS S:w  a  [        S5      eO(USS S:w  a  USS S:X  a  [        S5      e[        S	5      eU
R                  SU-   S-   5        U R                  X:5      nU
R                  5         U R	                  US5      nUSS S:w  a  [        S	5      e[        USS 5      nUS:w  a1  [        R                  US5      n[        SR                  UU5      5      eU R!                  U5      n["        [$        U ]O  U R(                  5        UU4UR+                  5         U
R+                  5         $ ! UR+                  5         U
R+                  5         f = f)zy
Send SOCKS5 request with given command (CMD field) and
address (DST field). Returns resolved DST address that was used.
wbrbr   s    s    r   r      %SOCKS5 proxy server sent invalid data   zPNo username/password supplied. Server requested username/password authenticationr	  r   zSOCKS5 authentication failed   z7All offered SOCKS5 authentication methods were rejectedr
   Unknown error{:#04x}: {})r   makefiler   flushr   r8   r@   chrr   rS   r   r   SOCKS5_ERRORSgetrC   r(   r   r   rU   rs   r   rx   )r   conncmdr   rW   rX   rY   rZ   r[   r\   writerreaderchosen_authauth_statusresolvedrespstatusrw   bndr   s                      r   r   socksocket._SOCKS5_request  s   
 <@::8
$ht$tQ'W	H 01 _- LLN--2K1Q7* (;= =
 1Q7* !X * +< = = Ws3x='9'@'@'BB'("3x=188:;  (( ) "mmFA6q#w.+?A Aq#w.)*HII / Qq!W,q#w.)$% % ,?A A LL30111#>HLLN ==+DAayG#';= = a^F~%))&/B!-"6"6vu"EFF ++F3C*d.t}}=c?LLNLLN LLNLLNs   H-J "J&c                    Uu  p4U R                   u  n  pgp[        R                  S[        R                  S0n
[        R                  [        R                  4 Ho  n [        R                  " X5      nUR                  X   U-   5        [        R                  " X5      nUR                  [        R                  " SU5      5        X44s  $    U(       aI  UR                  S5      nUR                  S[        [        U5      5      R                  5       -   U-   5        O[        R                  " X4[        R                  [        R                  [        R                   [        R"                  5      nUS   nUS   nUS   S   n[        R                  " X5      nUR                  X   U-   5        [        R                  " X5      nUR                  [        R                  " SU5      5        X44$ ! [        R                   a     GM  f = f)zf
Return the host and port packed for the SOCKS5 protocol,
and the resolved address as a tuple object.
r	     >Hidnar   r   rM   )r   rf   AF_INETAF_INET6	inet_ptonr   	inet_ntopstructpackrw   rS   r  r   rm   	AF_UNSPECrn   IPPROTO_TCPAI_ADDRCONFIG)r   rX   r   r   rY   rW   r   rZ   r[   r\   family_to_byter   
addr_bytes
host_bytes	addressestarget_addrs                   r   r    socksocket._write_SOCKS5_address.  s   
 
59ZZ2
Aq ..'6??GL
 ~~v7F#--f;


>1J>?'';

6;;tT23z! 8 V,JJJwS_!5!<!<!>>KL **4v7G7G+1+=+=+1+=+=+1+?+?AI $A,K ^Fq>!$D))&7JJJ~-
:;##F7D

6;;tT*+z1 << s   A*G**HHc                    U R                  US5      nUS:X  a'  [        R                  " U R                  US5      5      nO{US:X  a.  U R                  US5      nU R                  U[        U5      5      nOGUS:X  a6  [        R                  " [        R
                  U R                  US5      5      nO[        S5      e[        R                  " SU R                  US	5      5      S
   nX54$ )Nr   r	  rM   r   r(     r  r)  r   r   )	r   rf   	inet_ntoar   r.  r,  r8   r/  unpack)r   r   atyprX   lengthrY   s         r   r   socksocket._read_SOCKS5_address[  s    }}T1%7?##DMM$$:;DW_]]4+F==s6{3DW_##FOOT]]45LMD#$KLL}}T4==q#9:1=zr!   c                    U R                   u  p4pVpxU R                  S5      n	U R                  SS5      n
 Sn [        R                  " U5      nU	R                  [        R                  " SSS	U5      5        U	R                  U5        U(       a  U	R                  U5        U	R                  S
5        U(       a#  U	R                  UR                  S5      S
-   5        U	R                  5         U R                  U
S5      nUSS	 S
:w  a  [        S5      e[        US	S 5      nUS:w  a0  [        R                  US5      n[!        SR#                  X5      5      e[        R$                  " USS 5      [        R&                  " SUSS 5      S   4U l        U(       a  [        R$                  " U5      U4U l        OX4U l        U
R-                  5         U	R-                  5         g! [        R                   a<    U(       a  SnSn GN[        R                  " [        R
                  " U5      5      n GNf = f! U
R-                  5         U	R-                  5         f = f)z0Negotiates a connection through a SOCKS4 server.r  r  r   Fs      Tz>BBHrM   r   r   r*  rQ   z%SOCKS4 proxy server sent invalid datar   Z   r  r  Nr)  )r   r  rf   	inet_atonrw   gethostbynamer   r/  r0  rS   r  r   r8   r   SOCKS4_ERRORSr  rF   r(   r<  r=  r   r   rx   )r   r
  	dest_portrW   rX   rY   rZ   r[   r\   r  r  remote_resolver5  r#  r$  rw   s                   r   _negotiate_SOCKS4socksocket._negotiate_SOCKS4j  s   ;?::8
$ht$tQ'4	"N	9#--i8
 LLVT4CDLL$ X&LL!
 Y--f5?@LLN ==+DAayG#';= = a^F~%))&/B!-"6"6v"EFF $*#3#3DH#=#)==tAay#A!#D#FD&,&6&6z&BI&M#&/&:#LLNLLN_ << 9!4J%)N!'!1!1,,Y7"9J9\ LLNLLNs;   H0 G E.H0 H-<H0 ?*H-)H0 ,H--H0 0"Ic                    U R                   u  p4pVpxU(       a  UO[        R                  " U5      nSUR                  S5      -   S-   [	        U5      R                  5       -   S-   SUR                  S5      -   /n	U(       a*  U(       a#  U	R                  S[        US-   U-   5      -   5        U	R                  S5        U R                  SR                  U	5      5        U R                  5       n
U
R                  5       nU
R                  5         U(       d  [        S5      e UR                  S	S
5      u  pnUR                  S5      (       d  [        S5      e [!        U5      nUS:w  a'  SR%                  X5      nUS;   a  US-  n[#        U5      eSU l        XB4U l        g! [         a    [        S5      ef = f! [         a    [#        S5      ef = f)zoNegotiates a connection through an HTTP server.

NOTE: This currently only supports HTTP CONNECT-style proxies.s   CONNECT r*     :s	    HTTP/1.1s   Host: s   Proxy-Authorization: basic s   
r    r   z'HTTP proxy server sent invalid responsezHTTP/z0Proxy server does not appear to be an HTTP proxyz4HTTP proxy server did not return a valid HTTP status   z{}: {})i  i  i  za
[*] Note: The HTTP proxy server may not be supported by PySocks (must be a CONNECT tunnel proxy))s   0.0.0.0r   N)r   rf   rD  rS   strappendr   sendalljoinr  readlinerx   r8   splitr   rk   rq   rI   r(   r   r   )r   r
  rF  rW   rX   rY   rZ   r[   r\   http_headersfobjstatus_liner   status_code
status_msgrw   s                   r   _negotiate_HTTPsocksocket._negotiate_HTTP  s    <@::8
$h !yf&:&:9&E 4;;v..59~$$&')56	((00
  >"+HtOh,F"G!H I 	G$W\\,/0 }}mmo

#$DEE	O-8->->sA-F*E
 ((#BD D	Hk*K
 #OOK<Eo-  $ % E""-"o1  	O#$MNN	O  	HFH H	Hs   F F5 F25Gc                 :  > [        U5      S:w  d  US   R                  S5      (       a"  [        R                  " S[	        U5      -  5      eUu  p4U R
                  [        R                  :X  aV  U R                  (       d  U R                  S5        [        R                  " U5      nUS:X  a  U(       d  SU l
        gX44U l
        gU R                  u  pVpxn	n
[        U[        [        45      (       a+  [        U5      S:w  d  U(       a  [        U[        5      (       d  [!        S5      e["        [$        U ]O  U R(                  5        Uc8  Xl
        ["        [$        U ]O  U R(                  5        ["        [$        U ]W  X445        gU R-                  5       n ["        [$        U ]W  U5         U R.                  U   nU" XU5        g! [        R                   a*  nU(       d  U R1                  5         [!        S	U5      eUeSnAf[2         a    U R1                  5         e f = f! [        R                   ao  nU R1                  5         U(       dQ  Uu  pgS
R5                  Xg5      n[6        U   nSR5                  UU5      n[8        R;                  SX5        [=        X5      eUeSnAff = f)z
Connects to the specified destination through a proxy.
Uses the same API as socket's connect().
To select the proxy server, use set_proxy().

dest_pair - 2-tuple of (IP/hostname, port).
r   r   rj   z PySocks doesn't support IPv6: %sr   r   Nz0Invalid destination-connection (host, port) pairzSocket errorz{}:{}zError connecting to {} proxy {}z%s due to: %s)r   rk   rf   rw   rN  r   r   r   ru   rD  r   r   rp   r   tuplerq   r8   r   rU   rs   r   rv   r   _proxy_negotiatorsrx   r#   r(   PRINTABLE_PROXY_TYPESlogdebugr=   )r   ry   catch_errorsr
  rF  rW   r|   r}   rZ   r[   r\   	negotiaterw   proxy_serverprintable_typer&   r   s                   r   rv   socksocket.connect  sL    y>Q)A,"9"9#">"> ,,A!$Y 0 1 1  )	99)))??		'",,Y7I I%i&*#  (1&<# ZZ	8	 9tUm44y>Q& !)S11#BD D
 	j$*4==9"+*d.t}}=*d+Y,BC%%'
#	*d+J7& 33J?	$95<<  #JJL+NEBBK 

9 || 	JJL)3&
&~~jE!6z!B7>>~DPR		/36*366	s1   H #F< <H%G55HJ+A*JJc                      U R                  USS9  g! [         a(  nUR                  (       a  UR                  s SnA$ e SnAff = f)a  https://docs.python.org/3/library/socket.html#socket.socket.connect_ex
Like connect(address), but return an error indicator instead of raising an exception for errors returned by the C-level connect() call (other problems, such as "host not found" can still raise exceptions).
T)ra  r   N)rv   OSErrorerrno)r   ry   r   s      r   
connect_exsocksocket.connect_exD  s?    
		LLL6 	 wwww	s    
AA AA  Ac                     U R                   u  pp4nnU=(       d    [        R                  U5      nU(       d  [        S5      eX#4$ )z4
Return proxy address to connect to as tuple object
zInvalid proxy type)r   DEFAULT_PORTSr  r8   )r   rW   r|   r}   rZ   r[   r\   s          r   r   socksocket._proxy_addrT  sF    
 ZZ	8	@=#4#4Z#@
#$899%%r!   )r   r   r   r   r   NNNTNN)r   r,   ),r0   r1   r2   r3   r4   rV   rf   r+  rn   r)   r   rs   r   r   rt   r   ru   r   r   r   r   rx   r   getproxysocknamer   getproxypeernamer  r  r  r   r   r   rH  rY  r   r   r   r]  r    rv   ri  r   r5   __classcell__)r   s   @r   rU   rU      s    M$nn63E3E$
! EI*.62/
#-J$(H9(/
# *" *# K&`D+Z:x9.x "#4!#4 Z Zx  	& 	&r!   rU   rn  )	NNNNNTNNN)Hbase64r   sixPY2collectionscollections_abccollections.abcabcrh  r   r   r   r   ior   loggingosr   rf   r/  sys__version__r   version_infowin_inet_ptonImportError	getLoggerr0   r_  PROXY_TYPE_SOCKS4r   PROXY_TYPE_SOCKS5r   PROXY_TYPE_HTTPr   PROXY_TYPESr   zipvalueskeysr^  
_orgsocketr   r    IOErrorr#   r8   r=   r@   rC   rF   rI   rE  r  rl  r]   rb   rd   getdefaultproxyrh   
wrapmoduler   r   r   r   methodrp   Callabler   rO  setattrrU   r6   r!   r   <module>r     sT    
77' , , ,    	    
 77d?s''&0H
 !  F  F $64@S!3!3!5{7G7G7IJK "MM )
\&
 
	
 		: 		j 		* 		* 		
 	 '!	 )
-




4
&	 vtT48 CG.2@.$ $	> 
 482626:>%):3z
&-- 
I2D[$-F fo6677%%d+T;t#45 3b	& b	&  HFH 	HHs   8G G+