
    vKg1                     L    S SK r S SKrS SKJrJrJrJr  S SKJr   " S S5      r	g)    N)parse_qs	urlencodeurlsplit
urlunsplit)is_list_alikec                      \ rS rSrSrS r\S 5       r\R                  S 5       r\R                  S 5       r\S 5       r
\
R                  S 5       r
\
R                  S	 5       r
\S
 5       r\R                  S 5       r\R                  S 5       r\S 5       r\R                  S 5       r\R                  S 5       rSS jrSS jrS rS rS rS rS rSrg)RequestModifier   zThis class is responsible for modifying request and response attributes.

DEPRECATED. Use request and response interceptors instead.

Instances of this class are designed to be stateful and threadsafe.
c                 p    [         R                  " 5       U l        0 U l        0 U l        SU l        / U l        g)z!Initialise a new RequestModifier.N)	threadingLock_lock_headers_params_querystring_rewrite_rulesselfs    U/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/seleniumwire/modifier.py__init__RequestModifier.__init__   s.    ^^%
      c                     U R                      [        U R                  5      (       a  U R                  sSSS5        $ [        U R                  5      sSSS5        $ ! , (       d  f       g= f)am  The header overrides for outgoing browser requests.

The value of the headers can be a dictionary or list of sublists,
with each sublist having two elements - a URL pattern and headers.
Where a header in the dictionary exists in the request, the dictionary
value will overwrite the one in the request. Where a header in the dictionary
does not exist in the request, it will be added to the request as a
new header. To filter out a header from the request, set that header
in the dictionary to None. Header names are case insensitive.
For response headers, prefix the header name with 'response:'.

For example:

    headers = {
        'User-Agent': 'Firefox',
        'response:Cache-Control': 'none'
    }
    headers = [
        ('.*somewhere.com.*', {'User-Agent': 'Firefox', 'response:Cache-Control': 'none'}),
        ('*.somewhere-else.com.*', {'User-Agent': 'Chrome'})
N)r   r   r   dictr   s    r   headersRequestModifier.headers   s@    . ZZT]]++}} Z DMM*	 ZZ   &AA
A)c                 \    U R                      Xl        SSS5        g! , (       d  f       g= f)zSets the headers to override request headers.

Args:
    headers: The dictionary of headers or list of sublists,
    with each sublist having two elements - the pattern and headers
    to set.
N)r   r   )r   r   s     r   r   r   5   s     ZZ#M ZZ   
+c                     U R                      U R                  R                  5         SSS5        g! , (       d  f       g= f)zClears the headers being used to override request headers.

After this is called, request headers will pass through unmodified.
N)r   r   clearr   s    r   r   r   A   s%     ZZMM! ZZ   1
?c                     U R                      [        U R                  5      (       a  U R                  sSSS5        $ [        U R                  5      sSSS5        $ ! , (       d  f       g= f)a  The params that should be used to override the request params.

For POST requests, the parameters are assumed to be encoded in the
request body.

The value of the params can be a dictionary or list of sublists,
with each sublist having two elements - a URL pattern and params.
Where a param in the dictionary exists in the request, the dictionary
value will overwrite the one in the request. Where a param in the dictionary
does not exist in the request, it will be added to the request as a
new param. To filter out a param from the request, set that param
in the dictionary to None.

For example:
    params = {'foo': 'bar'}
    params = [
        ('.*somewhere.com.*', {'foo': 'bar'}),
        ('*.somewhere-else.com.*', {'x': 'y'}),
    ]
N)r   r   r   r   r   s    r   paramsRequestModifier.paramsJ   s@    , ZZT\\**|| Z DLL)	 ZZr   c                 \    U R                      Xl        SSS5        g! , (       d  f       g= f)zSets the params to override request params.

Args:
    params: The dictionary of params or list of sublists,
    with each sublist having two elements - the pattern and params
    to set.
N)r   r   )r   r$   s     r   r$   r%   f   s     ZZ!L ZZr   c                     U R                      U R                  R                  5         SSS5        g! , (       d  f       g= f)z}Clears the params being used to override request params.

After this is called, request params will pass through unmodified.
N)r   r   r!   r   s    r   r$   r%   r   s%     ZZLL  ZZr"   c                 h    U R                      U R                  sSSS5        $ ! , (       d  f       g= f)aI  The querystring overrides for outgoing browser requests.

The value of the querystring override can be a string or a list of sublists,
with each sublist having two elements, a URL pattern and the querystring.
The querystring override will overwrite the querystring in the request
or will be added to the request if the request has no querystring. To
remove a querystring from the request, set the value to empty string.

For example:
    querystring = 'foo=bar&x=y'
    querystring = [
        ('.*somewhere.com.*', 'foo=bar&x=y'),
        ('*.somewhere-else.com.*', 'a=b&c=d'),
    ]
Nr   r   r   s    r   querystringRequestModifier.querystring{   s    " ZZ$$ ZZs   #
1c                 \    U R                      Xl        SSS5        g! , (       d  f       g= f)z_Sets the querystring to override request querystring.

Args:
    querystring: The querystring.
Nr)   )r   r*   s     r   r*   r+      s     ZZ + ZZr   c                 ^    U R                      SU l        SSS5        g! , (       d  f       g= f)zBClears the querystring being used to override request querystring.Nr)   r   s    r   r*   r+      s     ZZ $D ZZs   
,c                     U R                      U R                   VVs/ sH  u  pUR                  U4PM     snnsSSS5        $ s  snnf ! , (       d  f       g= f)aY  The rules used to rewrite request URLs.

The value of the rewrite rules should be a list of sublists (or tuples)
with each sublist containing the pattern and replacement.

For example:
    rewrite_rules = [
        (r'(https?://)www.google.com/', r'www.bing.com/'),
        (r'https://docs.python.org/2/', r'https://docs.python.org/3/'),
    ]
N)r   r   pattern)r   patrepls      r   rewrite_rulesRequestModifier.rewrite_rules   sB     ZZ9=9L9LM9LICS[[$'9LM ZM Zs   A	AA	A		
Ac                     / nU H,  u  p4UR                  [        R                  " U5      U45        M.     U R                     X l        SSS5        g! , (       d  f       g= f)zSets the rewrite rules used to modify request URLs.

Args:
    rewrite_rules: The list of rewrite rules, which should
        be a list of sublists, with each sublist having two
        elements - the pattern and replacement.
N)appendrecompiler   r   )r   r2   compiledr/   replacements        r   r2   r3      sI     $1 GOORZZ0+>? %2 ZZ"* ZZs   A
Ac                     U R                      U R                  R                  5         SSS5        g! , (       d  f       g= f)z|Clears the rewrite rules being used to modify request URLs.

After this is called, request URLs will no longer be modified.
N)r   r   r!   r   s    r   r2   r3      s'     ZZ%%' ZZr"   c                    U R                  U R                  [        X5      5      nU(       am  U=(       d    0 R                  5        VVs0 sH-  u  pxUR	                  5       R                  S5      (       a  M+  Xx_M/     nnnU R                  [        X5      U5        U R                  XX4U5        U R                  X5        U R                  XU5        gs  snnf )aj  Performs modifications to the request.

Args:
    request: The request to modify.
    urlattr: The name of the url attribute on the request object.
    methodattr: The name of the method attribute on the request object.
    headersattr: The name of the headers attribute on the request object.
    bodyattr: The name of the body attribute on the request object.
	response:N)
_get_matching_overridesr   getattritemslower
startswith_modify_headers_modify_params_modify_querystring_rewrite_url)	r   requesturlattr
methodattrheadersattrbodyattroverride_headersnamevalues	            r   modify_requestRequestModifier.modify_request   s      77wwG`a %5$:#A#A#C #CKDzz|..{; #C   
   !>@PQGjxP  2'K8 s   	)C6Cc           	         U R                  U R                  [        X#5      5      nU=(       d    0 R                  5        VVs0 sHM  u  pgUR	                  5       R                  S5      (       d  M+  UR                  SSS9S   R                  5       U_MO     nnnU(       a  U R                  [        X5      U5        ggs  snnf )a  Performs modifications to the response.

Args:
    response: The response to modify.
    request: The original request.
    urlattr: The name of the url attribute on the response object.
    headersattr: The name of the headers attribute on the response object.
r<   :   )maxsplitN)	r=   r   r>   r?   r@   rA   splitstriprB   )r   responserF   rG   rI   rK   rL   rM   s           r   modify_responseRequestModifier.modify_response   s      77wwG`a
 !1 6B==?
?zz|&&{3 :DJJsQJ'*002E9? 	 
   !?AQR 
s   )B</&B<c                 \   UR                  5        VVs0 sH  u  p4UR                  5       X44_M     nnn[        U5       H1  n UR                  UR                  5       5      S   nX	 Ub  XqU'   M1  M3     UR                  5        H  u  pgUc  M
  XqU'   M     g s  snnf ! [         a     Mk  f = f)NrR   )r?   r@   listpopKeyErrorvalues)r   r   rK   hv
headers_lcheaderrM   s           r   rB   RequestModifier._modify_headers   s    4D4J4J4LM4LDAaggi!'4L
M 7mF,"v||~6q9 O$&+FO % $ (..0MF "' 1 N  s   B"B
B+*B+c                    [        X5      nU R                  U R                  U5      nU(       d  g [        X5      n[        X5      n	[        U5      R                  n
U	R                  S5      S:H  nUS:X  a   U(       a  [        X5      R                  SSS9n
[        U
SS9nU R                     UR                  U5        S S S 5        [        UR                  5       5       H  u  pUb  M
  UR                  U5        M     [        USS	9n
US:X  a<  U(       a5  U
R                  S5      n
[        [!        U
5      5      U	S
'   [#        XU
5        g [        U5      u  nnnnn[#        X[%        UUUU
U45      5        g ! , (       d  f       N= f)NzContent-Typez!application/x-www-form-urlencodedPOSTzutf-8replace)errorsT)keep_blank_values)doseqzContent-Length)r>   r=   r   r   querygetdecoder   r   updaterZ   r?   r[   r   encodestrlensetattrr   )r   rF   rG   rH   rI   rJ   request_urlr$   methodr   ri   is_form_datarequest_paramsrL   rM   schemenetlocpath_fragments                       r   rC   RequestModifier._modify_params  sU   g/--dllKH-'/%++{{>26YYVG.55gi5PE!%4@ZZ!!&) 
   4 4 67KD}""4( 8 .5 VLL)E(+CJG$%Gu-080E-FFD!XGj&&$x1X&YZ% Zs   +E55
Fc                     [        X5      nU R                  U R                  U5      nUc  g [        U5      u  pVpxn	[	        X[        XVXt=(       d    SU	45      5        g )N )r>   r=   r   r   rp   r   )
r   rF   rG   rq   r*   ru   rv   rw   rx   ry   s
             r   rD   #RequestModifier._modify_querystring,  s[    g/2243D3DkR,4[,A)*fdDUSUW_-`"abr   c                    [        X5      n[        X5      nU R                     U R                  S S  nS S S 5        [        U5      R                  nW H,  u  pUR                  X5      u  pUS:  d  M   [        XU
5          O   [        X5      n[        U5      R                  nX|:w  a  SU;   a  XS'   g g g ! , (       d  f       N= f)Nr   Host)r>   r   r   r   rv   subnrp   )r   rF   rG   rI   request_headersrq   r2   original_netlocr/   r9   modifiedcountmodified_netlocs                r   rE   RequestModifier._rewrite_url6  s    !'7g/ZZ //2M  #;/66$1 G%ll;DOHqy(3 %2 g/";/66-(*9' ) . Zs   B44
Cc                     U R                      [        U5      (       a6  U H/  u  p4[        R                  " X25      nU(       d  M$  Us  sS S S 5        $    OUsS S S 5        $  S S S 5        g ! , (       d  f       g = f)N)r   r   r6   search)r   	overridesurlr0   ovmatchs         r   r=   'RequestModifier._get_matching_overridesN  sZ    ZZY''(GCIIc/Eu!	 Z  )
 ! Z  ) ZZs   3A)A)A))
A7)r   r   r   r   r   N)r   rr   r   body)r   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr   setterdeleterr$   r*   r2   rN   rW   rB   rC   rD   rE   r=   __static_attributes__ r   r   r	   r	      sM   ! + +8 ^^	$ 	$ __" " * *6 ]]	" 	" ^^! ! % %& , , % %
 N N + + ( (9.S*(&#[Jc:0	!r   r	   )
r6   r   urllib.parser   r   r   r   seleniumwire.utilsr   r	   r   r   r   <module>r      s     	  B B ,O! O!r   