
    Dg+                        d dl mZ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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y# e$ r	 d dlmZ Y w xY w# e$ r Y w xY w)"    )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                 X   t        j                  |j                  dd      |j                  dd      |      | _         t	        j
                  | j                   j                               \  }}dddj                  ||      dj                  ||      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        V/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/seleniumwire/webdriver.py_setup_backendz DriverCommonMixin._setup_backend%   s     ~~%))&+>%))&!4(
 **4<<+?+?+AB
d %$^^D$7#NN46
 22)=o)NF7OI&(,$%    c                 V    | j                   j                          t        |           y)z3Shutdown Selenium Wire and then quit the webdriver.N)r   shutdownsuperquit)r/   	__class__s    r1   r7   zDriverCommonMixin.quitA   s    r3   c                 H   i }t        | j                  j                  j                  d      }|r|j	                  d      rq|j                  d      d   }|j                  d      ^}}t        | j                  j                  j                  d      }|r| d| d|d    ||<   n| d|d    ||<   t        | j                  j                  j                  d	      }|rd
j                  |      |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||**22F;DOOJ/zz+.q1H$NN51MFT4<<..66HD"(TF!DG9=V"(T!WI6V4<<..66
C"xx1Ddll1199;QR+6D'(r3   
proxy_confc                 J   | j                   j                  j                  }|r; |j                  di t	        j
                  t	        j                  d|i             y |j                  di t        j                  |j                  t        j                        t        j                  |j                  t        j                        t        j                  |j                  t        j                        t        j                  |j                  t        j                        i y)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     ,,%%--GNNeU33E4L4LgWaMb4cdeGNN OOW__U__%E,,gooe>V>V.W33W__UEdEd5e''9L9L)M	r3   )__name__
__module____qualname____doc__r   strr   r2   r7   propertyr!   setter__classcell__r8   s   @r1   r   r   "   sy    34S> d3PS8n 8
 tCH~  : \\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   }|j                  dd       d|_        | j	                  |      }|j                  dd      rt        r:t               }|d   d   |_        |d   d   |_	        	 |d   d	   |_
        ||_        nY|j                  d
|j                  d            }|t        j                  }|j                         }|j                  |       ||d
<   t!        | D  |i | y# t         $ r t               }||d<   Y w xY w# t         $ r Y w xY w)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__   sE     '#% 	0$Y/O 	&&'PRVW04-$$%9:##M48 #)'?;#? "(/*"=%+G_Y%?EN ).%  &zz.&**E[:\]'#6#>#>L+002##F+)5~&$)&)I  	0,.O /F9	0,   s#   C1 3D 1DD	DDrX   rY   rZ   r[   rp   r_   r`   s   @r1   r   r      s    ]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                   |i }	 |j                  dd      xs |d   }|j                  d       ||d<   | j	                  |      }|j                  dd      r,	 |j                         D ]  \  }}|j                  ||        	 t        	| <  |i | y# t        $ r t               }Y w xY w# t        $ rB |j                  dt        j                  j                               }|j                  |       Y sw xY w)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__   s
     '#% 	- $ZZ(8$?T6)CTN 	##$EF*y$$%9:##M48$"(,,. >JC"11#u=> 	$)&))  	-*_N	- " $ (()?ATA[A[A`A`AbcF#	$$   B *B. B+*B+.AC98C9rt   r`   s   @r1   r   r      s    \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.c                 d    |i }d|v sJ d       | j                  |       t        |   |i | y)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__   sI      '#%  --g/gg-01$)&)r3   Nrt   r`   s   @r1   r   r      s    \* *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.c                    |i }	 |j                  dd      xs |d   }|j                  d       ||d<   | j	                  |      }|j                  dd      r,	 |j                         D ]  \  }}|j                  ||        	 t        	| <  |i | y# t        $ r t               }Y w xY w# t        $ rB |j                  dt        j                  j                               }|j                  |       Y sw xY w)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__   s	     '#% 	) "::nd;Pvi?PL 	!!"CD(y$$%9:##M48$"(,,. <JC //U;< 	$)&))  	)&=L	) " $ (()?ATA[A[A`A`AbcF#	$r   r   rt   r`   s   @r1   r   r      s    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 }| j                  |      }|j                  dd      rX|j                  d      }|t        j                  j	                         }n|j	                         }|j                  |       ||d<   t        |   |i | y)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!::&<=L#2::??A+002'-9F)*$)&)r3   rt   r`   s   @r1   r   r     s    \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 , - - $	/ 1 A , * 2 0 0 ' 5GHmSABmT[F\\\ \~2*"$5x 2*j$*!#4g $*N*!#4g *.$*!2E $*N*!#4g *i  ,+,  		s"   C C# C C #C+*C+