
    ^i                     2   S SK r S SKrSSKJr  SSKJrJr  SSKJrJ	r	J
r
Jr   " S S\\ R                  5      r " S S	\\ R                  5      r " S
 S\R                   5      r " S S\R                   5      r " S S\R                   5      r " S S5      rg)    N   )
StrOrBytes)ProtocolError
SOCKSError)AddressTypedecode_addressencode_address#get_address_port_tuple_from_addressc                   (    \ rS rSrSrSrSrSrSrSr	g)	SOCKS4ReplyCode   z"Enumeration of SOCKS4 reply codes.   Z   [   \   ] N)
__name__
__module____qualname____firstlineno____doc__REQUEST_GRANTEDREQUEST_REJECTED_OR_FAILEDCONNECTION_FAILEDAUTHENTICATION_FAILED__static_attributes__r       H/home/james-whalen/.local/lib/python3.13/site-packages/socksio/socks4.pyr   r      s    ,O!(#r   r   c                        \ rS rSrSrSrSrSrg)SOCKS4Command   z$Enumeration of SOCKS4 command codes.      r   N)r   r   r   r   r   CONNECTBINDr   r   r   r   r    r       s    .GDr   r    c            
          \ rS rSr% Sr\\S'   \\S'   \\S'   Sr	\
R                  \   \S'   \ SS\S\
R                  \\
R                  \\4   4   S\
R                  \   S	S 4S
 jj5       rSS\
R                  \   S	\4S jjrSrg)SOCKS4Request   aN  Encapsulates a request to the SOCKS4 proxy server

Args:
    command: The command to request.
    port: The port number to connect to on the target host.
    addr: IP address of the target host.
    user_id: Optional user ID to be included in the request, if not supplied
        the user *must* provide one in the packing operation.
commandportaddrNuser_idaddressreturnc                     [        U5      u  p$[        U5      u  pVU[        R                  :w  a  [	        S5      eU " XXCS9$ )aj  Convenience class method to build an instance from command and address.

Args:
    command: The command to request.
    address: A string in the form 'HOST:PORT' or a tuple of ip address string
        and port number.
    user_id: Optional user ID.

Returns:
    A SOCKS4Request instance.

Raises:
    SOCKSError: If a domain name or IPv6 address was supplied.
z;IPv6 addresses and domain names are not supported by SOCKS4r)   r+   r*   r,   )r
   r	   r   IPV4r   clsr)   r-   r,   r*   atypeencoded_addrs          r   from_addressSOCKS4Request.from_address.   sJ    * <GD,W5K$$$M  7DRRr   c           	          U=(       d    U R                   nUc  [        S5      eSR                  SU R                  U R                  R                  SSS9U R                  US/5      $ )Z  Packs the instance into a raw binary in the appropriate form.

Args:
    user_id: Optional user ID as an override, if not provided the instance's
        will be used, if none was provided at initialization an error is raised.

Returns:
    The packed request.

Raises:
    SOCKSError: If no user was specified in this call or on initialization.
-SOCKS4 requires a user_id, none was specifiedr         big	byteorder    r,   r   joinr)   r*   to_bytesr+   selfr,   s     r   dumpsSOCKS4Request.dumpsK   sg     )T\\?LMMxx$$Q%$8			
 		
r   r   Nr   r   r   r   r   r    __annotations__intbytesr,   typingOptionalclassmethodUnionr   Tupler6   rF   r   r   r   r   r'   r'      s     
I
K&*GV__U#*
 +/	SS j&,,z3*GGHS '	S
 
S S8
V__U3 
u 
 
r   r'   c            
          \ rS rSr% Sr\\S'   \\S'   \\S'   Sr	\
R                  \   \S'   \ SS\S\
R                  \\
R                  \\4   4   S\
R                  \   S	S 4S
 jj5       rSS\
R                  \   S	\4S jjrSrg)SOCKS4ARequesth   aO  Encapsulates a request to the SOCKS4A proxy server

Args:
    command: The command to request.
    port: The port number to connect to on the target host.
    addr: IP address of the target host.
    user_id: Optional user ID to be included in the request, if not supplied
        the user *must* provide one in the packing operation.
r)   r*   r+   Nr,   r-   r.   c                 D    [        U5      u  p$[        U5      u  pVU " XXCS9$ )a#  Convenience class method to build an instance from command and address.

Args:
    command: The command to request.
    address: A string in the form 'HOST:PORT' or a tuple of ip address string
        and port number.
    user_id: Optional user ID.

Returns:
    A SOCKS4ARequest instance.
r0   )r
   r	   r2   s          r   r6   SOCKS4ARequest.from_addressx   s*    $ <GD,W57DRRr   c           
          U=(       d    U R                   nUc  [        S5      eSR                  SU R                  U R                  R                  SSS9SUSU R                  S/5      $ )	r9   r:   r   r;   r<   r=   r>   s      r@   rA   rD   s     r   rF   SOCKS4ARequest.dumps   sm     )T\\?LMMxx$$Q%$8#			
 	
r   r   rH   rI   r   r   r   rS   rS   h   s     
I
K&*GV__U#*
 +/	SS j&,,z3*GGHS '	S
 
S S*
V__U3 
u 
 
r   rS   c                   n    \ rS rSr% Sr\\S'   \\S'   \R                  \
   \S'   \S\SS 4S j5       rS	rg
)SOCKS4Reply   zEncapsulates a reply from the SOCKS4 proxy server

Args:
    reply_code: The code representing the type of reply.
    port: The port number returned.
    addr: Optional IP address returned.

reply_coder*   r+   datar.   c           
         [        U5      S:w  d	  USS S:w  a  [        S5      e U " [        USS 5      [        R	                  USS SS	9[        [        R                  USS 5      S
9$ ! [         a  n[        S5      UeSnAff = f)zUnpacks the reply data into an instance.

Returns:
    The unpacked reply instance.

Raises:
    ProtocolError: If the data does not match the spec.
   r   r   r@   zMalformed replyr<      r=   r>   )r\   r*   r+   N)	lenr   r   rK   
from_bytesr   r   r1   
ValueError)r3   r]   excs      r   loadsSOCKS4Reply.loads   s     t9>T!AY'1 122	<*4!95^^D1I^?#K$4$4d1Qi@ 
  	< 12;	<s   AA) )
B3A??Br   N)r   r   r   r   r   r   rJ   rK   rM   rN   strrO   rL   re   r   r   r   r   rZ   rZ      sC      
I
//#
< <= < <r   rZ   c                   v    \ rS rSrSrS\4S jrS\R                  \	\
4   SS4S jrS	\S\4S
 jrS\4S jrSrg)SOCKS4Connection   zEncapsulates a SOCKS4 and SOCKS4A connection.

Packs request objects into data suitable to be send and unpacks reply
data into their appropriate reply objects.

Args:
    user_id: The user ID to be sent as part of the requests.
r,   c                 L    Xl         [        5       U l        [        5       U l        g rH   )r,   	bytearray_data_to_send_received_datarD   s     r   __init__SOCKS4Connection.__init__   s    &['kr   requestr.   Nc                     UR                   =(       d    U R                   nU =R                  UR                  US9-  sl        g)zsPacks a request object and adds it to the send data buffer.

Args:
    request: The request instance to be packed.
)r,   N)r,   rm   rF   )rE   rq   r,   s      r   sendSOCKS4Connection.send   s2     //1T\\gmmGm<<r   r]   c                 |    U =R                   U-  sl         [        R                  [        U R                   5      5      $ )zUnpacks response data into a reply object.

Args:
    data: The raw response data from the proxy server.

Returns:
    The appropriate reply object.
)rn   rZ   re   rL   rE   r]   s     r   receive_dataSOCKS4Connection.receive_data   s1     	t#  t':':!;<<r   c                 N    [        U R                  5      n[        5       U l        U$ )zaReturns the data to be sent via the I/O library of choice.

Also clears the connection's buffer.
)rL   rm   rl   rv   s     r   data_to_sendSOCKS4Connection.data_to_send   s#    
 T''(&[r   )rm   rn   r,   )r   r   r   r   r   rL   ro   rM   rP   r'   rS   rs   rZ   rw   rz   r   r   r   r   ri   ri      sS    * *=FLL)FG =D =
= 
=; 
=e r   ri   )enumrM   _typesr   
exceptionsr   r   utilsr   r   r	   r
   rL   Enumr   r    
NamedTupler'   rS   rZ   ri   r   r   r   <module>r      s       1 $eTYY $E499 G
F%% G
TB
V&& B
J!<&## !<H, ,r   