
    @OOf                        U d Z ddl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 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 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  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 Z(e)e!   e*d&<   d'e!d(dfd)Z+ e&jX                  e+      Z-	  e&jX                  e+      Z.	 d*e/d(e!dz  fd+Z0d'e!d(dfd,Z1d'e!d(dfd-Z2d<d.Z3d/e/d0e$jh                  ez  ez  ez  d1e#jj                  fd2Z6dddddd3d4e!d5e7d6e/dz  d1e#jj                  dz  d7e$jh                  dz  d8ej                  dz  d9ej
                  dz  fd:Z8 e1 e	jr                                 e1 ejt                                 e1 ejv                                 e1 ejx                                 e1 ejz                                 e1 ej|                                 e1 ej~                                 e1 ej                                 e1 ej                                 e1 e
j                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                 e1 ej                                g d;ZMy)=a  
Mitmproxy Content Views
=======================

mitmproxy includes a set of content views which can be used to
format/decode/highlight data. While they are mostly used for HTTP message
bodies, the may be used in other contexts, e.g. to decode WebSocket messages.

Thus, the View API is very minimalistic. The only arguments are `data` and
`**metadata`, where `data` is the actual content (as bytes). The contents on
metadata depend on the protocol in use. Known attributes can be found in
`base.View`.
    N   )
TCPMessage)
UDPMessage)WebSocketMessage   )auto)css)dns)graphql)grpc)hex)http3)image)
javascript)json)mqtt)msgpack)	multipart)protobuf)query)raw)
urlencoded)wbxml)xml_html)format_dict)format_text)KEY_MAX)TViewResult)View)flow)http)tcp)udp)signals)strutilsviewsviewreturnc                      y N r'   s    `/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/mitmproxy/contentviews/__init__.py_updater.   6   s        namec                 x    t         D ]1  }|j                  j                         | j                         k(  s/|c S  y r*   )r&   r0   lower)r0   is     r-   getr4   ?   s3     66<<>TZZ\)H r/   c                     t         D ]3  }|j                  | j                  k(  st        d| j                  z          t         j                  |        t        j                  |        y )NzDuplicate view: )r&   r0   
ValueErrorappendon_addsend)r'   r3   s     r-   addr:   F   sP     =66TYY/$));<<= 
LL
KKr/   c                 X    t         j                  |        t        j                  |        y r*   )r&   remove	on_remover9   r,   s    r-   r<   r<   P   s    	LLNN4r/   c              #      K   | D ]\  }g }|D ]O  \  }}t        |t              r|j                  |d      }t        j                  |      }|j                  ||f       Q | ^ yw)zb
    Wraps a content generator so that each text portion is a *safe to print* unicode string.
    replaceN)
isinstancebytesdecoder%   escape_control_charactersr7   )linesencodingline
clean_linestyletexts         r-   safe_to_printrJ   U   ss       
 	-KE4$&{{8Y755d;Dudm,		-
 s   A#A%viewnamemessager    c           	         t        |       }|st        d      }|sJ 	 |j                  }t        |t        j                        r:||j
                  k7  r+dj                  |j                  j                  d            }nd}	 |dt        dgg      dfS d}d}t        |t        j                        rC|}|j                  j                  d      x}r$t        j                  |      x}	r|	d	    d
|	d    }d}
t        |t              r|}
d}t        |t              r|}t        ||||||
|      \  }}}|r| d| }|||fS # t        $ r- t        |t        j                        sJ |j
                  }d}Y w xY w)zC
    Like get_content_view, but also handles message encoding.
    r   z[decoded {}]zcontent-encoding z[cannot decode]N)errorzcontent missingzcontent-typer   /r   content_typer    http_messagetcp_messageudp_message )r4   contentr@   r!   Messageraw_contentformatheadersr6   iterparse_content_typer   r   get_content_view)rK   rL   r    viewmoderW   encrR   rS   ctypectrT   rU   descriptionrD   rO   s                  r-   get_message_content_viewrd   c   s    8}Hv;O8
// gt||,G<O<O1O ''(;(;<N(OPCC467894??LL'4<<(OO''7757,,U33r3"$Q%"Q%1K':&K':& 0!!!K Q{m,u$$U   '4<<000%% s   E   3E65E6rQ   r_   datarR   rS   rT   rU   c          	      .   	  | ||||||      }|d t        d      ||||||      d   f}|\  }}	d}
|t        |	      |
fS # t        $ rH d}t        d      }|sJ  |||||||      d   }	t        | d       dt        j                          }
Y ^w xY w)a  
    Args:
        viewmode: the view to use.
        data, **metadata: arguments passed to View instance.

    Returns:
        A (description, content generator, error) tuple.
        If the content view raised an exception generating the view,
        the exception is returned in error and the flow is formatted in raw mode.
        In contrast to calling the views directly, text is always safe-to-print unicode.
    rQ   Nz#Couldn't parse: falling back to RawRawr   r0   z content viewer failed: 
)r4   	Exceptiongetattr	traceback
format_excrJ   )r_   re   rR   r    rS   rT   rU   retdescrW   rO   r   s               r-   r^   r^      s    *$a%%##
 ;5E
!-!- + + 
C g  w'..  a4%j
s%%##
  8V,--G	H\H\H^G_`as   3A ABB)
r   r   r   r   r   r4   r:   r<   r^   rd   )utf8)N__doc__rj   r"   r   r#   r   	websocketr   rN   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   baser   r   r   r   r   	mitmproxyr    r!   mitmproxy.utilsr$   r%   r&   list__annotations__r.   
SyncSignalr8   r=   strr4   r:   r<   rJ   rX   Flowrd   rA   r^   ViewAutoViewRawViewHexStreamViewHexDumpViewGraphQLViewJSONViewXmlHtml	ViewWBXMLViewJavaScriptViewCSSViewURLEncodedViewMultipart	ViewImage	ViewQueryViewProtobufViewMsgPackViewGrpcProtobufViewMQTT	ViewHttp3ViewDns__all__r+   r/   r-   <module>r      s(      (                             # $tDz  %$ $4 $ 
		G	$ 'Gw'	 %c dTk d t  $ 
:%:%\\J&36FF:% )):%B  $!(,)-)-;/;/
;/ *	;/
 ))d
;/ ,,%;/ $&;/ $&;/~ MDMMO  KCKKM  C  OCOO  G  MDMMO  H  OEOO  J   KCKKM  J   I  OEOO  OEOO  H  G  D  MDMMO  OEOO  KCKKM r/   