
    'h                         d dl Z d dlZd dlmZmZ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mZ  G d d	ej$                        Z G d
 de
j(                        Zy)    N)ListOptionalUnion)CloseReasonOpcode)flow)serializable)
websockets)humanstrutilsc                   l    e Zd ZdZ	 ddededeeef   de	e
   deddfd	Zed
        Zd Zd Zd Zd Zy)WebSocketMessagezB
    A WebSocket message sent from one endpoint to the other.
    Ntypefrom_clientcontent	timestampkilledreturnc                     t        |      | _        	 || _        	 || _        	 |xs t	        j                         | _        	 || _        y N)r   r   r   r   timer   r   )selfr   r   r   r   r   s         k/var/www/html/scrapers/gsc/venv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/websocket.py__init__zWebSocketMessage.__init__   sF     4L	S&;E ) 8TYY[E\    c                      | | S r    )clsstates     r   
from_statezWebSocketMessage.from_state    s    E{r   c                     t        | j                        | j                  | j                  | j                  | j
                  fS r   )intr   r   r   r   r   r   s    r   	get_statezWebSocketMessage.get_state$   s-    499~t//t~~t{{ZZr   c                 z    |\  | _         | _        | _        | _        | _        t        | j                         | _         y r   )r   r   r   r   r   r   )r   r   s     r   	set_statezWebSocketMessage.set_state'   s-    QVN	4#T\4>4;499%	r   c                     | j                   t        j                  k(  r$dj                  t	        | j
                              S dj                  t        j                  | j
                              S )Nztext message: {}zbinary message: {})r   r   TEXTformatreprr   r   bytes_to_escaped_strr#   s    r   __repr__zWebSocketMessage.__repr__+   sL    99#%,,T$,,-?@@'..x/L/LT\\/Z[[r   c                     d| _         y)z~
        Kill this message.

        It will not be sent to the other endpoint. This has no effect in streaming mode.
        TN)r   r#   s    r   killzWebSocketMessage.kill1   s     r   )NF)__name__
__module____qualname____doc__r"   boolr   bytesstrr   floatr   classmethodr    r$   r&   r,   r.   r   r   r   r   r      s    
 w|]]&*]5:5#:5F]S[\aSb]qu]	]  [&\r   r   c                        e Zd ZdZd fd	Zej                  j                  j                         Zej                   e
ee   eeeeeeeeee              fdZed        Zd Zdedefd	Zd
 Z xZS )WebSocketFlowzS
    A WebSocketFlow is a simplified representation of a Websocket connection.
    c                    t         |   d|||       g | _        	 d| _        	 t        j
                  | _        	 d| _        	 d| _        	 d| _	        	 || _
        	 d| _        	 t        j                  d      | _        t        j                  d      | _        |rt!        j"                  |j$                  j&                        | _        t!        j*                  |j$                  j&                        | _        t!        j.                  |j$                  j&                        | _        t!        j2                  |j4                  j&                        | _        t!        j*                  |j4                  j&                        | _        t!        j.                  |j4                  j&                        | _        y d| _        d| _        d| _        d| _        d| _        d| _        y )	N	websocketclientz(message missing)zunknown status codeF   )maxsize )superr   messagesclose_senderr   NORMAL_CLOSURE
close_codeclose_messageclose_reasonstreamhandshake_flowendedqueueQueue_inject_messages_client_inject_messages_serverr
   get_client_keyrequestheaders
client_keyget_protocolclient_protocolget_extensionsclient_extensionsget_server_acceptresponseserver_acceptserver_protocolserver_extensions)r   client_connserver_connrH   live	__class__s        r   r   zWebSocketFlow.__init__?   s}   k;E027$B%44#0&1%R,G
A',{{1'=$',{{1'=$(778N8N8V8VWDO#-#:#:>;Q;Q;Y;Y#ZD %/%>%>~?U?U?]?]%^D"!+!=!=n>U>U>]>]!^D#-#:#:>;R;R;Z;Z#[D %/%>%>~?V?V?^?^%_D" DO#%D %'D"!#D#%D %'D"r   )rA   rB   rD   rE   rF   rQ   rS   rU   rX   rY   rZ   c                 F    t         |          }t        |d         |d<   |S )NrD   )r@   r$   r"   )r   dr^   s     r   r$   zWebSocketFlow.get_statex   s'    Gao.,r   c                 <     | d d d       }|j                  |       |S r   )r&   )r   r   fs      r   r    zWebSocketFlow.from_state}   s!    dD!	Er   c                 J    dj                  t        | j                              S )Nz<WebSocketFlow ({} messages)>)r)   lenrA   r#   s    r   r,   zWebSocketFlow.__repr__   s    .55c$--6HIIr   messager   c                 6   dj                  |j                  t        j                  | j                  j
                        t        j                  | j                  j
                        |j                  rdnd| j                  j                  j                        S )NzL{client} {direction} WebSocket {type} message {direction} {server}{endpoint}z->z<-)r   r<   server	directionendpoint)r)   r   r   format_addressr[   addressr\   r   rH   rO   path)r   re   s     r   message_infozWebSocketFlow.message_info   sx    ]dd''(8(8(@(@A''(8(8(@(@A%11dt((0055 e 
 	
r   c                     || j                   k(  r| j                  j                  |       y|| j                  k(  r| j                  j                  |       yt        d      )a  
        Inject and send a full WebSocket message to the remote endpoint.
        This might corrupt your WebSocket connection! Be careful!

        The endpoint needs to be either flow.client_conn or flow.server_conn.

        If ``payload`` is of type ``bytes`` then the message is flagged as
        being binary If it is of type ``str`` encoded as UTF-8 and sent as
        text.

        :param payload: The message body to send.
        :type payload: ``bytes`` or ``str``
        zInvalid endpointN)r[   rL   putr\   rM   
ValueError)r   ri   payloads      r   inject_messagezWebSocketFlow.inject_message   sT     t'''((,,W5)))((,,W5/00r   r   )r/   r0   r1   r2   r   r   Flow_stateobject_attributescopyupdatedictr   r   r5   r"   r$   r7   r    r,   rm   rr   __classcell__)r^   s   @r   r9   r9   :   s    $(L #ii??DDF""4&'$ "
  
J
$4 
 
1r   r9   )rJ   r   typingr   r   r   wsproto.frame_protocolr   r   !seleniumwire.thirdparty.mitmproxyr   +seleniumwire.thirdparty.mitmproxy.coretypesr	   %seleniumwire.thirdparty.mitmproxy.netr
   'seleniumwire.thirdparty.mitmproxy.utilsr   r   Serializabler   rs   r9   r   r   r   <module>r      sE      ( ( 6 2 D < C*|00 *Zi1DII i1r   