
    hg+                        d dl mZmZ d dlZ	 d dlmZ n# e$ r	 d dlmZ Y nw xY w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 n# e$ r Y nw xY wd d
l	mZ d dl	mZ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mZ d dlm Z   e e!edd                     ed          k    Z" G d d          Z# G d de e#e          Z G d de e#e          Z G d de e#e          Z G d de e#e          Z G d  d!e e#e          ZdS )"    )AnyDictN)parse)parse_version)ActionChains)FirefoxOptions)FirefoxProfile)Proxy)TouchActions)Chrome)ChromeOptionsDesiredCapabilities)Edge)EdgeOptions)Firefox)Remote)Safari)backendutils)InspectRequestsMixin__version__0z4.0.0c                        e Zd ZdZdeeef         deeef         fdZ fdZe	deeef         fd            Z
e
j        deeef         fd            Z
 xZS )	DriverCommonMixinz)Attributes common to all webdriver types.seleniumwire_optionsreturnc                 ~   t          j        |                    dd          |                    dd          |          | _         t	          j        | j                                                   \  }}ddd                    ||          d                    ||          d	i}d
|v r|d
         |d         d<   d|d<   |S )z^Create the backend proxy server and return its configuration
        in a dictionary.
        addrz	127.0.0.1portr   )r   r   optionsproxymanualz{}:{})	proxyType	httpProxysslProxyexclude_hostsnoProxyTacceptInsecureCerts)r   createpopgetr   urlsafe_addressaddressformat)selfr   r   r   configs        O/var/www/fb-scrape/myenv/lib/python3.11/site-packages/seleniumwire/webdriver.py_setup_backendz DriverCommonMixin._setup_backend%   s     ~%))&+>>%))&!44(
 
 
 *4<+?+?+A+ABB
d %$^^D$77#NN466 
 222)=o)NF7OI&(,$%    c                 z    | j                                          t                                                       dS )z3Shutdown Selenium Wire and then quit the webdriver.N)r   shutdownsuperquit)r/   	__class__s    r1   r7   zDriverCommonMixin.quitA   s,    r3   c                 "   i }t          | j        j        j        d          }|r|                    d          rw|                    d          d         }|                    d          ^}}t          | j        j        j        d          }|r| d| d|d          ||<   n| d|d          ||<   t          | j        j        j        d	          }|rd
                    |          |d	<   t          | j        j        j        d          }|r||d<   |S )z+Get the proxy configuration for the driver.modeupstreamz	upstream:   z://upstream_auth@r   no_proxy,upstream_custom_authcustom_authorization)getattrr   masterr    
startswithsplitjoin)	r/   confr:   r;   schemerestauthr?   custom_auths	            r1   r!   zDriverCommonMixin.proxyF   s*    t|*2F;; 		7DOOJ// 		7zz+..q1H$NN511MFT4<.6HHD 7"(==T==DG==V"(66T!W66V4<.6
CC 	2"xx11Ddl19;QRR 	7+6D'(r3   
proxy_confc                    | j         j        j        }|r5 |j        di t	          j        t	          j        d|i                     dS  |j        di t          j        |                    t          j                  t          j	        |                    t          j	                  t          j
        |                    t          j
                  t          j        |                    t          j                  i dS )a3  Set the proxy configuration for the driver.

        The configuration should be a dictionary:

        webdriver.proxy = {
            'https': 'https://user:pass@server:port',
            'no_proxy': 'localhost,127.0.0.1',
        }

        Args:
            proxy_conf: The proxy configuration.
        r!   N )r   rD   r    updater   build_proxy_argsget_upstream_proxy	MITM_MODEdefaultMITM_UPSTREAM_AUTHMITM_UPSTREAM_CUSTOM_AUTHMITM_NO_PROXY)r/   rM   r    s      r1   r!   zDriverCommonMixin.proxyd   s     ,%- 
	GNeeU3E4LgWaMb4c4cddeeeeeGN  OW__U_%E%E,gooe>V.W.W3W__UEd5e5e'9L)M)M	    r3   )__name__
__module____qualname____doc__r   strr   r2   r7   propertyr!   setter__classcell__r8   s   @r1   r   r   "   s        334S> d3PS8n    8    
 tCH~    X: \S#X    \    r3   r   c                   (     e Zd ZdZdd fd
Z xZS )r   zSExtend the Firefox webdriver to provide additional methods for inspecting requests.Nr   c                   |i }	 |d         }n## t           $ r t                      }||d<   Y nw xY w|                    dd           d|_        |                     |          }|                    dd          rt          rat                      }|d         d         |_        |d         d         |_	        	 |d         d	         |_
        n# t           $ r Y nw xY w||_        ne|                    d
|                    d                    }|t          j        }|                                }|                    |           ||d
<    t!                      j        |i | dS )Initialise a new Firefox WebDriver instance.

        Args:
            seleniumwire_options: The seleniumwire options dictionary.
        Nr    z'network.proxy.allow_hijacking_localhostTauto_configr!   r$   r%   r'   capabilitiesdesired_capabilities)KeyErrorr   set_preferenceaccept_insecure_certsr2   r+   SELENIUM_V4r
   
http_proxy	ssl_proxyr?   r!   r   FIREFOXcopyrP   r6   __init__)	r/   r   argskwargsfirefox_optionsr0   r!   rf   r8   s	           r1   rp   zFirefox.__init__   s     '#% 	0$Y/OO 	0 	0 	0,..O /F9	0 	&&'PRVWWW04-$$%9::##M488 	6 6 #)'?;#? "(/*"=%+G_Y%?ENN   D ).%%  &zz.&**E[:\:\]]'#6#>L+0022##F+++)5~&$)&)))))s    007C 
CCrX   rY   rZ   r[   rp   r_   r`   s   @r1   r   r      sK        ]]37 /* /* /* /* /* /* /* /* /* /* /*r3   r   c                   (     e Zd ZdZdd fd
Z xZS )r   zRExtend the Chrome webdriver to provide additional methods for inspecting requests.Nrb   c                Z   |i }	 |                     dd          p|d         }n# t          $ r t                      }Y nw xY w|                    d           ||d<   |                     |          }|                    dd          r	 |                                D ]\  }}|                    ||           nW# t          $ rJ |	                    dt          j                                                  }|                    |           Y nw xY w t                      j        |i | dS )zInitialise a new Chrome WebDriver instance.

        Args:
            seleniumwire_options: The seleniumwire options dictionary.
        Nchrome_optionsr    --proxy-bypass-list=<-loopback>re   Trg   )r*   rh   r   add_argumentr2   r+   itemsset_capabilityAttributeError
setdefaultr   CHROMEro   rP   r6   rp   )
r/   r   rq   rr   rw   r0   keyvaluecapsr8   s
            r1   rp   zChrome.__init__   sj     '#% 	- $ZZ(8$??T6)CTNN 	- 	- 	-*__NNN	-
 	##$EFFF*y$$%9::##M488 	$$"(,,.. > >JC"11#u====>! $ $ $ (()?ATA[A`A`AbAbccF#####	$ 	$)&)))))"   & A A
0B; ;ADDrt   r`   s   @r1   r   r      sK        \\37 !* !* !* !* !* !* !* !* !* !* !*r3   r   c                   $     e Zd ZdZd fd	Z xZS )r   zRExtend the Safari webdriver to provide additional methods for inspecting requests.Nc                     |i }d|v s
J d            |                      |            t                      j        |i | dS )zInitialise a new Safari WebDriver instance.

        Args:
            seleniumwire_options: The seleniumwire options dictionary.
        Nr   z6You must set a port number in the seleniumwire_options)r2   r6   rp   )r/   r   rq   rr   r8   s       r1   rp   zSafari.__init__   se      '#%  ----/g---0111$)&)))))r3   Nrt   r`   s   @r1   r   r      sC        \\* * * * * * * * * *r3   r   c                   $     e Zd ZdZd fd	Z xZS )r   zPExtend the Edge webdriver to provide additional methods for inspecting requests.Nc                 Z   |i }	 |                     dd          p|d         }n# t          $ r t                      }Y nw xY w|                    d           ||d<   |                     |          }|                    dd          r	 |                                D ]\  }}|                    ||           nW# t          $ rJ |	                    dt          j                                                  }|                    |           Y nw xY w t                      j        |i | dS )zInitialise a new Edge WebDriver instance.

        Args:
            seleniumwire_options: The seleniumwire options dictionary.
        Nedge_optionsr    rx   re   Trg   )r*   rh   r   ry   r2   r+   rz   r{   r|   r}   r   r~   ro   rP   r6   rp   )
r/   r   rq   rr   r   r0   r   r   r   r8   s
            r1   rp   zEdge.__init__   si     '#% 	) "::nd;;Pvi?PLL 	) 	) 	)&==LLL	)
 	!!"CDDD(y$$%9::##M488 	$$"(,,.. < <JC //U;;;;<! $ $ $ (()?ATA[A`A`AbAbccF#####	$ 	$)&)))))r   r   rt   r`   s   @r1   r   r      sC        ZZ!* !* !* !* !* !* !* !* !* !*r3   r   c                   (     e Zd ZdZdd fd
Z xZS )r   zRExtend the Remote webdriver to provide additional methods for inspecting requests.Nrb   c                `   |i }|                      |          }|                    dd          rd|                    d          }|t          j                                        }n|                                }|                    |           ||d<    t                      j        |i | dS )rd   Nre   Trg   )r2   r+   r   rn   ro   rP   r6   rp   )r/   r   rq   rr   r0   rf   r8   s         r1   rp   zRemote.__init__  s      '#% $$%9::##M488 		:!::&<==L#2:??AA+0022'''-9F)*$)&)))))r3   rt   r`   s   @r1   r   r     sK        \\37 * * * * * * * * * * *r3   r   )$typingr   r   seleniumpackaging.versionr   r   ImportErrorpkg_resourcesselenium.webdriverr   r   r	   r
   r   r   _Chromer   r   r   _Edger   r   _Firefoxr   _Remoter   _Safariseleniumwirer   r   seleniumwire.inspectr   rC   rk   r   rO   r3   r1   <module>r      s            ,8888888 , , ,++++++++, , + + + + + - - - - - - - - - - - - $ $ $ $ $ $	/////// 	 	 	D	 0 0 0 0 0 0 A A A A A A A A , , , , , , * * * * * * 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 ' ' ' ' ' ' ' ' 5 5 5 5 5 5mGGHmSAABBmmT[F\F\\\ \ \ \ \ \ \ \~2* 2* 2* 2* 2*"$5x 2* 2* 2*j$* $* $* $* $*!#4g $* $* $*N* * * * *!#4g * * *.$* $* $* $* $*!2E $* $* $*N* * * * *!#4g * * * * *s    ##A AA