
    @OOf                         d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d d	l
mZ  G d
 de      ZdedefdZ G d d      Zy)    )Sequence)
NamedTuple)ctx)
exceptions)
flowfilter)http)version)NO_RESPONSE)	RESPONSESc                   6    e Zd ZU ej                  ed<   eed<   y)	BlockSpecmatchesstatus_codeN)__name__
__module____qualname__r   TFilter__annotations__int     [/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/addons/blocklist.pyr   r      s    r   r   optionreturnc                 j   | d   | dd }}|j                         j                  |d      }t        |      dk7  rt        d      |\  }}	 t	        |      }t        j                  |      }t        j                  |      st        d|       t        ||      S # t        $ r t        d|       w xY w)zl
    Parses strings in the following format, enforces number of segments:

        /flow-filter/status

    r      N   z-Invalid number of parameters (2 are expected)zInvalid HTTP status code: )r   r   )
lowersplitlen
ValueErrorr   r   parser   getr   )r   sepremparts	flow_pattstatusr   flow_filters           r   
parse_specr*      s     ay&*CIIKc1%E
5zQHIIIv@&k ""9-K==%5fX>??[kBB  @5fX>??@s   
B B2c                   D    e Zd ZddZd Zd Zdej                  ddfdZy)		BlockListr   Nc                     g | _         y )N)items)selfs    r   __init__zBlockList.__init__+   s	    &(
r   c                 B    |j                  dt        t           g d       y )N
block_lista  
            Block matching requests and return an empty response with the specified HTTP status.
            Option syntax is "/flow-filter/status-code", where flow-filter describes
            which requests this rule should be applied to and status-code is the HTTP status code to return for
            blocked requests. The separator ("/" in the example) can be any character.
            Setting a non-standard status code of 444 will close the connection without sending a response.
            )
add_optionr   str)r/   loaders     r   loadzBlockList.load.   s"    SM		
r   c                    d|v rNg | _         t        j                  j                  D ])  }	 t	        |      }| j                   j                  |       + y y # t
        $ r!}t        j                  d| d|       |d }~ww xY w)Nr2   zCannot parse block_list option z: )	r.   r   optionsr2   r*   r!   r   OptionsErrorappend)r/   updatedr   speces        r   	configurezBlockList.configure<   s    7"DJ++00 (%f-D
 

!!$'( #
 " $119&A3Gs   A	A>A99A>flowc                 z   |j                   s|j                  s|j                  sy | j                  D ]  }|j	                  |      sd|j
                  d<   |j                  t        k(  r|j                          Ht        j                  j                  |j                  dt        j                  i      |_          y )NTblocklistedServer)headers)responseerrorliver.   r   metadatar   r
   killr   Responsemaker	   	MITMPROXY)r/   r?   r<   s      r   requestzBlockList.requestH   s    ==DJJdiiJJ 	D||D!/3m,##{2IIK$(MM$6$6((8W=N=N2O %7 %DM	r   )r   N)	r   r   r   r0   r6   r>   r   HTTPFlowrL   r   r   r   r,   r,   *   s(    )

(DMM d r   r,   N)collections.abcr   typingr   	mitmproxyr   r   r   r   r	   mitmproxy.net.http.status_codesr
   r   r   r4   r*   r,   r   r   r   <module>rR      sL    $         7 5
 
Cs Cy C0* *r   