
    'h
-                        d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
 ddl	mZ ddlmZ dej                  dej                  ej                      ded	dfd
Zded	efdZdej                   d	ej                   fdZ G d dej.                        Z G d d      Z G d dej.                        Z G d d      Zdededed	ej                   fdZddej:                  e   fdZd Zy)z5
    This module manages and invokes typed commands.
    N)
exceptions)command_lexer)unquotefargskwargsreturnc                     t        j                  |       }	  |j                  |i | y # t        $ r*}t	        j
                  d|j                  d   z        d }~ww xY w)Nzcommand argument mismatch: %sr   )inspect	signaturebind	TypeErrorr   CommandErrorr   )r   r   r   sigvs        i/var/www/html/scrapers/gsc/venv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/command.pyverify_arg_signaturer      s\    


A
CS$!&! S%%&Eq	&QRRSs   * 	A%AAtc                 0   | t         j                  k(  rt        j                  d      t        j
                  j                  j                  j                  j                  | d      }|s#t        j                  dt        | d|       z        |j                  S )z9
        Translates a type to an explanatory string.
    zmissing type annotationNzunsupported type: %s__name__)r   _emptyr   r   seleniumwire
thirdparty	mitmproxytypesCommandTypesgetgetattrdisplay)r   tos     r   typenamer!      sz     	GNN%%&?@@		 	 	*	*	0	0	=	=	A	A!T	JB%%&<wq*VW?X&XYY::    xc                 B    | t         j                  j                  k(  ry | S N)r   	Signatureemptyr#   s    r   _empty_as_noner)   %   s    G###Hr"   c                       e Zd ZU eed<   ej                  ed<   ej                  j                  Z
ej                  ed<   d Zy)CommandParameternametypekindc                     | j                   t        j                  j                  u rd| j                   S | j                  S )N*)r.   r   	ParameterVAR_POSITIONALr,   selfs    r   __str__zCommandParameter.__str__0   s4    99))888tyyk?"99r"   N)r   
__module____qualname__str__annotations__typingTyper   r1   POSITIONAL_OR_KEYWORDr.   _ParameterKindr5    r"   r   r+   r+   +   s2    
I
++#*#4#4#J#JD'
 
 Jr"   r+   c                      e Zd ZU eed<   ded<   ej                  ed<   ej                  e   ed<   dddedej                  ddfd	Z
edej                  ej                     fd
       Zedej                  e   fd       ZdefdZdej$                  e   dej&                  fdZdej$                  e   dej*                  fdZy)Commandr,   CommandManagermanagerr   helpfuncr	   Nc           
      j   || _         || _        || _        t        j                  | j                        | _        |j
                  rD|j
                  j                         }dj                  t        j                  |            | _
        nd | _
        | j                  j                  j                         D ]  \  }}|j                  }t        j                  j                   j"                  j$                  j'                  |j                  d       r[t)        j*                  d| dt-        |       d| d       | j.                  rot        j                  j                   j"                  j$                  j'                  | j.                  d       s&t)        j*                  d| j.                   d| d      y y )N
z	Argument z has an unknown type (z) in .z!Return type has an unknown type ()r,   rB   rD   r   r   __doc__stripjointextwrapwraprC   
parametersitems
annotationr   r   r   r   r   r   r   r   r)   return_type)r4   rB   r,   rD   txt	parameterr   s          r   __init__zCommand.__init__=   sl   		 **4995<<,,$$&C		(--"45DIDI  $~~88>>@ 	wOD)$$A**44::GGKKIL`L`bfg --	$?UVdefVgUhhmnrmsst.uvv	w L$;$;$E$E$K$K$X$X$\$\]a]m]mos$t)),MdN^N^M__deidjjk*lmm %ur"   c                 @    t        | j                  j                        S r%   )r)   r   return_annotationr3   s    r   rP   zCommand.return_typeQ   s    dnn>>??r"   c                     g }| j                   j                  j                         D ]5  \  }}|j                  t	        ||j
                  |j                               7 |S )z$Returns a list of CommandParameters.)r   rM   rN   appendr+   rO   r.   )r4   retr,   params       r   rM   zCommand.parametersU   sV     >>44::< 	MKD%JJ'e.>.>

KL	M
r"   c                     dj                  d | j                  D              }| j                  rdt        | j                         }nd}| j                   d| | S )N c              3   2   K   | ]  }t        |        y wr%   )r8   ).0rY   s     r   	<genexpr>z)Command.signature_help.<locals>.<genexpr>^   s     B#e*Bs   z ->  )rJ   rM   rP   r!   r,   )r4   paramsrX   s      r   signature_helpzCommand.signature_help]   sY    B$//BB$"2"2345CC))AfXcU++r"   r   c                    	  | j                   j                  | }|j                  j                         D ]L  \  }}| j                   j                  |   j                  }t        | j                  ||      |j                  |<   N |j                          |S # t        $ rL dt        | j                   j                         }dt        |       }t        j                  d| d|       w xY w)Nz
Expected: z
Received: z Command argument mismatch: 
    z
    )r   r   r   r8   rM   r   r   	argumentsrN   rO   parseargrB   apply_defaults)r4   r   bound_argumentsexpectedreceivedr,   value
convert_tos           r   prepare_argszCommand.prepare_argse   s    	j1dnn1148O +44::< 	XKD%2248CCJ.6t||UJ.WO%%d+	X 	&&(  	j#C(A(A$B#CDH#CI;/H)),MhZW]^f]g*hii	js   B AC+c                    | j                  |      } | j                  |j                  i |j                  }|| j                  yt
        j                  j                  j                  j                  j                  | j                        }|sJ |j                  | j                  ||      s.t        j                  | j                   d|j                          |S )zn
        Call the command with a list of arguments. At this point, all
        arguments are strings.
        Nz% returned unexpected data - expected )rk   rD   r   r   rP   r   r   r   r   r   r   is_validrB   r   r   r,   r   )r4   r   
bound_argsrX   typs        r   callzCommand.callu   s    
 &&t,
dii>J,=,=>;4++3%%//55BBFFtGWGWX
s||DLL#s3))99+B3;;-P  
r"   )r   r6   r7   r8   r9   r   r&   r:   OptionalCallablerS   propertyr;   rP   Listr+   rM   ra   SequenceBoundArgumentsrk   Anyrp   r>   r"   r   r@   r@   7   s    
I   
//#
n 0 n n6?? nW[ n( @V__V[[9 @ @ FKK(89  , ,!5 ':P:P  - &** r"   r@   c                   @    e Zd ZU eed<   ej                  ed<   eed<   y)ParseResultri   r-   validN)r   r6   r7   r8   r9   r:   r;   boolr>   r"   r   ry   ry      s    J
++Kr"   ry   c                      e Zd ZU ej                  eef   ed<   d Zd Z	dedej                  fdZ ej                  d      d	ed
ej                  ej                  e   ej                  e   f   fd       Zdedej                  ej&                     d
ej&                  fdZdedej                  e   d
ej&                  fdZd	ed
ej&                  fdZej0                  fddZy)rA   commandsc                      || _         i | _        y r%   )masterr}   )r4   r   s     r   rS   zCommandManager.__init__   s    r"   c                    t        |      D ]\  }|j                  d      rt        ||      }	 t        t        |dd       t              }|s@	 | j                  |j                  |       ^ y # t        j                  $ r?}| j                  j                  j                  d|j                  d|       Y d }~d }~ww xY w# t        $ r Y w xY w)N__command_namezCould not load command z: )dir
startswithr   
isinstancer8   addr   r   r   r   logwarn	Exception)r4   addonio
is_commandes         r   collect_commandszCommandManager.collect_commands   s    U 	A<<%E1%!+GA~t,Lc!RJ " HHQ^^Q7	  *66  KKOO00CD>>ST U  ! s)   CA,,B>?5B99B>	CCpathrD   c                 8    t        | ||      | j                  |<   y r%   )r@   r}   )r4   r   rD   s      r   r   zCommandManager.add   s    %dD$7dr"      )maxsizecmdstrr	   c                 f   t         j                  j                  |d      }g }t        dt        j
                  j                  j                  j                        t        dt        j
                  j                  j                  j                        g}d}|D ]x  }|j                         rJ|j                  t        |t        j
                  j                  j                  j                  d             ^|r*|j                  t        j                   j"                  u r|rNJ |r|j%                  d      }n8t        dt        j
                  j                  j                  j&                        }|j(                  t        j
                  j                  j                  j                  k(  xr || j*                  v }|j(                  t        j
                  j                  j                  j                  k(  xr || j*                  v}|xr> |d   j(                  t        j
                  j                  j                  j                  k(  }	|r!|	r| j*                  |   j,                  |dd z   }|r|	r|j%                  d       t        j
                  j                  j                  j.                  j1                  |j(                  d      }
d}|
r 	 |
j3                  | |j(                  |       d}|j                  t        ||j(                  |             { ||fS # t4        j6                  $ r d}Y Ew xY w)	z
        Parse a possibly partial command. Return a sequence of ParseResults and a sequence of remainder type help items.
        T)parseAllr_   N)ri   r-   rz   r      F)r   exprparseStringr+   r   r   r   r   CmdCmdArgsisspacerW   ry   Spacer.   r   r1   r2   popUnknownr-   r}   rM   r   r   parser   r   )r4   r   partsparsednext_paramsrg   partarg_is_known_commandarg_is_unknown_commandcommand_args_followingr    rz   s               r   parse_partialzCommandManager.parse_partial   s    #0"4"4"@"@RV"@"W+-R!8!8!B!B!H!H!L!LMR!8!8!B!B!H!H!P!PQ6
 7; 0	D||~")44>>DDJJ" HMMW->->-M-MM&&&??1-+B0G0G0Q0Q0W0W0_0_` !8!8!B!B!H!H!L!LLfQUY]YfYfQf ! !8!8!B!B!H!H!L!LLjQU]a]j]jQj # fA 3 3|7N7N7X7X7^7^7f7f f # $(>"mmD1<<{12N%*@"((2288EEII(--Y]^BE!HHT8==$7 !EMM!U0	d {"" "++ "!E"s   LL0/L0r   r   c                     || j                   vrt        j                  d|z         | j                   |   j                  | S )zO
        Call a command with native arguments. May raise CommandError.
        Unknown command: %s)r}   r   r   rD   r4   r   r   s      r   rp   zCommandManager.call   sC     t}},))*?,*NOO/t}}\*//66r"   c                     || j                   vrt        j                  d|z        | j                   |   j                  |      S )zZ
        Call a command using a list of string arguments. May raise CommandError.
        r   )r}   r   r   rp   r   s      r   call_stringszCommandManager.call_strings   sA     t}},))*?,*NOO}}\*//55r"   c                 L   | j                  |      \  }}|st        j                  d|      |D cg c]R  }|j                  t        j
                  j                  j                  j                  k7  rt        |j                        T c}^}}| j                  ||      S c c}w )zC
        Execute a command string. May raise CommandError.
        zInvalid command: )r   r   r   r-   r   r   r   r   r   r   ri   r   )r4   r   r   _r   r   r   s          r   executezCommandManager.execute   s     %%f-q)),=fZ*HII 
yyL33==CCIII DJJ
t
   t44
s   AB!Nc                 2   t        | j                  j                               }|j                  d        |D ]\  }|j                  xs dj                         D ]  }t        d|z   |        t        |j                         |       t        |       ^ y )Nc                 "    | j                         S r%   )ra   r(   s    r   <lambda>z%CommandManager.dump.<locals>.<lambda>  s     0 0 2 r"   )keyr_   z# )file)listr}   valuessortrC   
splitlinesprintra   )r4   outcmdschls        r   dumpzCommandManager.dump  s    DMM((*+		2	3 	Avv|//1 +dRic*+!""$3/sO		r"   )r	   N)r   r6   r7   r:   Dictr8   r@   r9   rS   r   rr   r   	functools	lru_cacheTupleru   ry   r+   r   rw   rp   r   r   sysstdoutr   r>   r"   r   rA   rA      s   kk#w,''$8 86?? 8 Y%B#B# 
fook2FOODT4UU	VB# &B#H7 7V__VZZ-H 7VZZ 76 6FOOC4H 6VZZ 65c 5fjj 5 zz r"   rA   rB   specargtypec                 N   t         j                  j                  j                  j                  j                  |d      }|st        j                  d|       	 |j                  | ||      S # t        j                  $ r$}t        j                  t        |            |d}~ww xY w)zE
        Convert a string to a argument to the appropriate type.
    NzUnsupported argument type: )r   r   r   r   r   r   r   r   r   r   r8   )rB   r   r   r   r   s        r   rd   rd     s     	))//<<@@$OA%%(CG9&MNN5www.. 5%%c!f-145s   A- -B$ BB$r,   c                       fd}|S )Nc                      t        j                          fd       }xs  j                  j                  dd      |j                  d<   |S )Nc                  .    t        | |        | i |S r%   )r   )r   r   functions     r   wrapperz+command.<locals>.decorator.<locals>.wrapper&  s     48T,V,,r"   r   rG   r   )r   wrapsr   replace__dict__)r   r   r,   s   ` r   	decoratorzcommand.<locals>.decorator%  sN    		"	- 
#	- ,0+V83D3D3L3LSRU3V(r"   r>   )r,   r   s   ` r   commandr   $  s     r"   c                 X     dt         j                  dt         j                  f fd}|S )z
        Set the type of a command argument at runtime. This is useful for more
        specific types such as seleniumwire.thirdparty.mitmproxy.types.Choice, which we cannot annotate
        directly as mypy does not like that.
    r   r	   c                 F    | j                   v sJ | j                   <   | S r%   )r9   )r   r,   r-   s    r   r   zargument.<locals>.decorator8  s,    q((((("&$r"   )r   FunctionType)r,   r-   r   s   `` r   argumentr   1  s*    U'' E,>,> 
 r"   r%   ) rH   r   r   r   rK   r   r:   'seleniumwire.thirdparty.mitmproxy.typesr   !seleniumwire.thirdparty.mitmproxyr   r   /seleniumwire.thirdparty.mitmproxy.command_lexerr   rr   Iterablerw   dictr   r-   r8   r!   r)   
NamedTupler+   r@   ry   rA   rd   rq   r   r   r>   r"   r   <module>r      s     
    . 8 ; CSFOO S6??6::3N SX\ Sae S	 	 	fjj VZZ 	v(( 	M M`&## G GT
5n 
5C 
5$ 
56:: 
5
&//#& 
r"   