
    Dg                         d Z ddlmZ ddlmZ ddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZmZmZmZ  G d de      Z G d	 d
      Z G d d      Z G d d      Zy)zRHouses the classes used to transfer request and response data between components.     )datetime)
HTTPStatus)HTTPMessage)DictIterableListOptionalTupleUnion)parse_qs	urlencodeurlsplit
urlunsplitc                       e Zd ZdZd Zy)HTTPHeaderszgA dict-like data-structure to hold HTTP headers.

    Note that duplicate key names are permitted.
    c                 4    t        | j                               S N)repritemsselfs    T/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/seleniumwire/request.py__repr__zHTTPHeaders.__repr__   s    DJJL!!    N)__name__
__module____qualname____doc__r    r   r   r   r   	   s    
"r   r   c            
          e Zd ZdZdddededeeeef      defdZe	d	efd
       Z
e
j                  defd       Z
e	d	efd       Zej                  defd       Ze	d	eeeeee   f   f   fd       Zej                  deeeeee   f   f   fd       Ze	d	efd       Ze	d	efd       Zej                  defd       Z	 ddedeeeef   eeeef      f   defdZej,                  fdefdZd Zd Zy)RequestzRepresents an HTTP request.r   bodymethodurlheadersr#   c                   d| _         || _        || _        t               | _        |D ]!  \  }}| j                  j                  ||       # || _        d| _        t        j                         | _
        g | _        i | _        y)a  Initialise a new Request object.

        Args:
            method: The request method - GET, POST etc.
            url: The request URL.
            headers: The request headers as an iterable of 2-element tuples.
            body: The request body as bytes.
        N)idr$   r%   r   r&   
add_headerr#   responser   nowdatews_messagescert)r   r$   r%   r&   r#   kvs          r   __init__zRequest.__init__   su     "&"} 	*DAqLL##Aq)	* 	,0&lln	35	r   returnc                     | j                   S )zKGet the request body.

        Returns: The request body as bytes.
        _bodyr   s    r   r#   zRequest.body-        zzr   bc                     |d| _         y t        |t              r|j                  d      | _         y t        |t              st        d      || _         y Nr   utf-8zbody must be of type bytesr5   
isinstancestrencodebytes	TypeErrorr   r7   s     r   r#   zRequest.body5   E    9DJ3'*DJAu%899DJr   c                 @    t        | j                        j                  S )zSGet the query string from the request.

        Returns: The query string.
        )r   r%   queryr   s    r   querystringzRequest.querystring@   s     !'''r   qsc                 j    t        t        | j                              }||d<   t        |      | _        y )N   listr   r%   r   )r   rF   partss      r   rE   zRequest.querystringH   s*    Xdhh'(ae$r   c                 8   | j                   }| j                  j                  d      dk(  r)| j                  r| j                  j	                  dd      }t        |d      j                         D ci c]  \  }}|t        |      dk(  r|d	   n| c}}S c c}}w )
aI  Get the request parameters.

        Parameters are returned as a dictionary. Each dictionary entry will have a single
        string value, unless a parameter happens to occur more than once in the request,
        in which case the value will be a list of strings.

        Returns: A dictionary of request parameters.
        Content-Type!application/x-www-form-urlencodedr:   replaceerrorsT)keep_blank_values   r   )rE   r&   getr#   decoder   r   len)r   rF   namevals       r   paramszRequest.paramsN   s     <<N+/RRW[W`W`!!')!<BHPQSgkHlHrHrHtu94CAc!f36uuus   2 Bpc                     t        |d      }| j                  j                  d      dk(  r|j                  dd      | _        y t        t        | j                              }||d<   t        |      | _        y )	NT)doseqrM   rN   r:   rO   rP   rH   )	r   r&   rT   r>   r#   rJ   r   r%   r   )r   rZ   rF   rK   s       r   rY   zRequest.params_   sb    q%<<N+/RR		')	<DI$((+,EE!H!%(DHr   c                 @    t        | j                        j                  S )zBGet the request path.

        Returns: The request path.
        )r   r%   pathr   s    r   r^   zRequest.pathj   s     !&&&r   c                 @    t        | j                        j                  S )zBGet the request host.

        Returns: The request host.
        )r   r%   netlocr   s    r   hostzRequest.hostr   s     !(((r   c                 j    t        t        | j                              }||d<   t        |      | _        y )N   rI   )r   rZ   rK   s      r   r^   zRequest.pathz   s*    Xdhh'(ae$r   status_codec                 :   	 t         j                  j                         D ci c]  }||j                   c}|   }t        |t              r|j                         }t        ||||      | _        yc c}w # t        $ r t        dj                  |            w xY w)z7Create a response object and attach it to this request.zUnknown status code: {})rd   reasonr&   r#   N)r   __members__valuesphraseKeyError
ValueErrorformatr<   dictr   Responser*   )r   rd   r&   r#   r0   rf   s         r   create_responsezRequest.create_response   s    	L+5+A+A+H+H+JKaakKKXF gt$mmoG [QX_cd L 	L6==kJKK	Ls    A6 A1A6 1A6 6$B
error_codec                 (    | j                  |       y)ztConvenience method for signalling that this request is to be terminated
        with a specific error code.
        )rd   N)ro   )r   rp   s     r   abortzRequest.abort   s     	4r   c                 6    dj                  t        |             S )NzLRequest(method={method!r}, url={url!r}, headers={headers!r}, body={_body!r})
format_mapvarsr   s    r   r   zRequest.__repr__   s    ]hhimnristtr   c                     | j                   S r   )r%   r   s    r   __str__zRequest.__str__   s    xxr   N)r   r   )r   r   r   r   r=   r   r
   r?   r1   propertyr#   setterrE   r   r   r   rY   r^   ra   intro   r   	FORBIDDENrr   r   rx   r   r   r   r!   r!      s   %cf # C (5c?:S [` . e   
[[e   (S ( ( %c % %
 vS%T#Y"778 v v  ]])S%T#Y"778 ) ) 'c ' ' )c ) ) 
[[%c % % oree).tCH~xcSVh?X/X)Yefke '1&:&: 5 5ur   r!   c            
           e Zd ZdZdddededeeeef      defdZ	e
d	efd
       Zej                  defd       Zd Zd Zy)rn   zRepresents an HTTP response.r   r"   rd   rf   r&   r#   c                    || _         || _        t               | _        |D ]!  \  }}| j                  j	                  ||       # || _        t        j                         | _        i | _	        y)a"  Initialise a new Response object.

        Args:
            status_code: The status code.
            reason: The reason message (e.g. "OK" or "Not Found").
            headers: The response headers as an iterable of 2-element tuples.
            body: The response body as bytes.
        N)
rd   rf   r   r&   r)   r#   r   r+   r,   r.   )r   rd   rf   r&   r#   r/   r0   s          r   r1   zResponse.__init__   s`     '"} 	*DAqLL##Aq)	* 	&lln		r   r2   c                     | j                   S )zMGet the response body.

        Returns: The response body as bytes.
        r4   r   s    r   r#   zResponse.body   r6   r   r7   c                     |d| _         y t        |t              r|j                  d      | _         y t        |t              st        d      || _         y r9   r;   rA   s     r   r#   zResponse.body   rB   r   c                 6    dj                  t        |             S )Nz]Response(status_code={status_code!r}, reason={reason!r}, headers={headers!r}, body={_body!r})rt   r   s    r   r   zResponse.__repr__   s    (jd4	
r   c                 N    dj                  | j                  | j                        S )Nz{} {})rl   rd   rf   r   s    r   rx   zResponse.__str__   s    ~~d..<<r   N)r   r   r   r   r{   r=   r   r
   r?   r1   ry   r#   rz   r   rx   r   r   r   rn   rn      s~    &kn s C (5QTVYQY?B[ ch ( e   
[[e  
=r   rn   c                   :    e Zd ZdZdedeeef   defdZ	d Z
d Zy)	WebSocketMessagez\Represents a websocket message transmitted between client and server
    or vice versa.
    from_clientcontentr,   c                .    || _         || _        || _        y)zInitialise a new websocket message.

        Args:
            from_client: True if the message was sent by the client.
            content: The text or binary message data.
            date: The datetime the message was sent or received.
        N)r   r   r,   )r   r   r   r,   s       r   r1   zWebSocketMessage.__init__   s     '	r   c                     t        | j                  t              r| j                  S dt        | j                         dS )N<z  bytes of binary websocket data>)r<   r   r=   rV   r   s    r   rx   zWebSocketMessage.__str__   s4    dllC(<<3t||$%%EFFr   c                     t        |t              sy| |u ry| j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )NFT)r<   r   r   r   r,   )r   others     r   __eq__zWebSocketMessage.__eq__   s[    %!12U]5#4#44r9Vr[_[d[dhmhrhr[rrr   N)r   r   r   r   boolr   r=   r?   r   r1   rx   r   r   r   r   r   r      s6    
t 
eCJ6G 
x 
G
sr   r   N)r   r   httpr   http.clientr   typingr   r   r   r	   r
   r   urllib.parser   r   r   r   r   r!   rn   r   r   r   r   <module>r      sM    X   # ? ? B B"+ "E EP1= 1=hs sr   