
    vKg*                     d    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K	J
r
  S SKJr   " S S5      rg)    N)IteratorListOptionalUnion)TimeoutException)har)Requestc                      \ rS rSrSr\S\\   4S j5       r\R                  S 5       rS\
\   4S jr\S\\   4S j5       rS)S\S	\\\4   S\4S
 jjr\S\4S j5       r\S 5       r\R*                  S 5       rS 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 5       r\R*                  S 5       r\R                  S 5       r\S\\   4S j5       r\R*                  S\\   4S j5       r\R                  S 5       r\S\4S  j5       r\R*                  S!\4S" j5       r\R                  S# 5       r\S\4S$ j5       r\R*                  S!\4S% j5       r\R                  S& 5       rS'rg()*InspectRequestsMixin   zKMixin class that provides functions to inspect and modify browser requests.returnc                 J    U R                   R                  R                  5       $ )zRetrieves the requests made between the browser and server.

Captured requests can be cleared with 'del', e.g:

    del firefox.requests

Returns:
    A list of Request instances representing the requests made
    between the browser and server.
)backendstorageload_requestsselfs    T/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/seleniumwire/inspect.pyrequestsInspectRequestsMixin.requests   s     ||##1133    c                 L    U R                   R                  R                  5         g N)r   r   clear_requestsr   s    r   r   r      s    ++-r   c              #   h   #    U R                   R                  R                  5        Sh  vN   g N7f)z7Return an iterator of requests.

Returns: An iterator.
N)r   r   iter_requestsr   s    r   r   "InspectRequestsMixin.iter_requests    s#     
 <<''55777s   (202c                 J    U R                   R                  R                  5       $ )zRetrieve the last request made between the browser and server.

Note that this is more efficient than running requests[-1]

Returns:
    A Request instance representing the last request made, or
    None if no requests have been made.
)r   r   load_last_requestr   s    r   last_request!InspectRequestsMixin.last_request'   s     ||##5577r   pattimeoutc                 V   [         R                   " 5       n[         R                   " 5       U-
  U:  a_  U R                  R                  R                  U5      nUc  [         R                  " S5        OU$ [         R                   " 5       U-
  U:  a  M_  [        SR                  X!5      5      e)a  Wait up to the timeout period for a request matching the specified
pattern to be seen.

The pat attribute can be can be a simple substring or a regex that will
be searched in the full request URL. If a request is not seen before the
timeout then a TimeoutException is raised. Only requests with corresponding
responses are considered.

Given that pat can be a regex, ensure that any special characters
(e.g. question marks) are escaped.

Args:
    pat: The pat of the request to look for. A regex can be supplied.
    timeout: The maximum time to wait in seconds. Default 10s.

Returns:
    The request.
Raises:
    TimeoutException if a request is not seen within the timeout
        period.
g?z3Timed out after {}s waiting for request matching {})timer   r   findsleepr   format)r   r"   r#   startrequests        r   wait_for_request%InspectRequestsMixin.wait_for_request3   s    , 		iikE!G+ll**//4G

5! iikE!G+ T[[\cijjr   c                 r    [         R                  " U R                  R                  R	                  5       5      $ )zGet a HAR archive of HTTP transactions that have taken place.

Note that the enable_har option needs to be set before HAR
data will be captured.

Returns: A JSON string of HAR data.
)r   generate_harr   r   load_har_entriesr   s    r   r   InspectRequestsMixin.harU   s(      4 4 E E GHHr   c                 B    U R                   R                  R                  $ )a  The header overrides for outgoing browser requests.

DEPRECATED. Use request_interceptor and response_interceptor.

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:

    header_overrides = {
        'User-Agent': 'Firefox',
        'response:Cache-Control': 'none'
    }
    header_overrides = [
        ('.*somewhere.com.*', {'User-Agent': 'Firefox', 'response:Cache-Control': 'none'}),
        ('*.somewhere-else.com.*', {'User-Agent': 'Chrome'})
    ]
r   modifierheadersr   s    r   header_overrides%InspectRequestsMixin.header_overrides`   s    4 ||$$,,,r   c                     [        U[        5      (       a  U H  u  p#U R                  U5        M     OU R                  U5        XR                  R                  l        g r   )
isinstancelist_validate_headersr   r3   r4   )r   r4   _hs       r   r5   r6   |   sI    gt$$&&q)   ""7+(/%r   c                 t    UR                  5        H$  nUc  M  [        U[        5      (       a  M   S5       e   g )NzHeader values must be strings)valuesr8   str)r   r4   vs      r   r:   &InspectRequestsMixin._validate_headers   s1    !A}!!S))J+JJ) "r   c                 0    U R                   R                  ?g r   r2   r   s    r   r5   r6      s    LL!!)r   c                 B    U R                   R                  R                  $ )a  The parameter overrides for outgoing browser requests.

DEPRECATED. Use request_interceptor.

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:
    param_overrides = {'foo': 'bar'}
    param_overrides = [
        ('.*somewhere.com.*', {'foo': 'bar'}),
        ('*.somewhere-else.com.*', {'x': 'y'}),
    ]
r   r3   paramsr   s    r   param_overrides$InspectRequestsMixin.param_overrides   s    0 ||$$+++r   c                 8    XR                   R                  l        g r   rD   )r   rE   s     r   rF   rG          '-$r   c                 0    U R                   R                  ?g r   rD   r   s    r   rF   rG          LL!!(r   c                 B    U R                   R                  R                  $ )a  The body overrides for outgoing browser requests.

DEPRECATED. Use request_interceptor and response_interceptor.

For 'not GET' requests, the parameters are assumed to be encoded in the
request body.

The value of the body can be a string value or list of sublists,
with each sublist having two elements - a URL pattern and string value.
The string value will be encoded, then replace whole http body.
And body_overrides has higher priority than param_overrides When they conflict.
For example:
    body_overrides = '{"foo":"bar"}'
    body_overrides = [
        ('.*somewhere.com.*', '{"foo":"bar"}'),
        ('*.somewhere-else.com.*', '{"x":"y"}'),
    ]
r   r3   bodiesr   s    r   body_overrides#InspectRequestsMixin.body_overrides   s    ( ||$$+++r   c                 8    XR                   R                  l        g r   rM   )r   rN   s     r   rO   rP      rI   r   c                 0    U R                   R                  ?g r   rM   r   s    r   rO   rP      rK   r   c                 B    U R                   R                  R                  $ )a  The querystring overrides for outgoing browser requests.

DEPRECATED. Use request_interceptor.

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_overrides = 'foo=bar&x=y'
    querystring_overrides = [
        ('.*somewhere.com.*', 'foo=bar&x=y'),
        ('*.somewhere-else.com.*', 'a=b&c=d'),
    ]
r   r3   querystringr   s    r   querystring_overrides*InspectRequestsMixin.querystring_overrides   s    & ||$$000r   c                 8    XR                   R                  l        g r   rT   )r   querystringss     r   rV   rW      s    ,8)r   c                 0    U R                   R                  ?g r   rT   r   s    r   rV   rW      s    LL!!-r   c                 B    U R                   R                  R                  $ )a  The rules used to rewrite request URLs.

DEPRECATED. Use request_interceptor.

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/'),
    ]
r   r3   rewrite_rulesr   s    r   r]   "InspectRequestsMixin.rewrite_rules   s     ||$$222r   c                 8    XR                   R                  l        g r   r\   )r   r]   s     r   r]   r^      s    .;+r   c                 0    U R                   R                  ?g r   r\   r   s    r   r]   r^     s    LL!!/r   c                 .    U R                   R                  $ )zThe URL patterns used to scope request capture.

The value of the scopes should be a list (or tuple) of
regular expressions.

For example:
    scopes = [
        '.*stackoverflow.*',
        '.*github.*'
    ]
r   scopesr   s    r   rc   InspectRequestsMixin.scopes  s     ||"""r   rc   c                 $    XR                   l        g r   rb   )r   rc   s     r   rc   rd     s    $r   c                 &    / U R                   l        g r   rb   r   s    r   rc   rd     s     r   c                 .    U R                   R                  $ )zA callable that will be used to intercept/modify requests.

The callable must accept a single argument for the request
being intercepted.
r   request_interceptorr   s    r   ri   (InspectRequestsMixin.request_interceptor  s     ||///r   interceptorc                 $    XR                   l        g r   rh   r   rk   s     r   ri   rj   %  s    +6(r   c                 &    S U R                   l        g r   rh   r   s    r   ri   rj   )  s    +/(r   c                 .    U R                   R                  $ )zA callable that will be used to intercept/modify responses.

The callable must accept two arguments: the response being
intercepted and the originating request.
r   response_interceptorr   s    r   rq   )InspectRequestsMixin.response_interceptor-  s     ||000r   c                     [        [        R                  " U5      R                  5      S:w  a  [	        S5      eXR
                  l        g )N   zEA response interceptor takes two parameters: the request and response)leninspect	signature
parametersRuntimeErrorr   rq   rm   s     r   rq   rr   6  s6    w  -889Q>fgg,7)r   c                 &    S U R                   l        g r   rp   r   s    r   rq   rr   <  s    ,0)r    N)
   ) __name__
__module____qualname____firstlineno____doc__propertyr   r	   r   deleterr   r   r   r    r?   r   intfloatr+   r   r5   setterr:   rF   rO   rV   r]   rc   callableri   rq   __static_attributes__r{   r   r   r   r      s'   U4$w- 4 4 . .8x0 8 	8hw/ 	8 	8 kC  k%U
2C  kW  kD IS I I - -6 0 0K
 * * , ,2 . . ) ) , ,* . . ) ) 1 1( !!9 "9 "". #. 3 3  < < 0 0 #S	 # # ]]%T#Y % % ^^! ! 0X 0 0 7x 7  7   0 !0 1h 1 1   8 8 !8
 !!1 "1r   r   )rv   r%   typingr   r   r   r   selenium.common.exceptionsr   seleniumwirer   seleniumwire.requestr	   r   r{   r   r   <module>r      s&      2 2 7  (s1 s1r   