Ë
    ·�©j?  ã                  ó¼  — d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	 ddl
mZmZ ddlmZmZmZmZmZmZmZmZ ddlmZmZ dd	lmZmZmZmZmZmZm Z m!Z! dd
l"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+m,Z, ddlm-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 dgZ8 G d„ de+«      Z9 G d„ de9«      Z:d!d„Z; e<ejz                  j}                  dd«      «      Z? e<ejz                  j}                  dd«      «      Z@ e<ejz                  j}                  dd«      «      ZA e<ejz                  j}                  dd«      «      ZBe?e@eAeBf	 	 	 	 	 	 	 	 	 d"d„ZC e& eD«       ddddœ¬ «       y)#é    )ÚannotationsN)Ú	GeneratorÚSequence)ÚAnyé   )ÚHeadersÚMultipleValuesError)ÚInvalidHandshakeÚInvalidHeaderÚInvalidHeaderValueÚInvalidMessageÚInvalidStatusÚInvalidUpgradeÚNegotiationErrorÚStatusLineTooLong)ÚClientExtensionFactoryÚ	Extension)Úbuild_authorization_basicÚbuild_extensionÚ
build_hostÚbuild_subprotocolÚparse_connectionÚparse_extensionÚparse_subprotocolÚparse_upgrade)ÚRequestÚResponse)Úlazy_import)ÚCLIENTÚ
CONNECTINGÚOPENÚProtocolÚState)ÚConnectionOptionÚExtensionHeaderÚ
LoggerLikeÚOriginÚSubprotocolÚUpgradeProtocol)ÚWebSocketURI)Ú
accept_keyÚgenerate_keyÚClientProtocolc                  ó†   ‡ — e Zd ZdZdddedddœ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dˆ fd„Zdd„Zdd„Zdd„Zdd	„Z	dd
„Z
dˆ fd„Zˆ xZS )r-   as  
    Sans-I/O implementation of a WebSocket client connection.

    Args:
        uri: URI of the WebSocket server, parsed
            with :func:`~websockets.uri.parse_uri`.
        origin: Value of the ``Origin`` header. This is useful when connecting
            to a server that validates the ``Origin`` header to defend against
            Cross-Site WebSocket Hijacking attacks.
        extensions: List of supported extensions, in order in which they
            should be tried.
        subprotocols: List of supported subprotocols, in order of decreasing
            preference.
        state: Initial state of the WebSocket connection.
        max_size: Maximum size of incoming messages in bytes.
            :obj:`None` disables the limit. You may pass a ``(max_message_size,
            max_fragment_size)`` tuple to set different limits for messages and
            fragments when you expect long messages sent in short fragments.
        logger: Logger for this connection;
            defaults to ``logging.getLogger("websockets.client")``;
            see the :doc:`logging guide <../../topics/logging>` for details.

    Ni   )ÚoriginÚ
extensionsÚsubprotocolsÚstateÚmax_sizeÚloggerc               óŠ   •— t         ‰| �  t        |||¬«       || _        || _        || _        || _        t        «       | _        y )N)Úsider2   r3   r4   )	ÚsuperÚ__init__r   Úurir/   Úavailable_extensionsÚavailable_subprotocolsr,   Úkey)	Úselfr9   r/   r0   r1   r2   r3   r4   Ú	__class__s	           €úX/var/www/html/streamforge-license/venv/lib/python3.12/site-packages/websockets/client.pyr8   zClientProtocol.__init__J   sL   ø€ ô 	‰ÑÜØØØð	 	ô 	
ð ˆŒØˆŒØ$.ˆÔ!Ø&2ˆÔ#Ü“>ˆ�ó    c                ó´  — t        «       }t        | j                  j                  | j                  j                  | j                  j
                  «      |d<   | j                  j                  rt        | j                  j                  Ž |d<   | j                  �| j                  |d<   d|d<   d|d<   | j                  |d<   d|d	<   | j                  �@t        | j                  D �cg c]  }|j                  |j                  «       f‘Œ  c}«      |d
<   | j                  �t        | j                  «      |d<   t!        | j                  j"                  |«      S c c}w )a1  
        Create a handshake request to open a connection.

        You must send the handshake request with :meth:`send_request`.

        You can modify it before sending it, for example to add HTTP headers.

        Returns:
            WebSocket handshake request event to send to the server.

        ÚHostÚAuthorizationr'   Ú	websocketÚUpgradeÚ
ConnectionzSec-WebSocket-KeyÚ13zSec-WebSocket-VersionúSec-WebSocket-ExtensionsúSec-WebSocket-Protocol)r   r   r9   ÚhostÚportÚsecureÚ	user_infor   r/   r<   r:   r   ÚnameÚget_request_paramsr;   r   r   Úresource_name)r=   ÚheadersÚextension_factorys      r?   ÚconnectzClientProtocol.connecta   s5  € ô “)ˆÜ$ T§X¡X§]¡]°D·H±H·M±MÀ4Ç8Á8Ç?Á?ÓSˆ�‰Ø�8‰8×ÒÜ'@À$Ç(Á(×BTÑBTÐ'UˆG�OÑ$Ø�;‰;Ð"Ø $§¡ˆG�HÑØ(ˆ�	ÑØ )ˆ�ÑØ'+§x¡xˆÐ#Ñ$Ø+/ˆÐ'Ñ(Ø×$Ñ$Ð0Ü2Að .2×-FÑ-Föà)ð '×+Ñ+Ð->×-QÑ-QÓ-SÒTòó3ˆGÐ.Ñ/ð ×&Ñ&Ð2Ü0AØ×+Ñ+ó1ˆGÐ,Ñ-ô �t—x‘x×-Ñ-¨wÓ7Ð7ùòs   Ã$#Ec                ó,  — |j                   dk7  rt        |«      ‚|j                  }t        |j	                  d«      D �cg c]  }t        |«      ‘Œ c}g «      }t        d„ |D «       «      s#t        d|rdj                  |«      «      ‚d«      ‚t        |j	                  d«      D �cg c]  }t        |«      ‘Œ c}g «      }t        |«      dk(  r|d   j                  «       d	k(  s#t        d|rdj                  |«      «      ‚d«      ‚	 |d
   }|t        | j                   «      k7  rt#        d
|«      ‚| j%                  |«      | _        | j)                  |«      | _        yc c}w c c}w # t        $ r t        d
«      d‚t        $ r t        d
d«      d‚w xY w)zÞ
        Check a handshake response.

        Args:
            request: WebSocket handshake response received from the server.

        Raises:
            InvalidHandshake: If the handshake response is invalid.

        ée   rF   c              3  óB   K  — | ]  }|j                  «       d k(  –— Œ y­w)ÚupgradeN)Úlower)Ú.0Úvalues     r?   ú	<genexpr>z2ClientProtocol.process_response.<locals>.<genexpr>˜   s   è ø€ ÒF°%�5—;‘;“= IÕ-ÑFùs   ‚ú, NrE   r   r   rD   zSec-WebSocket-Acceptzmultiple values)Ústatus_coder   rQ   ÚsumÚget_allr   Úanyr   Újoinr   ÚlenrX   ÚKeyErrorr   r	   r+   r<   r   Úprocess_extensionsr0   Úprocess_subprotocolÚsubprotocol)r=   ÚresponserQ   rZ   Ú
connectionrW   Ú
s_w_accepts          r?   Úprocess_responsezClientProtocol.process_response„   s—  € ð ×Ñ 3Ò&Ü Ó)Ð)à×"Ñ"ˆä-0Ø29·/±/À,Ó2OÖP¨Ô˜eÕ$ÒPÐRTó.
ˆ
ô ÑF¸:ÔFÔFÜ Ø±z˜dŸi™i¨
Ó3óð ØGKóð ô *-Ø/6¯©¸yÓ/IÖJ eŒ]˜5Õ!ÒJÈBó*
ˆô
 �G“ Ò! g¨a¡j×&6Ñ&6Ó&8¸KÒ&GÜ  Á'¨D¯I©I°gÓ,>ÓTÐTÈtÓTÐTð	UØ Ð!7Ñ8ˆJð
 œ D§H¡HÓ-Ò-Ü$Ð%;¸ZÓHÐHà×1Ñ1°'Ó:ˆŒØ×3Ñ3°GÓ<ˆÕùò3 Qùò Køô ò 	BÜÐ 6Ó7¸TÐAÜ"ò 	UÜÐ 6Ð8IÓJÐPTÐTð	Uús   ¿EÂ&E#ÄE( Å(+Fc                óŒ  — g }|j                  d«      }|rš| j                  €t        d«      ‚t        |D �cg c]  }t	        |«      ‘Œ c}g «      }|D ][  \  }}| j                  D ]7  }|j
                  |k7  rŒ	 |j                  ||«      }	|j                  |	«        ŒK t        d|› d|› �«      ‚ |S c c}w # t        $ r Y Œ^w xY w)aj  
        Handle the Sec-WebSocket-Extensions HTTP response header.

        Check that each extension is supported, as well as its parameters.

        :rfc:`6455` leaves the rules up to the specification of each
        extension.

        To provide this level of flexibility, for each extension accepted by
        the server, we check for a match with each extension available in the
        client configuration. If no match is found, an exception is raised.

        If several variants of the same extension are accepted by the server,
        it may be configured several times, which won't make sense in general.
        Extensions must implement their own requirements. For this purpose,
        the list of previously accepted extensions is provided.

        Other requirements, for example related to mandatory extensions or the
        order of extensions, may be implemented by overriding this method.

        Args:
            headers: WebSocket handshake response headers.

        Returns:
            List of accepted extensions.

        Raises:
            InvalidHandshake: To abort the handshake.

        rH   zno extensions supportedzUnsupported extension: name = z, params = )r_   r:   r   r^   r   rN   Úprocess_response_paramsÚappend)
r=   rQ   Úaccepted_extensionsr0   Úheader_valueÚparsed_extensionsrN   Úresponse_paramsrR   Ú	extensions
             r?   rd   z!ClientProtocol.process_extensions±   s
  € ð> 02Ðà—_‘_Ð%?Ó@ˆ
áØ×(Ñ(Ð0Ü&Ð'@ÓAÐAä7:ØCMÖN°<” Õ.ÒNÐPRó8Ðð *;ò Ñ%��oØ)-×)BÑ)Bò Ð%à(×-Ñ-°Ò5Ø ð!Ø$5×$MÑ$MØ+Ð-@ó%˜	ð (×.Ñ.¨yÔ9ñ ð#ô, +ð"Ø"&  {°?Ð2CðEóð ð/ð8 #Ð"ùò? Oøô ,ò !Ù ð!ús   ¶B2Á8B7Â7	CÃCc                óH  — d}|j                  d«      }|r‡| j                  €t        d«      ‚t        |D �cg c]  }t	        |«      ‘Œ c}g «      }t        |«      dkD  rt        dddj                  |«      › �«      ‚|d   }|| j                  vrt        d|› �«      ‚|S c c}w )	a#  
        Handle the Sec-WebSocket-Protocol HTTP response header.

        If provided, check that it contains exactly one supported subprotocol.

        Args:
            headers: WebSocket handshake response headers.

        Returns:
           Subprotocol, if one was selected.

        NrI   zno subprotocols supportedr   zmultiple values: r\   r   zunsupported subprotocol: )r_   r;   r   r^   r   rb   r   ra   )r=   rQ   rf   r1   ro   Úparsed_subprotocolss         r?   re   z"ClientProtocol.process_subprotocolú   sÃ   € ð +/ˆà—‘Ð'?Ó@ˆáØ×*Ñ*Ð2Ü&Ð'BÓCÐCä9<ØEQÖR°\Ô" <Õ0ÒRÐTVó:Ðô Ð&Ó'¨!Ò+Ü#Ø,Ø'¨¯	©	Ð2EÓ(FÐ'GÐHóð ð
 .¨aÑ0ˆKØ $×"=Ñ"=Ñ=Ü&Ð)BÀ;À-Ð'PÓQÐQàÐùò Ss   ¶Bc                ó8  — | j                   re| j                  j                  d|j                  «       |j                  j	                  «       D ]"  \  }}| j                  j                  d||«       Œ$ | j
                  j                  |j                  «       «       y)z�
        Send a handshake request to the server.

        Args:
            request: WebSocket handshake request event.

        z> GET %s HTTP/1.1z> %s: %sN)Údebugr4   ÚpathrQ   Ú	raw_itemsÚwritesrm   Ú	serialize)r=   Úrequestr<   rZ   s       r?   Úsend_requestzClientProtocol.send_request  sw   € ð �:Š:Ø�K‰K×ÑÐ1°7·<±<Ô@Ø%Ÿo™o×7Ñ7Ó9ò :‘
��UØ—‘×!Ñ! *¨c°5Õ9ð:ð 	�‰×Ñ˜7×,Ñ,Ó.Õ/r@   c              #  óÈ  •K  — | j                   t        u �rc	 t        j                  | j                  j
                  | j                  j                  | j                  j                  «      E d {  –—† }| j"                  r¯j$                  |j&                  }}| j(                  j#                  d||«       |j*                  j-                  «       D ]"  \  }}| j(                  j#                  d||«       Œ$ |j.                  r/| j(                  j#                  dt1        |j.                  «      «       	 | j3                  «       | j                   t        u sJ ‚t<        | _         | j8                  j;                  |«       t>        ‰| �  «       E d {  –—†  y 7 �Œ## t        $ rP}|| _	        | j                  «        | j                  «       | _        t        | j                  «       d –— Y d }~�Œud }~wt        $ rj}t        d«      | _	        || j                  _        | j                  «        | j                  «       | _        t        | j                  «       d –— Y d }~�Œæd }~ww xY w# t4        $ rr}|_        | j8                  j;                  |«       || _	        | j                  «        | j                  «       | _        t        | j                  «       d –— Y d }~�Œ—d }~ww xY w7 �ŒT­w)Nz%did not receive a valid HTTP responsez< HTTP/1.1 %d %sz< %s: %sz< [body] (%d bytes)) r2   r    r   ÚparseÚreaderÚ	read_lineÚ
read_exactÚread_to_eofr   Úhandshake_excÚsend_eofÚdiscardÚparserÚnextÚ	Exceptionr   Ú	__cause__rv   r]   Úreason_phraser4   rQ   rx   Úbodyrb   rj   r
   Ú
_exceptionÚeventsrm   r!   r7   )r=   rg   ÚexcÚcodeÚphraser<   rZ   r>   s          €r?   r~   zClientProtocol.parse-  s)  øè ø€ Ø�:‰:œÒ#ðÜ&.§n¡nØ—K‘K×)Ñ)Ø—K‘K×*Ñ*Ø—K‘K×+Ñ+ó'÷ �ð* �zŠzØ'×3Ñ3°X×5KÑ5K�f�Ø—‘×!Ñ!Ð"4°d¸FÔCØ"*×"2Ñ"2×"<Ñ"<Ó">ò >‘J�C˜Ø—K‘K×%Ñ% j°#°uÕ=ð>à—=’=Ø—K‘K×%Ñ%Ð&;¼SÀÇÁÓ=OÔPð	Ø×%Ñ% hÔ/ð —:‘:¤Ñ+Ð+Ð+ÜˆDŒJØ�K‰K×Ñ˜xÔ(ä‘7‘=“?×"Ñ"ðYúô
 %ò Ø%(�Ô"Ø—‘”Ø"Ÿl™l›n�”Ü�T—[‘[Ô!ß‘ûÜò Ü%3Ø;ó&�Ô"ð 03�×"Ñ"Ô,Ø—‘”Ø"Ÿl™l›n�”Ü�T—[‘[Ô!ß‘ûðûô( $ò Ø&)�Ô#Ø—‘×"Ñ" 8Ô,Ø%(�Ô"Ø—‘”Ø"Ÿl™l›n�”Ü�T—[‘[Ô!ß‘ûðúð 	#ûsŽ   ƒK"˜AF Á.FÁ/F Á3B;K"Ä/I! Å AK"ÆKÆK"ÆF Æ	IÆAG(Ç"K"Ç(IÇ4AIÉK"ÉIÉK"É!	KÉ*A'KËK"ËKËK")r9   r*   r/   zOrigin | Noner0   z'Sequence[ClientExtensionFactory] | Noner1   zSequence[Subprotocol] | Noner2   r#   r3   z*int | None | tuple[int | None, int | None]r4   zLoggerLike | NoneÚreturnÚNone)r‘   r   )rg   r   r‘   r’   )rQ   r   r‘   zlist[Extension])rQ   r   r‘   zSubprotocol | None)r{   r   r‘   r’   )r‘   zGenerator[None])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    r8   rS   rj   rd   re   r|   r~   Ú__classcell__©r>   s   @r?   r-   r-   1   s—   ø„ ñð8 !%Ø>BØ59Ø!Ø?DØ$(ñ"àð"ð ð	"ð
 <ð"ð 3ð"ð ð"ð =ð"ð "ð"ð 
õ"ó.!8óF+=óZG#óR"óH0÷/#ñ /#r@   c                  ó    ‡ — e Zd Zdˆ fd„Zˆ xZS )ÚClientConnectionc                óX   •— t        j                  dt        «       t        ‰| �  |i |¤Ž y )Nz.ClientConnection was renamed to ClientProtocol)ÚwarningsÚwarnÚDeprecationWarningr7   r8   )r=   ÚargsÚkwargsr>   s      €r?   r8   zClientConnection.__init__`  s)   ø€ Ü�‰Ø<Üô	
ô 	‰Ñ˜$Ð) &Ó)r@   )rŸ   r   r    r   r‘   r’   )r“   r”   r•   r8   r—   r˜   s   @r?   rš   rš   _  s   ø„ ÷*ñ *r@   rš   c                óÜ   — t        | t        t        f«      ryt        | t        «      rt        | j                  t
        «      ryt        | t        «      r| j                  j                  dv ry| S )aô  
    Determine whether a connection error is retryable or fatal.

    When reconnecting automatically with ``async for ... in connect(...)``
    (:mod:`asyncio`, :mod:`trio`) or ``for ... in reconnect(...)``
    (:mod:`threading`), whenever a connection attempt fails,
    :func:`process_exception` determines whether to retry connecting or to raise
    the exception.

    This function defines the default behavior, which is to retry on:

    * :exc:`OSError` and :exc:`asyncio.TimeoutError`: network errors;
    * :exc:`~websockets.exceptions.InvalidMessage` when it stems from an
      :exc:`EOFError`: also network errors;
    * :exc:`~websockets.exceptions.InvalidStatus` when the status code is 500,
      502, 503, or 504: server or proxy errors.

    All other exceptions are considered fatal.

    You can change this behavior with the ``process_exception`` argument of
    :func:`~websockets.asyncio.client.connect` (:mod:`asyncio`),
    :func:`~websockets.trio.client.connect` (:mod:`trio`), or
    :func:`~websockets.sync.client.reconnect` (:mod:`threading`).

    Return :obj:`None` if the exception is retryable i.e. when the error could
    be transient and trying to reconnect with the same parameters could succeed.
    The exception will be logged at the ``INFO`` level.

    Return an exception, either ``exc`` or a new exception, if the exception is
    fatal i.e. when trying to reconnect will most likely produce the same error.
    That exception will be raised, breaking out of the retry loop.

    N)iô  iö  i÷  iø  )	Ú
isinstanceÚOSErrorÚTimeoutErrorr   r‰   ÚEOFErrorr   rg   r]   )rŽ   s    r?   Úprocess_exceptionr¦   h  s\   € ôF �#œ¤Ð.Ô/ØÜ�#”~Ô&¬:°c·m±mÄXÔ+NØÜ�#”}Ô%¨#¯,©,×*BÑ*Bð Gñ +ð Ø€Jr@   Ú WEBSOCKETS_BACKOFF_INITIAL_DELAYÚ5ÚWEBSOCKETS_BACKOFF_MIN_DELAYz3.1ÚWEBSOCKETS_BACKOFF_MAX_DELAYz90.0ÚWEBSOCKETS_BACKOFF_FACTORz1.618c              #  ót   K  — t        j                   «       | z  –— |}||k  r|–— ||z  }||k  rŒ	 |–— Œ­w)z—
    Generate a series of backoff delays between reconnection attempts.

    Yields:
        How many seconds to wait before retrying to connect.

    )Úrandom)Úinitial_delayÚ	min_delayÚ	max_delayÚfactorÚdelays        r?   Úbackoffr³   Ÿ  sM   è ø€ ô �-‰-‹/˜MÑ
)Ò)Ø€EØ
�)Ò
ØŠØ�‰ˆð �)Ó
ð ØŠð ùs   ‚/8²8z.legacy.client)ÚWebSocketClientProtocolrS   Úunix_connect)Údeprecated_aliases)rŽ   rˆ   r‘   zException | None)
r®   Úfloatr¯   r·   r°   r·   r±   r·   r‘   zGenerator[float])EÚ
__future__r   Úosr­   rœ   Úcollections.abcr   r   Útypingr   Údatastructuresr   r	   Ú
exceptionsr
   r   r   r   r   r   r   r   r0   r   r   rQ   r   r   r   r   r   r   r   r   Úhttp11r   r   Úimportsr   Úprotocolr   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r9   r*   Úutilsr+   r,   Ú__all__r-   rš   r¦   r·   ÚenvironÚgetÚBACKOFF_INITIAL_DELAYÚBACKOFF_MIN_DELAYÚBACKOFF_MAX_DELAYÚBACKOFF_FACTORr³   Úglobals© r@   r?   ú<module>rË      sV  ðÝ "ã 	Û Û ß /Ý ç 8÷	÷ 	ó 	÷ :÷	÷ 	ó 	÷ &Ý  ß ?Õ ?÷÷ õ ß +ð Ð
€ôk#�Xô k#ô\	*�~ô *ó.ñb ˜bŸj™jŸn™nÐ-OÐQTÓUÓVÐ Ù˜"Ÿ*™*Ÿ.™.Ð)GÈÓOÓPÐ Ù˜"Ÿ*™*Ÿ.™.Ð)GÈÓPÓQÐ Ù�r—z‘z—~‘~Ð&AÀ7ÓKÓL€ð 1Ø(Ø(Ø"ð	Øðàðð ðð ð	ð
 óñ0 ÙƒIð $4Ø#Ø(ñ	ör@   