
    hg                         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mZm	Z	 d dlm
Z
 ddlmZ d Zd Ze j        d             Z G d	 d
          Zd Z G d d          ZdS )    N)
controllereventsequence
exceptions)flow   )ctxc                 \    t          | d| j        j                                                  S )Nname)getattr	__class____name__lower)itms    g/var/www/fb-scrape/myenv/lib/python3.11/site-packages/seleniumwire/thirdparty/mitmproxy/addonmanager.py	_get_namer      s%    3 6 < < > >???    c                 d    | }t          j        |           D ]\  }}}}| j        } ||k    r n| p|S )z
    Cut off a traceback at the function with the given name.
    The func_name's frame is excluded.

    Args:
        tb: traceback object, as returned by sys.exc_info()[2]
        func_name: function name

    Returns:
        Reduced traceback.
    )	traceback
extract_tbtb_next)tb	func_nametb_orig_fnames        r   cut_tracebackr      sQ     G#.r22  1eQZIE =r   c               #   L  K   	 d V  d S # t           j        t           j        f$ r  t          $ rt t	          j                    \  } }}t          |d          }t          j        	                    dd
                    t          j        | ||                    z             Y d S w xY w)Ninvoke_addonzError handling request
%s )r   	AddonHaltOptionsError	Exceptionsysexc_infor   r   logerrorjoinr   format_exception)etypevaluer   s      r   safecallr+   &   s      
 *"9:    
 
 
<>>ub2~..(277*5%<<, , 	
 	
 	
 	
 	
 	

s   
 BB#"B#c                       e Zd ZdZd Z	 ddededej        dedej	        ej
        e                  d	dfd
Zdedej        d	dfdZdS )LoaderzQ
        A loader object is passed to the load() event when addons start up.
    c                     || _         d S N)masterselfr0   s     r   __init__zLoader.__init__:   s    r   Nr
   typespecdefaulthelpchoicesreturnc                 P   || j         j        v rt| j         j        j        |         }|j        |k    o+|j        |k    o |j        |k    o|j        |k    o
|j        |k    }|rdS t          j	        
                    d|z             | j         j                            |||||           dS )a  
            Add an option to mitmproxy.

            Help should be a single paragraph with no linebreaks - it will be
            reflowed by tools. Information on the data type should be omitted -
            it will be generated and added by tools as needed.
        NzOver-riding existing option %s)r0   options_optionsr
   r4   r5   r6   r7   r   r%   warn
add_option)r2   r
   r4   r5   r6   r7   existingsame_signatures           r   r=   zLoader.add_option=   s     4;&&&{*3D9H% ,!X-, G+, %,  G+   F=DEEE&&	
 	
 	
 	
 	
r   pathfuncc                 F    | j         j                            ||           d S r/   )r0   commandsadd)r2   r@   rA   s      r   add_commandzLoader.add_commanda   s#      t,,,,,r   r/   )r   
__module____qualname____doc__r3   strtypetypingAnyOptionalSequencer=   CallablerE    r   r   r-   r-   6   s            :>"
 "
"
 "
 	"

 "
 !56"
 
"
 "
 "
 "
H- -6? -t - - - - - -r   r-   c              #   p   K   | D ]0}|V  t          |d          rt          |j                  E d{V  1dS )z2
        Recursively traverse an addon chain.
    addonsN)hasattrtraverserR   )chainas     r   rT   rT   e   s_        * *1h 	*)))))))))* *r   c                   \    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )AddonManagerc                 x    i | _         g | _        || _        |j        j                            | j                   d S r/   )lookuprU   r0   r:   changedconnect_configure_allr1   s     r   r3   zAddonManager.__init__p   s9    
&&t':;;;;;r   c                 2    |                      d|           d S )N	configure)trigger)r2   r:   updateds      r   r]   zAddonManager._configure_allv   s    ['*****r   c                 b    | j         D ]}|                     |d           i | _        g | _         dS )z(
            Remove all addons.
        doneN)rU   r   rZ   )r2   rV   s     r   clearzAddonManager.cleary   s@      	) 	)Aa((((


r   c                 8    | j                             |d          S )z
            Retrieve an addon by name. Addon names are equal to the .name
            attribute on the instance, or the lower case class name if that
            does not exist.
        N)rZ   get)r2   r
   s     r   rf   zAddonManager.get   s     {tT***r   c                    t          |g          D ]1}t          |          }|| j        v rt          j        d|z            2t          | j                  }|                     |d|           t          |g          D ]}t          |          }|| j        |<   t          |g          D ]!}| j        j        	                    |           "| j        j
                                         |S )ad  
            Register an addon, call its load event, and then register all its
            sub-addons. This should be used by addons that dynamically manage
            addons.

            If the calling addon is already running, it should follow with
            running and configure events. Must be called within a current
            context.
        z$An addon called '%s' already exists.load)rT   r   rZ   r   AddonManagerErrorr-   r0   r   rC   collect_commandsr:   process_deferred)r2   addonrV   r
   ls        r   registerzAddonManager.register   s    5'"" 	 	AQ<<Dt{"" 2:TA   # 4;%+++5'"" 	" 	"AQ<<D !DK5'"" 	5 	5AK 11!4444,,...r   c                 j    |D ]/}| j                             |                     |                     0dS )z
            Add addons to the end of the chain, and run their load event.
            If any addon has sub-addons, they are registered.
        N)rU   appendrn   )r2   rR   is      r   rD   zAddonManager.add   sB    
  	0 	0AJdmmA..////	0 	0r   c                    t          |g          D ]^t                    }|| j        vrt          j        d|z            fd| j        D             | _        | j        t                    = _|                     |d           dS )z
            Remove an addon and all its sub-addons.

            If the addon is not in the chain - that is, if it's managed by a
            parent addon - it's the parent's responsibility to remove it from
            its own addons attribute.
        zNo such addon: %sc                     g | ]}|u|	S rP   rP   ).0rq   rV   s     r   
<listcomp>z'AddonManager.remove.<locals>.<listcomp>   s    >>>1A::!:::r   rc   N)rT   r   rZ   r   ri   rU   r   )r2   rl   nrV   s      @r   removezAddonManager.remove   s     5'"" 	* 	*A!A## 23F3JKKK>>>>TZ>>>DJIaLL))%(((((r   c                 *    t          | j                  S r/   )lenrU   r2   s    r   __len__zAddonManager.__len__   s    4:r   c                 H    t          j        d | j        D                       S )Nc                 ,    g | ]}t          |          S rP   )rI   )rt   rq   s     r   ru   z(AddonManager.__str__.<locals>.<listcomp>   s    :::!s1vv:::r   )pprintpformatrU   rz   s    r   __str__zAddonManager.__str__   s#    ~::tz:::;;;r   c                 2    t          |          }|| j        v S r/   )r   rZ   )r2   itemr
   s      r   __contains__zAddonManager.__contains__   s    t{""r   c                   K   t          |d          st          j        d|z            t          |j        t
          j                  r|j                                         |                     ||           |j        j	        dk    r|j        
                                 |j        j        s|j                                         |j                                         t          |j        t
          j                  r|j                                         t          |t          j                  r|                     d|g           dS dS )z/
            Handle a lifecycle event.
        replyz!Message %s has no reply attributestartupdateN)rS   r   ControlException
isinstancer   r   
DummyReplyresetr`   statetakehas_messageackcommit
mark_resetr   Flow)r2   r
   messages      r   handle_lifecyclezAddonManager.handle_lifecycle   s6      w(( 	-3g=   gmZ%:;; 	"M!!!T7###='))M   =, $!!###M  """'-)>?? +((***gty)) 	.LLG9-----	. 	.r   c                 R   |t           j        vrt          j        d|z            t	          |g          D ]p}t          ||d          }|r[t          |          r	 ||i | -t          |t          j	                  rHt          j        d
                    ||                    qdS )zG
            Invoke an event on an addon and all its children.
        zUnknown event: %sNz"Addon handler {} ({}) not callable)r   Eventsr   ri   rT   r   callabler   types
ModuleTypeformat)r2   rl   r
   argskwargsrV   rA   s          r   r   zAddonManager.invoke_addon   s     }+++./BT/IJJJ5'"" 	 	A1dD))D D>> D$)&))))e&677 	
 $6<CCD!LL  	 	r   c                     | j         D ]R}	 t                      5   | j        ||g|R i | ddd           n# 1 swxY w Y   <# t          j        $ r Y  dS w xY wdS )z9
            Trigger an event across all addons.
        N)rU   r+   r   r   r    )r2   r
   r   r   rq   s        r   r`   zAddonManager.trigger   s      	 	AZZ @ @%D%a???????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @'   		 	s-   A8A<	A<	 AAAN)r   rF   rG   r3   r]   rd   rf   rn   rD   rw   r{   r   r   r   r   r`   rP   r   r   rX   rX   o   s        < < <+ + +  + + +  40 0 0) ) )   < < <# # #. . .:  ,	 	 	 	 	r   rX   )
contextlibr~   r#   r   r   rK   !seleniumwire.thirdparty.mitmproxyr   r   r   r   r   r   r   r   contextmanagerr+   r-   rT   rX   rP   r   r   <module>r      s7        



       S S S S S S S S S S 2 2 2 2 2 2      @ @ @  ( 
 
 
,- ,- ,- ,- ,- ,- ,- ,-^* * *S S S S S S S S S Sr   