
    vKg                        S SK rS SKrS SKrS SKrS SKJr  S SKJr  S SKJ	r	J
r
  S SKJr  S SKJr  \R                   " \5      rSrSrS	rS
rSrSrSrS rS\	\\
4   S\	\\4   4S jrSS jrSS jrS rS r S\!S\S\!4S jr"g)    N)
namedtuple)Path)Dict
NamedTuple)_parse_proxy)encodingca.crtzca.keyzseleniumwire-ca.pemmodeupstream_authupstream_custom_authno_proxyc                    U =(       d    0 R                  S0 5      n[        R                  R                  S5      n[        R                  R                  S5      n[        R                  R                  S5      n0 nU(       a  X%S'   U(       a  X5S'   U(       a  XES'   UR	                  U5        UR                  S5      n[        U[        5      (       a1  UR                  S5       Vs/ sH  ofR                  5       PM     snUS'   [        S	S
5      nS H)  nUR                  U5      c  M  U" [        XX   5      6 XX'   M+     U$ s  snf )ad  Get the upstream proxy configuration from the options dictionary.
This will be overridden with any configuration found in the environment
variables HTTP_PROXY, HTTPS_PROXY, NO_PROXY

The configuration will be returned as a dictionary with keys 'http',
'https' and 'no_proxy'. The value of the 'http' and 'https' keys will
be a named tuple with the attributes:
    scheme, username, password, hostport
The value of 'no_proxy' will be a list.

Note that the keys will only be present in the dictionary when relevant
proxy configuration exists.

Args:
    options: The selenium wire options.
Returns: A dictionary.
proxy
HTTP_PROXYHTTPS_PROXYNO_PROXYhttphttpsr   ,	ProxyConfz!scheme username password hostport)r   r   )poposenvirongetupdate
isinstancestrsplitstripr   r   )	optionsproxy_options
http_proxyhttps_proxyr   mergedhconf
proxy_types	            R/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/seleniumwire/utils.pyget_upstream_proxyr)      s   $ ]''4M-J**../Kzz~~j)HF#v%w%z
MM- zz*%H(C  191DE1DAggi1DEzk#FGD'
 ::j!-!%|F4F'G!HF	 ( M Fs   &Eproxy_configreturnc                    U R                  S5      nU R                  S5      nSnU(       a/  U(       a(  UR                  UR                  :w  a  [        S5      eUnOU(       a  UnO	U(       a  Un0 nU(       a|  Uu  pVpxSR                  XX5      U[        '   U(       a  SR                  Xg5      U[
        '   U R                  S5      n	U	(       a  X[        '   U R                  S5      n
U
(       a  X[        '   U$ )	zBuild the arguments needed to pass an upstream proxy to mitmproxy.

Args:
    proxy_config: The proxy config parsed out of the Selenium Wire options.
Returns: A dictionary of arguments suitable for passing to mitmproxy.
r   r   NzADifferent settings for http and https proxy servers not supportedzupstream:{}://{}z{}:{}custom_authorizationr   )r   hostport
ValueErrorformat	MITM_MODEMITM_UPSTREAM_AUTHMITM_UPSTREAM_CUSTOM_AUTHMITM_NO_PROXY)r*   r"   r#   r&   argsschemeusernamepasswordr.   custom_authr   s              r(   build_proxy_argsr:   J   s     !!&)J""7+KDk+"6"66`aa		D/3,(,33FEY'.~~h'ID#$"&&'=>.9*+##J/"*K    c                     [         R                  " [        U 5      n[        [	        [
        R                  " 5       U 5      S5       nUR                  U5        SSS5        [        R                  SR                  U 5      5        g! , (       d  f       N3= f! [         a'    [        R                  SR                  U 5      5         gf = f)z?Extracts the root certificate to the current working directory.wbNz5{} extracted. You can now import this into a browser.zInvalid certificate '{}')pkgutilget_data__package__openr   r   getcwdwriteloginfor0   FileNotFoundErrorerror)	cert_namecertouts      r(   extract_certrK   w   s    \Y7 $ryy{I.5IIdO 6HOOPYZ[ 65  @		,33I>?@s   B B
B.CCc                    [         R                  " U SS9  [        U [        5      nU(       a  UR	                  5       (       a  gUb6  Ub3  [        U5      R                  5       n[        U5      R                  5       nOOUc  Ub  [        S5      e[        R                  " [        [        5      n[        R                  " [        [        5      n[        US5       nUR                  US-   U-   5        SSS5        g! , (       d  f       g= f)a  Extracts the root certificate and key and combines them into a
single file called seleniumwire-ca.pem in the specified destination
folder.

Args:
    dest_folder: The destination folder that the combined certificate
        and key will be written to.
    cert_path: Optional path to the root certificate. When not supplied
        selenium wire's own root certificate will be used.
    key_path: Optional path to the private key. When not supplied
        selenium wire's own private key will be used. Note that the key
        must always be supplied when a certificate is supplied.
    check_exists: If True the combined file will not be overwritten
        if it already exists in the destination folder.
T)exist_okNz+A certificate and key must both be suppliedr=      
)r   makedirsr   COMBINED_CERTexists
read_bytesr/   r>   r?   r@   	ROOT_CERTROOT_KEYrA   rC   )dest_folder	cert_pathkey_pathcheck_existscombined_path	root_certroot_keyf_outs           r(   extract_cert_and_keyr]      s      KKd+m4M,,..!5O..0	>,,.		("6FGG$$[)<	##K:	mT	"eI%01 
#	"	"s   C88
Dc                     [        U [        R                  R                  5      =(       a    [        U [        5      (       + $ )N)r   collectionsabcSequencer   )	containers    r(   is_list_alikerc      s)    i!9!9:]:iY\C]?]]r;   c                 *    U tpnU(       a  SU S3nX4$ )zMake an address safe to use in a URL.

Args:
    address: A tuple of address information.
Returns:
    A 2-tuple of url-safe (address, port)
[] )addressaddrportrests       r(   urlsafe_addressrl      s&      D4&{:r;   datar   c                 .    [         R                  " X5      $ )zAttempt to decode data based on the supplied encoding.

If decoding fails a ValueError is raised.

Args:
    data: The encoded data.
    encoding: The encoding type.
Returns: The decoded data.
Raises: ValueError if the data could not be decoded.
)decoderdecode)rm   r   s     r(   rp   rp      s     >>$))r;   )r	   )NNT)#collections.abcr_   loggingr   r>   r   pathlibr   typingr   r   urllib.requestr   *seleniumwire.thirdparty.mitmproxy.net.httpr   ro   	getLogger__name__rD   rS   rT   rP   r1   r2   r3   r4   r)   r   r:   rK   r]   rc   rl   bytesrp   rg   r;   r(   <module>rz      s      	  "  # ' J!	%	$ 2 /d*4Z#8 *T#s(^ *Z
\2D^"* *# *% *r;   