
    @OOf                     J   d Z ddlZddlZddlmZ ddlmZ ddlZddlm	Z	 ddlm
Z
 erddlZ G d d      Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d deej&                  j(                        Z G d de      Zy)a&  
Commands make it possible for layers to communicate with the "outer world",
e.g. to perform IO or to ask the master.
A command is issued by a proxy layer and is then passed upwards to the proxy server, and from there
possibly to the master and addons.

The counterpart to commands are events.
    N)TYPE_CHECKING)Union)
Connection)Serverc                   2    e Zd ZU dZdZeedf   ed<   	 d Zy)Commandz%
    Base class for all commands
    Fzmitmproxy.proxy.layer.Layerblockingc                     | j                   j                         }|j                  dd        t        |       j                   dt        |       dS )Nr	   ())__dict__copypoptype__name__repr)selfxs     Y/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/proxy/commands.py__repr__zCommand.__repr__)   sD    MM 	j$t*%%&aQy22    N)	r   
__module____qualname____doc__r	   r   bool__annotations__r    r   r   r   r      s)     <AHeD778@
3r   r   c                   (    e Zd ZU dZeed<   defdZy)RequestWakeupzI
    Request a `Wakeup` event after the specified amount of seconds.
    delayc                     || _         y N)r    )r   r    s     r   __init__zRequestWakeup.__init__6   s	    
r   N)r   r   r   r   floatr   r#   r   r   r   r   r   /   s     Le r   r   c                   (    e Zd ZU dZeed<   defdZy)ConnectionCommandz2
    Commands involving a specific connection
    
connectionc                     || _         y r"   )r'   )r   r'   s     r   r#   zConnectionCommand.__init__A   s	    $r   N)r   r   r   r   r   r   r#   r   r   r   r&   r&   :   s     %: %r   r&   c                   >     e Zd ZU dZeed<   dedef fdZd Z xZ	S )SendDataz$
    Send data to a remote peer
    datar'   c                 2    t         |   |       || _        y r"   )superr#   r+   )r   r'   r+   	__class__s      r   r#   zSendData.__init__L   s    $	r   c                     t        | j                        j                  dd      d   j                         }d| d| j                  dS )Nr      r   z	SendData(, r   )strr'   splitlowerr+   )r   targets     r   r   zSendData.__repr__P   sD    T__%++C3A6<<>6("TYYM33r   )
r   r   r   r   bytesr   r   r#   r   __classcell__r.   s   @r   r*   r*   E   s'     K: U 4r   r*   c                        e Zd ZU dZeed<   dZy)OpenConnectionz
    Open a new connection
    r'   TN)r   r   r   r   r   r   r	   r   r   r   r:   r:   U   s     Hr   r:   c                       e Zd ZdZy)CloseConnectionz
    Close a connection. If the client connection is closed,
    all other connections will ultimately be closed during cleanup.
    N)r   r   r   r   r   r   r   r<   r<   ^   s    r   r<   c                   8     e Zd ZU eed<   	 ddedef fdZ xZS )CloseTcpConnection
half_closer'   c                 2    t         |   |       || _        y r"   )r-   r#   r?   )r   r'   r?   r.   s      r   r#   zCloseTcpConnection.__init__m   s    $$r   )F)r   r   r   r   r   r   r#   r7   r8   s   @r   r>   r>   e   s&    %: %4 % %r   r>   c                   *     e Zd ZdZdZdZ fdZ xZS )	StartHookz
    Start an event hook in the mitmproxy core.
    This triggers a particular function (derived from the class name) in all addons.
     Tc                 P    | t         u rt        d      t        |   | g|i |S )Nz+StartHook may not be instantiated directly.)rB   	TypeErrorr-   __new__)clsargskwargsr.   s      r   rF   zStartHook.__new__{   s0    )IJJws4T4V44r   )r   r   r   r   namer	   rF   r7   r8   s   @r   rB   rB   r   s    
 DH5 5r   rB   c                   T    e Zd ZU dZeed<   eed<   ej                  fdedefdZ	d Z
y)Loga  
    Log a message.

    Layers could technically call `logging.log` directly, but the use of a command allows us to
    write more expressive playbook tests. Put differently, by using commands we can assert that
    a specific log message is a direct consequence of a particular I/O event.
    This could also be implemented with some more playbook magic in the future,
    but for now we keep the current approach as the fully sans-io one.
    messagelevelc                     t        |t              r:t        j                  dt        d       t        t        |j                               }|| _        || _	        y )Nz>commands.Log() now expects an integer log level, not a string.   )
stacklevel)

isinstancer2   warningswarnDeprecationWarninggetattrloggingupperrM   rN   )r   rM   rN   s      r   r#   zLog.__init__   sE    
 eS!MMP"
 GU[[]3E
r   c                 ~    d| j                   dt        j                  | j                        j	                          dS )NzLog(r1   r   )rM   rW   getLevelNamerN   r4   )r   s    r   r   zLog.__repr__   s6    dll%R(<(<TZZ(H(N(N(P'QQRSSr   N)r   r   r   r   r2   r   intrW   INFOr#   r   r   r   r   rL   rL      s9     LJ
 \\ Tr   rL   )r   rW   rS   typingr   r   mitmproxy.hooks	mitmproxymitmproxy.connectionr   r   mitmproxy.proxy.layerr   r   r&   r*   r:   r<   r>   hooksHookrB   rL   r   r   r   <module>rd      s          + ' 3 30G % %4  4 & ' 
% 
%5-- 5T' Tr   