
    kjb                     X   d dl Z d dlZd dlZd dlm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  ej<                  e      Z g dZ!g dZ"g dZ# G d d      Z$y)    N)Sequence)command)command_lexer)contentviews)ctx)dns)
exceptionsflow)http)log)tcp)udp)ContentviewMessage)CommandError)ALERT)keymap)overlay)signals)strutils)lowlightlowdarklightdarksolarized_lightsolarized_darksinglevertical
horizontal)defaulttablelistc                      e Zd ZdZd Zd Z ej                  d      dee   fd       Z	 ej                  d      dzd	       Z
 ej                  d
      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d      dzd       Z ej                  d       dzd!       Z ej                  d"      dzd#       Z ej                  d$      d%ed&ee   d'ej2                  j4                  d(ej2                  j6                  ddf
d)       Z ej                  d*      d%ed+ej2                  j4                  d,ej2                  j4                  d(ej2                  j6                  ddf
d-       Z ej                  d.      d/eddfd0       Z ej                  d1      d%ed'ej2                  j4                  d(ej2                  j6                  ddfd2       Z ej                  d3      d4eddfd5       Z  ej                  d6      dzd7       Z! ej                  d8      dzd9       Z" ej                  d:      dzd;       Z# ej                  d<      dzd=       Z$ ej                  d>      dzd?       Z% ej                  d@      dAe&jN                  ddfdB       Z( ej                  dC      dzdD       Z) ej                  dE      dzdF       Z* ej                  dG       ejV                  dHej2                  jY                  dI      J      dAe&jN                  dHeddfdK              Z- ej                  dI      dee   fdL       Z. ej                  dM      dee   fdN       Z/ ej                  dO       ejV                  dPej2                  jY                  dM      J      dPeddfdQ              Z0dR Z1 ej                  dS      dzdT       Z2 ej                  dU      dzdV       Z3 ej                  dW      dzdX       Z4 ej                  dY      dZej2                  jj                  ddfd[       Z6 ej                  d\      dZej2                  jj                  ddfd]       Z7 ej                  d^      dZej2                  jj                  ddfd_       Z8 ej                  d`      dzda       Z9 ej                  db       ejV                  dcej2                  jY                  dd      J      dceddfde              Z: ej                  dd      dee   fdf       Z; ej                  dg      defdh       Z< ej                  di      dee   fdj       Z= ej                  dk      dlee   dmed'ej2                  j4                  d(ej2                  j6                  ddf
dn       Z> ej                  do      dlee   dmeddfdp       Z?dq Z@ ej                  dr      dzds       ZA ej                  dt      dzdu       ZB ej                  dv      dzdw       ZCdx ZDdzdyZEy){ConsoleAddonz^
    An addon that exposes console-specific commands, and hooks into required
    events.
    c                      || _         d| _        y )NF)masterstarted)selfr'   s     n/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/mitmproxy/tools/console/consoleaddons.py__init__zConsoleAddon.__init__4   s        c           	         |j                  dt        ddt        j                  j	                                |j                  dt        ddt
        j                         |j                  dt        d	d
t        t                     |j                  dt        dd       |j                  dt        dd       |j                  dt        ddt        t                     |j                  dt        dd       |j                  dt        dd       |j                  dt        ddt        t                     |j                  dt        dd       |j                  dt        dd       y )Nconsole_default_contentviewautozThe default content view mode.)choicesconsole_eventlog_verbosityinfozEventLog verbosity.console_layoutr   zConsole layout.console_layout_headersTzShow layout component headersconsole_focus_followFzFocus follows new flows.console_paletter   zColor palette.console_palette_transparentz'Set transparent background for palette.console_mousezConsole mouse interaction.console_flowlist_layoutr!   zSet the flowlist layoutconsole_strip_trailing_newlinesz<Strip trailing newlines from edited request/response bodies.console_quickhelp_visiblez5Show the quick help bar at the bottom of the console.)
add_optionstrr   registryavailable_viewsr   	LogLevelssortedconsole_layoutsboolconsole_palettesr9   )r)   loaders     r*   loadzConsoleAddon.load8   sw   ), ))99; 	 	
 	(!MM 	 	
 	?+ 	 	
 	$+		
 	"D%1K	
 	+, 	 	
 	)5		
 	/47ST%%23 	 	
 	-J		
 	'C		
r,   zconsole.layout.optionsreturnc                 
    g dS )zN
        Returns the available options for the console_layout option.
        r    r)   s    r*   layout_optionszConsoleAddon.layout_optionsy   s
    
 43r,   zconsole.layout.cycleNc                     | j                         }| j                         j                  t        j                  j                        }t        j                  j                  ||dz   t        |      z            y)z;
        Cycle through the console layout options.
           )r3   N)rK   indexr   optionsr3   updatelen)r)   optsoffs      r*   layout_cyclezConsoleAddon.layout_cycle   s\    
 ""$!!#))#++*D*DE$a3t9/D*EFr,   zconsole.panes.nextc                 L    | j                   j                  j                          y)z-
        Go to the next layout pane.
        N)r'   windowswitchrJ   s    r*   
panes_nextzConsoleAddon.panes_next   s    
 	!!#r,   zconsole.panes.prevc                 "    | j                         S )z1
        Go to the previous layout pane.
        )rX   rJ   s    r*   
panes_prevzConsoleAddon.panes_prev   s    
   r,   zconsole.options.reset.focusc                     | j                   j                  j                  d      }|st        j                  d      | j                   j
                  j                  d|j                         g       y)zA
        Reset the current option in the options editor.
        rO   zNot viewing options.zoptions.reset.oneN)r'   rV   currentr	   r   commandscall_stringscurrent_name)r)   fvs     r*   options_reset_currentz"ConsoleAddon.options_reset_current   sX    
 [[''	2))*@AA))*=@Q?RSr,   zconsole.nav.startc                 :    | j                   j                  d       y)z:
        Go to the start of a list or scrollable.
        m_startNr'   
inject_keyrJ   s    r*   	nav_startzConsoleAddon.nav_start       
 	y)r,   zconsole.nav.endc                 :    | j                   j                  d       y)z8
        Go to the end of a list or scrollable.
        m_endNrd   rJ   s    r*   nav_endzConsoleAddon.nav_end       
 	w'r,   zconsole.nav.nextc                 :    | j                   j                  d       y)z2
        Go to the next navigatable item.
        m_nextNrd   rJ   s    r*   nav_nextzConsoleAddon.nav_next   s    
 	x(r,   zconsole.nav.selectc                 :    | j                   j                  d       y)zA
        Select a navigable item for viewing or editing.
        m_selectNrd   rJ   s    r*   
nav_selectzConsoleAddon.nav_select   s    
 	z*r,   zconsole.nav.upc                 :    | j                   j                  d       y)
        Go up.
        upNrd   rJ   s    r*   nav_upzConsoleAddon.nav_up   s    
 	t$r,   zconsole.nav.downc                 :    | j                   j                  d       y)
        Go down.
        downNrd   rJ   s    r*   nav_downzConsoleAddon.nav_down       
 	v&r,   zconsole.nav.pageupc                 :    | j                   j                  d       y)rs   zpage upNrd   rJ   s    r*   
nav_pageupzConsoleAddon.nav_pageup   rg   r,   zconsole.nav.pagedownc                 :    | j                   j                  d       y)rw   z	page downNrd   rJ   s    r*   nav_pagedownzConsoleAddon.nav_pagedown   s    
 	{+r,   zconsole.nav.leftc                 :    | j                   j                  d       y)z
        Go left.
        leftNrd   rJ   s    r*   nav_leftzConsoleAddon.nav_left   rz   r,   zconsole.nav.rightc                 :    | j                   j                  d       y)z
        Go right.
        rightNrd   rJ   s    r*   	nav_rightzConsoleAddon.nav_right   rk   r,   zconsole.choosepromptr0   cmdargsc           	            fd} j                   j                  t        j                   j                   ||d|             y)z
        Prompt the user to choose from a specified list of strings, then
        invoke another command with all occurrences of {choice} replaced by
        the choice the user made.
        c                    D cg c]  }|j                  d|        }}	 j                  j                  j                  |       y c c}w # t        j
                  $ r(}t        j                  t        |             Y d }~y d }~ww xY wNz{choice}	replacer'   r]   r^   r	   r   loggererrorr=   )optargrepler   r   r)   s       r*   callbackz-ConsoleAddon.console_choose.<locals>.callback   sq    <@ASCKK
C0ADA%$$11#t< B ** %SV$$%   A	&A B	!BB	 N)r'   r   Chooser)r)   r   r0   r   r   r   s   `  `` r*   console_choosezConsoleAddon.console_choose   s1    	% 	GOODKK"hWXr,   zconsole.choose.cmd	choicecmdsubcmdc           	           t         j                  j                  j                  |      } fd} j                  j	                  t	        j
                   j                  ||d|             y)z
        Prompt the user to choose from a list of strings returned by a
        command, then invoke another command with all occurrences of {choice}
        replaced by the choice the user made.
        c                    D cg c]  }|j                  d|        }}	 j                  j                  j                  |       y c c}w # t        j
                  $ r(}t        j                  t        |             Y d }~y d }~ww xY wr   r   )r   r   r   r   r   r)   r   s       r*   r   z1ConsoleAddon.console_choose_cmd.<locals>.callback  sq    <@ASCKK
C0ADA%$$11&$? B ** %SV$$%r   r   N)r   r'   r]   executer   r   )r)   r   r   r   r   r0   r   s   `  ``  r*   console_choose_cmdzConsoleAddon.console_choose_cmd   sM     **%%--i8	% 	GOODKK"hWXr,   console.commandcommand_strc                     dj                  d |D              }|r|dz  }t        j                  j                  |       y)z[
        Prompt the user to edit a command with a (possibly empty) starting value.
         c              3   F   K   | ]  }t        j                  |        y w)N)r   quote).0xs     r*   	<genexpr>z/ConsoleAddon.console_command.<locals>.<genexpr>  s     FQ---a0Fs   !)partialN)joinr   status_prompt_commandsend)r)   r   quoteds      r*   console_commandzConsoleAddon.console_command  s;    
 F+FFcMF%%**6*:r,   zconsole.command.confirmc                 P      fd} j                   j                  ||       y)zG
        Prompt the user before running the specified command.
        c                     | dk(  ry 	 j                   j                  j                         y # t        j                  $ r(}t
        j                  t        |             Y d }~y d }~ww xY w)Nn)r'   r]   r^   r	   r   r   	exceptionr=   )r   r   r   r   r)   s     r*   r   z6ConsoleAddon.console_command_confirm.<locals>.callback-  sW    cz)$$11#t<** )  Q(()s   &0 A+A&&A+N)r'   prompt_for_user_choice)r)   r   r   r   r   s   ` `` r*   console_command_confirmz$ConsoleAddon.console_command_confirm"  s    	) 	**68<r,   zconsole.command.setoption_namec                     t        | j                  j                  |d      xs d}d| d|}t        |      dz
  }t        j
                  j                  ||       y)z3
        Prompt the user to set an option.
        Nr   zset r   rM   )r   cursor)getattrr'   rO   rQ   r   r   r   )r)   r   option_valueset_commandr   s        r*   console_command_setz ConsoleAddon.console_command_set7  s\    
 t{{22KFL"[M<*:;[!A%%%**;v*Nr,   zconsole.view.keybindingsc                 :    | j                   j                  d       y)View the commands list.keybindingsNr'   switch_viewrJ   s    r*   view_keybindingszConsoleAddon.view_keybindingsA  s     	.r,   zconsole.view.commandsc                 :    | j                   j                  d       y)r   r]   Nr   rJ   s    r*   view_commandszConsoleAddon.view_commandsF       	
+r,   zconsole.view.optionsc                 :    | j                   j                  d       y)zView the options editor.rO   Nr   rJ   s    r*   view_optionszConsoleAddon.view_optionsK  s     		*r,   zconsole.view.eventlogc                 :    | j                   j                  d       y)zView the event log.eventlogNr   rJ   s    r*   view_eventlogzConsoleAddon.view_eventlogP  r   r,   zconsole.view.helpc                 :    | j                   j                  d       y)z
View help.helpNr   rJ   s    r*   	view_helpzConsoleAddon.view_helpU  s     	'r,   zconsole.view.flowr   c                 $   t        |t        j                  t        j                  t
        j                  t        j                  f      r| j                  j                  d       yt        j                  dt        |      j                   d       y)zView a flow.flowviewzNo detail view for .N)
isinstancer   HTTPFlowr   TCPFlowr   UDPFlowr   DNSFlowr'   r   r   warningtype__name__)r)   r   s     r*   	view_flowzConsoleAddon.view_flowZ  sZ     dT]]CKKckkRSKK##J/NN0d1D1D0EQGHr,   zconsole.exitc                 8    | j                   j                          y)zExit mitmproxy.N)r'   shutdownrJ   s    r*   exitzConsoleAddon.exitb  s     	r,   zconsole.view.popc                 @    t         j                  j                          y)zv
        Pop a view off the console stack. At the top level, this prompts the
        user to exit mitmproxy.
        N)r   pop_view_stater   rJ   s    r*   view_popzConsoleAddon.view_popg  s     	##%r,   zconsole.bodyviewpartzconsole.bodyview.options)r   c                    t        ||d      }|st        j                  d|z        |j                  j	                  d      }|j                  d      }|st        j                  d      | j                  j                  ||       y)z
        Spawn an external viewer for a flow request or response body based
        on the detected MIME type. We use the mailcap system to find the
        correct viewer, and fall back to the programs in $PAGER or $EDITOR
        if necessary.
        Nz0Part must be either request or response, not %s.zcontent-typeFstrictzNo content to view.)r   r	   r   headersgetget_contentr'   spawn_external_viewer)r)   r   r   fparttcontents         r*   bodyviewzConsoleAddon.bodyviewo  s     dD)))BTI  MMn-##5#1))*?@@))'15r,   c                 
    ddgS )z6
        Possible parts for console.bodyview.
        requestresponserI   rJ   s    r*   bodyview_optionszConsoleAddon.bodyview_options  s    
 :&&r,   zconsole.edit.focus.optionsc                    | j                   j                  j                  j                  g 	 | j                   j                  j                  d      dt        dt        dz  ddffd}t        j                  d      t        t        j                        r(j                  d	        |d	j                  d
          nt        t        j                         r(j                  d        |dj                  d
          nt        t"        j$                        rfj'                  g d        |dj(                          |dj*                         j,                  rP |dj,                  j                  d
          n/t        t.        j0                        rt        j                  d      j                  d       S # t        $ r dY w xY w)z=
        Possible components for console.edit.focus.
        console.flowview.moder/   message_namemessageNrG   c                 &   |y t        j                  |      \  }}t         j                  j                  |xs dt        j                  |            }t        |t         j                        r"j                  |  d|j                   d       y y )Nr,   z ())	r   get_datar>   get_viewmake_metadatar   InteractiveContentviewappendname)r   r   data_cvr   focus_options	view_names        r*   add_message_edit_optionz@ConsoleAddon.edit_focus_options.<locals>.add_message_edit_option  s     "++G4GD!&&//**7D9B
 "lAAB$$~Ry%BC Cr,   No flow selected.tcp-messageudp-message)cookiesurlencoded formmultipart formpathmethodqueryreasonrequest-headersresponse-headersrequest-bodyresponse-bodystatus_codeset-cookiesurlr  r  websocket-messagez1Cannot edit DNS flows yet, please submit a patch.comment)r'   viewfocusr   r]   callr   r=   r   r	   r   r   r   r   messagesr   r   r   r   extendr   r   	websocketr   r   )r)   r   r   r   r   s     @@@r*   edit_focus_optionszConsoleAddon.edit_focus_options  s   
 {{%%**	,,112IJI	D	D(:T(A	D	D <))*=>>dCKK(  /#M4==3DEckk*  /#M4==3DEdmm,  $ $NDLLA#OT]]C~~'')@)@)D ckk*))C  	Y'u  	I	s   %G GGzconsole.edit.focus	flow_partc                 	   | j                   j                  j                  j                  }|st	        j
                  d       |j                          |dv xr |j                  du }|r#t        j                  j                         |_        |dk(  r| j                   j                  d       y|dk(  r| j                   j                  d       y|dk(  r| j                   j                  d	       y|d
k(  r| j                   j                  d       y|dk(  r| j                   j                  d       y|dk(  r| j                   j                  d       y|dk(  r| j                   j                  d       y|dk(  r| j                   j                  d       yt        j                  d|      x}r/|d   xdk(  r |j                  }nZxdk(  r |j                  }nGxxdk(  rnxdk(  rn n  |j                  d   }n&dk(  r|j                   j                  d   }n	 J d       t"        j$                  j'                  |d         }|rt)        |t"        j*                        st        d|d    d       t#        j,                  |||j.                        }| j                   j1                  |j2                        }t#        j4                  ||||j.                        |_        y|d!v r|dk(  r|j                  }n|j                  }| j                   j1                  |j9                  d"      xs d#      }	| j                   j:                  j<                  r|	j?                  d$      }	|	|_        y|d%k(  r| j                   j                  d&       y|d'k(  rp|j                  j@                  jC                         }
| j                   j1                  |
      }|j?                  d$      }
|
jE                         |j                  _         y|d(v r*| j                   jF                  jI                  d)d*d+|g       y|d,v r|dk(  r|j                   j                  d   }n|j                  d   }| j                   j1                  |j6                  xs d#      }	| j                   j:                  j<                  r|	j?                  d$      }	|	j?                  d$      |_        yy)-zA
        Edit a component of the currently focused flow.
        r   )r  r  r  Nr  edit_focus_commentr  edit_focus_cookiesr  edit_focus_urlencoded_formr  edit_focus_multipart_formr  edit_focus_pathr  edit_focus_queryr
  edit_focus_request_headersr  edit_focus_response_headerszX(?P<message>(request|response)-body|(tcp|udp|websocket)-message) \((?P<contentview>.+)\)r   r  r  r   r  r  r  Fzshould be exhaustivecontentviewzContentview z is not bidirectional.)r  r  r   r,      
r  edit_focus_setcookiesr  )r  r  r	  r   zflow.set@focus)r   r  r  )%r'   r  r  r   r	   r   backupr   r   Responsemaker   rematchr   r  r  r   r>   r   r   r   prettify_messager   spawn_editortextreencode_messager   r   rO   r:   rstripr  encodedecoder]   r^   )r)   r  r   require_dummy_responsemr   r   pretty
prettifiedcr  
edited_urls               r*   
edit_focuszConsoleAddon.edit_focus  s    {{%%** ))*=>> MM &% 	 " MM..0DM	!KK##$89)#KK##$89++KK##$@A**KK##$?@& KK##$56'!KK##$67++KK##$@A,,KK##$AB((g
 
Q 
 I,#"llG$"mmG2]]2"mmB/G("nn55b9G8"885&&**1]+;<BZL,O,OP""1]#3"44JK  "227D"''JF11&++>J*;;	GO ;;N*,,--(()<)<E)<)J)QcRA
 {{""BBHHUOGO-'KK##$;<%,,""))+C11#6J##E*C"zz|DLL==KK  --!J)#D MM//..11"5--+(()?C@A{{""BBHHUOhhuoGO Nr,   c                     | j                   j                  j                  d      }|st        j                  d      |j                         S )N
grideditorzNot in a grideditor.)r'   rV   r\   r	   r   key_responder)r)   gewidgets     r*   _grideditorzConsoleAddon._grideditor7  s@    ;;%%--l;))*@AA%%''r,   zconsole.grideditor.addc                 @    | j                         j                          y)z-
        Add a row after the cursor.
        N)r?  cmd_addrJ   s    r*   grideditor_addzConsoleAddon.grideditor_add=  s    
 	""$r,   zconsole.grideditor.insertc                 @    | j                         j                          y)z1
        Insert a row before the cursor.
        N)r?  
cmd_insertrJ   s    r*   grideditor_insertzConsoleAddon.grideditor_insertD      
 	%%'r,   zconsole.grideditor.deletec                 @    | j                         j                          y)z
        Delete row
        N)r?  
cmd_deleterJ   s    r*   grideditor_deletezConsoleAddon.grideditor_deleteK  rF  r,   zconsole.grideditor.loadr  c                 B    | j                         j                  |       y)z4
        Read a file into the current cell.
        N)r?  cmd_read_filer)   r  s     r*   grideditor_loadzConsoleAddon.grideditor_loadR  s    
 	((.r,   zconsole.grideditor.load_escapedc                 B    | j                         j                  |       y)ze
        Read a file containing a Python-style escaped string into the
        current cell.
        N)r?  cmd_read_file_escapedrL  s     r*   grideditor_load_escapedz$ConsoleAddon.grideditor_load_escapedY  s     	006r,   zconsole.grideditor.savec           
         | j                         j                  }	 t        |ddd      5 }t        j                  |      }|D ]8  }|j                  |D cg c]  }t        j                  |      xs d c}       : 	 ddd       t        j                  t        dt        |      z         yc c}w # 1 sw Y   5xY w# t        $ r(}t        j                  t        |             Y d}~yd}~ww xY w)z-
        Save data to file as a CSV.
        wr   utf8)newlineencodingNzSaved %s rows as CSV.)r?  valueopencsvwriterwriterowr   
always_strr   r   r   rQ   OSErrorr   r=   )r)   r  rowsfprY  rowr   r   s           r*   grideditor_savezConsoleAddon.grideditor_savea  s    
 !''		!dCf= B COO?BC!,,Q/525C JJu5TCD D	   	!LLQ  	!s@   B? *B3 B.5	B3?.B? .B33B<8B? ?	C0C++C0zconsole.grideditor.editorc                 @    | j                         j                          y)z?
        Spawn an external editor on the current cell.
        N)r?  cmd_spawn_editorrJ   s    r*   grideditor_editorzConsoleAddon.grideditor_editorr  s    
 	++-r,   zconsole.flowview.mode.setmodezconsole.flowview.mode.optionsc                    | j                   j                  j                  d      }|st        j                  d      |j
                  j                  }|j                         | j                         vrt        j                  d      	 | j                   j                  j                  ddd| |g       y# t        j                  $ r(}t        j                  t        |             Y d}~yd}~ww xY w)zA
        Set the display mode for the current flow view.
        r   Not viewing a flow.zInvalid flowview mode.zview.settings.setvalr'  flowview_mode_N)r'   rV   current_windowr	   r   body
tab_offsetlowerflowview_mode_optionsr]   r^   r   r   r=   )r)   rd  r`   idxr   s        r*   flowview_mode_setzConsoleAddon.flowview_mode_sety  s     [[..z:))*?@@gg  ::<t99;;))*BCC	!KK  --&^C53I4(P && 	!LLQ  	!s   	,B6 6C1	C,,C1c                 >    t         j                  j                         S )zB
        Returns the valid options for the flowview mode.
        )r   r>   r?   rJ   s    r*   rl  z"ConsoleAddon.flowview_mode_options  s    
 $$4466r,   r   c                 :   | j                   j                  j                  d      }|st        j                  d      |j
                  j                  }| j                   j                  j                  ddd| | j                   j                  j                  g      S )zA
        Get the display mode for the current flow view.
        r   rf  zview.settings.getvalr'  rg  )r'   rV   rh  r	   r   ri  rj  r]   r^   rO   r.   )r)   r`   rm  s      r*   flowview_modezConsoleAddon.flowview_mode  s    
 [[..z:))*?@@gg  {{##00" &##??
 	
r,   zconsole.key.contextsc                 F    t        t        t        j                              S )z9
        The available contexts for key binding.
        )r#   rA   r   ContextsrJ   s    r*   key_contextszConsoleAddon.key_contexts  s    
 F6??+,,r,   console.key.bindcontextskeyc                     	 | j                   j                  j                  ||dz   dj                  |      z   |d       y# t        $ r}t        j                  |      d}~ww xY w)z&
        Bind a shortcut key.
        r   r   N)r'   r   addr   
ValueErrorr	   r   )r)   rv  rw  r   r   vs         r*   key_bindzConsoleAddon.key_bind  sW    	-KK""3c	CHHTN(BHbQ 	-))!,,	-s   =A   	A#	AA#zconsole.key.unbindc                     	 | j                   j                  j                  ||       y# t        $ r}t	        j
                  |      d}~ww xY w)z)
        Un-bind a shortcut key.
        N)r'   r   removerz  r	   r   )r)   rv  rw  r{  s       r*   
key_unbindzConsoleAddon.key_unbind  sB    
	-KK%%c84 	-))!,,	-s   &) 	AAAc                     | j                   j                  j                  d      }|st        j                  d      |j                         }|st        j                  d      |S )Nr   zNot viewing key bindings.zNo key binding focused)r'   rV   r\   r	   r   get_focused_binding)r)   kwidgetfs      r*   	_keyfocuszConsoleAddon._keyfocus  sY    ++$$,,];))*EFF'')))*BCCr,   zconsole.key.unbind.focusc                     | j                         }	 | j                  j                  j                  |j                  |j
                         y# t        $ r}t        j                  |      d}~ww xY w)zW
        Un-bind the shortcut key currently focused in the key binding viewer.
        N)	r  r'   r   r~  rw  rv  rz  r	   r   )r)   br{  s      r*   key_unbind_focuszConsoleAddon.key_unbind_focus  sX    
 NN	-KK%%aeeQZZ8 	-))!,,	-s   :A 	A0A++A0zconsole.key.execute.focusc                 Z    | j                         }| j                  |j                         y)<
        Execute the currently focused key binding.
        N)r  r   r   r)   r  s     r*   key_execute_focuszConsoleAddon.key_execute_focus  s"    
 NNQYY'r,   zconsole.key.edit.focusc                     | j                         }| j                  ddj                  |j                        |j                  |j
                         y)r  ru  ,N)r  r   r   rv  rw  r   r  s     r*   key_edit_focuszConsoleAddon.key_edit_focus  s?    
 NNHHQZZ EEII		
r,   c                     d| _         y )NT)r(   rJ   s    r*   runningzConsoleAddon.running  s	    r,   c                     |st         j                  j                          |D ]"  }t         j                  j                  |       $ y )Nr
   )r   update_settingsr   flow_change)r)   flowsr  s      r*   rP   zConsoleAddon.update  s=    ##((* 	-A$$!$,	-r,   )rG   N)Fr   
__module____qualname____doc__r+   rF   r   r   r=   rK   rT   rX   rZ   ra   rf   rj   rn   rq   ru   ry   r|   r~   r   r   	mitmproxytypesCmdCmdArgsr   r   r   r   r   r   r   r   r   r   r   Flowr   r   r   argumentChoicer   r   r  r:  r?  rB  rE  rI  PathrM  rP  r`  rc  rn  rl  rq  rt  r|  r  r  r  r  r  r  rP   rI   r,   r*   r%   r%   .   s   
?
B W__-.4 4 /4 W__+,G -G W__)*$ +$ W__)*! +! W__23T 4T W__()* ** W__&'( (( W__'() )) W__)*+ ++ W__%&% '% W__'(' )' W__)** +* W__+,, -, W__'(' )' W__()( *( W__%&YY #Y __  	Y
 &&Y 
Y 'Y. W__)*YY ??&&Y ##	Y
 &&Y 
Y +Y0 W__&';C ;D ; (; W__./== __  = &&	=
 
= 0=( W__*+Os Ot O ,O W__/0/ 1/ W__,-, ., W__+,+ -+ W__,-, ., W__()( *( W__()Idii ID I *I W__^$ % W__'(& )& W__'(Wf9??#9#9:T#UV6TYY 6c 6d 6 W )6$ W__/0'(3- ' 1' W__12CHSM C 3CJ W__)*W)//001MNa.C a.D a. +a.F( W__-.% /% W__01( 2( W__01( 2( W__.//IOO$8$8 /T / 0/ W__677IOO,@,@ 7T 7 87 W__./!IOO$8$8 !T ! 0!  W__01. 2. W__01WY__++,KL!c !d ! 2!& W__457x} 7 67 W__,-
s 
 .
$ W__+,-hsm - -- W__'(-3-- - __  	-
 &&- 
- )- W__)*-8C= -s -t - +- W__/0- 1- W__01( 2( W__-.

 /

-r,   r%   )%rX  loggingr+  collections.abcr   mitmproxy.typesr  r   r   r   r   r   r	   r   r   r   r   r   mitmproxy.contentviewsr   mitmproxy.exceptionsr   mitmproxy.logr   mitmproxy.tools.consoler   r   r   mitmproxy.utilsr   	getLoggerr   r   rD   rB   r9   r%   rI   r,   r*   <module>r     s    
  	 $   # "          5 -  * + + $			8	$  7 M- M-r,   