
    kjE                     6    d Z ddlZddlmZ d Z G d d      Zy)z3
Utility decorators that help build state machines
    N)eventsc                        fd}|S )zg
    Only allow the given event type.
    If another event is passed, an AssertionError is raised.
    c                 t     ddu r1t        j                         dt        j                  f fd       }|S  S )NTeventc           	          t        |      r	 | |      S dj                  d D              xs d}t        dj                   d| d| d      )N|c              3   4   K   | ]  }|j                     y wN)__name__).0es     ^/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/mitmproxy/proxy/utils.py	<genexpr>zGexpect.<locals>.decorator.<locals>._check_event_type.<locals>.<genexpr>   s      A As   z	no eventszUnexpected event type at z: Expected z, got .)
isinstancejoinAssertionError__qualname__)selfr   event_types_strevent_typesfs      r   _check_event_typez4expect.<locals>.decorator.<locals>._check_event_type   sl    e[1T5>)  A[ AAP[ $ )3ANN3C D$$3#4F5'D     )	functoolswrapsr   Event)r   r   r   s   ` r   	decoratorzexpect.<locals>.decorator   s>    __Q
v|| 
  
 %$Hr    )r   r   s   ` r   expectr    
   s    ( r   c                   V    e Zd ZU dZee   ed<   eed<   d ZdefdZ	d Z
d Zd	 Zd
 Zy)ReceiveBufferzJ
    A data structure to collect stream contents efficiently in O(n).
    _chunks_lenc                      g | _         d| _        y Nr   )r#   r$   r   s    r   __init__zReceiveBuffer.__init__/   s    	r   otherc                     t        |t              sJ | j                  j                  |       | xj                  t        |      z  c_        | S r
   )r   bytesr#   appendr$   len)r   r)   s     r   __iadd__zReceiveBuffer.__iadd__3   s;    %'''E"		SZ	r   c                     | j                   S r
   r$   r'   s    r   __len__zReceiveBuffer.__len__9   s    yyr   c                 8    dj                  | j                        S )Nr   )r   r#   r'   s    r   	__bytes__zReceiveBuffer.__bytes__<   s    xx%%r   c                      | j                   dkD  S r&   r0   r'   s    r   __bool__zReceiveBuffer.__bool__?   s    yy1}r   c                 F    | j                   j                          d| _        y r&   )r#   clearr$   r'   s    r   r7   zReceiveBuffer.clearB   s    	r   N)r   
__module__r   __doc__listr+   __annotations__intr(   r.   r1   r3   r5   r7   r   r   r   r"   r"   '   s=     %[
Ie &r   r"   )r9   r   mitmproxy.proxyr   r    r"   r   r   r   <module>r>      s!     ": r   