Ë
    Ûvžj;>  ã                  óø  — d dl mZ d dlZd dlZd dlZd dlZd dl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 g d¢Z e	d«      Zd*d	„Zd+d
„Z ej0                  d«      Zd,d„Z ej0                  d«      Zd-d„Z ej0                  d«      Z ej0                  d«      Zd-d„Z ej0                  d«      Z  ej0                  d«      Z!d.d„Z"	 	 	 	 	 	 	 	 	 	 d/d„Z#	 	 	 	 	 	 	 	 d0d„Z$d1d„Z% ej0                  d«      Z&	 	 	 	 	 	 	 	 d2d„Z'd3d„Z(	 	 	 	 	 	 	 	 d4d„Z)	 	 	 	 	 	 	 	 d5d„Z*d6d„Z+e+Z,	 	 	 	 	 	 d7d„Z-d8d„Z.e.Z/	 	 	 	 	 	 	 	 d9d „Z0d:d!„Z1e1Z2d;d"„Z3e3Z4d<d#„Z5d=d$„Z6 ej0                  d%«      Z7d-d&„Z8d>d'„Z9d?d(„Z:d@d)„Z;y)Aé    )ÚannotationsN)ÚCallableÚSequenceÚTypeVarÚcasté   )ÚInvalidHeaderFormatÚInvalidHeaderValue)ÚConnectionOptionÚExtensionHeaderÚExtensionNameÚExtensionParameterÚSubprotocolÚUpgradeProtocol)Ú
build_hostÚparse_connectionÚparse_upgradeÚparse_extensionÚbuild_extensionÚparse_subprotocolÚbuild_subprotocolÚvalidate_subprotocolsÚbuild_www_authenticate_basicÚparse_authorization_basicÚbuild_authorization_basicÚTc                óœ   — 	 t        j                  | «      }|j                  dk(  rd| › d�} 	 ||rdndk7  r| › d|› �} | S # t        $ r Y Œw xY w)z#
    Build a ``Host`` header.

    é   Ú[Ú]i»  éP   Ú:)Ú	ipaddressÚ
ip_addressÚversionÚ
ValueError)ÚhostÚportÚsecureÚaddresss       úc/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/websockets/headers.pyr   r   &   sg   € ðÜ×&Ñ& tÓ,ˆð �?‰?˜aÒØ�t�f˜A�;‰Dà‘v‘ 2Ò&Ø��q˜˜Ðˆà€Køô ò áðús   ‚? ¿	AÁ
Ac                ó,   — |t        | «      k(  rdS | |   S )z·
    Return the next character from ``header`` at the given position.

    Return :obj:`None` at the end of ``header``.

    We never need to peek more than one character ahead.

    N)Úlen)ÚheaderÚposs     r+   Ú
peek_aheadr0   B   s   € ð œ#˜f›+Ò%ˆ4Ð6¨6°#©;Ð6ó    z[\t ]*c                óV   — t         j                  | |«      }|€J ‚|j                  «       S )z±
    Parse optional whitespace from ``header`` at the given position.

    Return the new position.

    The whitespace itself isn't returned because it isn't significant.

    )Ú_OWS_reÚmatchÚend)r.   r/   r4   s      r+   Ú	parse_OWSr6   Q   s,   € ô �M‰M˜& #Ó&€EØÐÐÐØ�9‰9‹;Ðr1   z[-!#$%&\'*+.^_`|~0-9a-zA-Z]+c                óŽ   — t         j                  | |«      }|€t        |d| |«      ‚|j                  «       |j	                  «       fS )z®
    Parse a token from ``header`` at the given position.

    Return the token value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    zexpected token)Ú	_token_rer4   r	   Úgroupr5   ©r.   r/   Úheader_namer4   s       r+   Úparse_tokenr<   c   sB   € ô �O‰O˜F CÓ(€EØ€}Ü! +Ð/?ÀÈÓMÐMØ�;‰;‹=˜%Ÿ)™)›+Ð%Ð%r1   zC"(?:[\x09\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x09\x20-\x7e\x80-\xff])*"z\\([\x09\x20-\x7e\x80-\xff])c                ó¼   — t         j                  | |«      }|€t        |d| |«      ‚t        j	                  d|j                  «       dd «      |j                  «       fS )z¹
    Parse a quoted string from ``header`` at the given position.

    Return the unquoted value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    zexpected quoted stringz\1r   éÿÿÿÿ)Ú_quoted_string_rer4   r	   Ú_unquote_reÚsubr9   r5   r:   s       r+   Úparse_quoted_stringrB   {   sW   € ô ×#Ñ# F¨CÓ0€EØ€}Ü! +Ð/GÈÐQTÓUÐUÜ�?‰?˜5 %§+¡+£-°°"Ð"5Ó6¸¿	¹	»ÐCÐCr1   z[\x09\x20-\x7e\x80-\xff]*z([\x22\x5c])c                ó~   — t         j                  | «      }|€t        d«      ‚dt        j	                  d| «      z   dz   S )zh
    Format ``value`` as a quoted string.

    This is the reverse of :func:`parse_quoted_string`.

    z-invalid characters for quoted-string encodingÚ"z\\\1)Ú_quotable_reÚ	fullmatchr&   Ú	_quote_rerA   )Úvaluer4   s     r+   Úbuild_quoted_stringrI   ‘   s@   € ô ×"Ñ" 5Ó)€EØ€}ÜÐHÓIÐIØ”—‘˜w¨Ó.Ñ.°Ñ4Ð4r1   c                óÐ  — t        ||«      dk(  rt        ||dz   «      }t        ||«      dk(  rŒg }	  | |||«      \  }}|j                  |«       t        ||«      }|t        |«      k(  rnkt        ||«      dk(  rt        ||dz   «      }nt	        |d||«      ‚t        ||«      dk(  rt        ||dz   «      }t        ||«      dk(  rŒ|t        |«      k(  rnŒ¤|t        |«      k(  sJ ‚|S )aö  
    Parse a comma-separated list from ``header`` at the given position.

    This is appropriate for parsing values with the following grammar:

        1#item

    ``parse_item`` parses one item.

    ``header`` is assumed not to start or end with whitespace.

    (This function is designed for parsing an entire header value and
    :func:`~websockets.http.read_headers` strips whitespace from values.)

    Return a list of items.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    Ú,r   zexpected comma)r0   r6   Úappendr-   r	   )Ú
parse_itemr.   r/   r;   ÚitemsÚitems         r+   Ú
parse_listrP   ž   s  € ô> �V˜SÓ
! SÒ
(Ü˜  a¡Ó(ˆô �V˜SÓ
! SÓ
(ð €EØ
á˜v s¨KÓ8‰	ˆˆcØ�‰�TÔÜ˜ Ó$ˆð ”#�f“+ÒØô �f˜cÓ" cÒ)Ü˜F C¨!¡GÓ,‰Cä% kÐ3CÀVÈSÓQÐQô ˜ Ó%¨Ò,Ü˜F C¨!¡GÓ,ˆCô ˜ Ó%¨Ó,ð ”#�f“+ÒØð- ð4 ”#�f“+ÒÐÐà€Lr1   c                óF   — t        | ||«      \  }}t        t        |«      |fS )z½
    Parse a Connection option from ``header`` at the given position.

    Return the protocol value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    )r<   r   r   ©r.   r/   r;   rO   s       r+   Úparse_connection_optionrS   à   s)   € ô ˜F C¨Ó5�I€Dˆ#ÜÔ  $Ó'¨Ð,Ð,r1   c                ó&   — t        t        | dd«      S )zÓ
    Parse a ``Connection`` header.

    Return a list of HTTP connection options.

    Args
        header: value of the ``Connection`` header.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    r   Ú
Connection)rP   rS   ©r.   s    r+   r   r   ð   s   € ô Ô-¨v°q¸,ÓGÐGr1   z>[-!#$%&\'*+.^_`|~0-9a-zA-Z]+(?:/[-!#$%&\'*+.^_`|~0-9a-zA-Z]+)?c                óª   — t         j                  | |«      }|€t        |d| |«      ‚t        t        |j                  «       «      |j                  «       fS )z½
    Parse an Upgrade protocol from ``header`` at the given position.

    Return the protocol value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    zexpected protocol)Ú_protocol_rer4   r	   r   r   r9   r5   r:   s       r+   Úparse_upgrade_protocolrY     sK   € ô ×Ñ˜v sÓ+€EØ€}Ü! +Ð/BÀFÈCÓPÐPÜ” §¡£Ó/°·±³Ð<Ð<r1   c                ó&   — t        t        | dd«      S )zÆ
    Parse an ``Upgrade`` header.

    Return a list of HTTP protocols.

    Args:
        header: Value of the ``Upgrade`` header.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    r   ÚUpgrade)rP   rY   rV   s    r+   r   r     s   € ô Ô,¨f°a¸ÓCÐCr1   c                óF  — t        | ||«      \  }}t        | |«      }d}t        | |«      dk(  rot        | |dz   «      }t        | |«      dk(  r5|}t        | ||«      \  }}t        j                  |«      €t        |d| |«      ‚t        | ||«      \  }}t        | |«      }||f|fS )zÌ
    Parse a single extension parameter from ``header`` at the given position.

    Return a ``(name, value)`` pair and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    NÚ=r   rD   zinvalid quoted header content)r<   r6   r0   rB   r8   rF   r	   )r.   r/   r;   ÚnamerH   Ú
pos_befores         r+   Úparse_extension_item_paramr`   '  sÅ   € ô ˜F C¨Ó5�I€Dˆ#Ü
�F˜CÓ
 €Cà€EÜ�&˜#Ó #Ò%Ü˜  a¡Ó(ˆÜ�f˜cÓ" cÒ)ØˆJÜ,¨V°S¸+ÓF‰JˆE�3ô ×"Ñ" 5Ó)Ð1Ü)ØÐ!@À&È*óð ô % V¨S°+Ó>‰JˆE�3Ü˜ Ó$ˆà�%ˆ=˜#ÐÐr1   c                ó  — t        | ||«      \  }}t        | |«      }g }t        | |«      dk(  r@t        | |dz   «      }t        | ||«      \  }}|j	                  |«       t        | |«      dk(  rŒ@t        t        |«      |f|fS )a  
    Parse an extension definition from ``header`` at the given position.

    Return an ``(extension name, parameters)`` pair, where ``parameters`` is a
    list of ``(name, value)`` pairs, and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    Ú;r   )r<   r6   r0   r`   rL   r   r   )r.   r/   r;   r^   Ú
parametersÚ	parameters         r+   Úparse_extension_itemre   K  s�   € ô ˜F C¨Ó5�I€Dˆ#Ü
�F˜CÓ
 €Cà€JÜ
�V˜SÓ
! SÒ
(Ü˜  a¡Ó(ˆÜ3°F¸CÀÓM‰ˆ	�3Ø×Ñ˜)Ô$ô �V˜SÓ
! SÓ
(ô ” Ó% zÐ2°CÐ7Ð7r1   c                ó&   — t        t        | dd«      S )aâ  
    Parse a ``Sec-WebSocket-Extensions`` header.

    Return a list of WebSocket extensions and their parameters in this format::

        [
            (
                'extension name',
                [
                    ('parameter name', 'parameter value'),
                    ....
                ]
            ),
            ...
        ]

    Parameter values are :obj:`None` when no value is provided.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    r   zSec-WebSocket-Extensions)rP   re   rV   s    r+   r   r   d  s   € ô. Ô*¨F°AÐ7QÓRÐRr1   c           
     óŒ   — dj                  t        t        | «      g|D � �cg c]  \  } }|€| n| › d|› �‘Œ c}} z   «      S c c}} w )zc
    Build an extension definition.

    This is the reverse of :func:`parse_extension_item`.

    z; r]   )Újoinr   Ústr)r^   rc   rH   s      r+   Úbuild_extension_itemrj   �  sb   € ð �9‰9Ü	Œc�4‹Ðñ  *ô
ñ  *‘��eð �M‰D¨$¨¨q°°Ð'8Ñ8Ø)ò
ñ	
óð ùó
s   ¡A c                ó2   — dj                  d„ | D «       «      S )zl
    Build a ``Sec-WebSocket-Extensions`` header.

    This is the reverse of :func:`parse_extension`.

    ú, c              3  ó:   K  — | ]  \  }}t        ||«      –— Œ y ­w)N)rj   )Ú.0r^   rc   s      r+   Ú	<genexpr>z"build_extension.<locals>.<genexpr>›  s!   è ø€ ð ÙGQÑ3C°4¸Ô˜T :×.Ázùs   ‚©rh   )Ú
extensionss    r+   r   r   ”  s"   € ð �9‰9ñ ÙGQóó ð r1   c                óF   — t        | ||«      \  }}t        t        |«      |fS )zº
    Parse a subprotocol from ``header`` at the given position.

    Return the subprotocol value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    )r<   r   r   rR   s       r+   Úparse_subprotocol_itemrs   £  s(   € ô ˜F C¨Ó5�I€Dˆ#Ü”˜TÓ" CÐ'Ð'r1   c                ó&   — t        t        | dd«      S )z 
    Parse a ``Sec-WebSocket-Protocol`` header.

    Return a list of WebSocket subprotocols.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    r   zSec-WebSocket-Protocol)rP   rs   rV   s    r+   r   r   ³  s   € ô Ô,¨f°aÐ9QÓRÐRr1   c                ó$   — dj                  | «      S )zl
    Build a ``Sec-WebSocket-Protocol`` header.

    This is the reverse of :func:`parse_subprotocol`.

    rl   rp   )Úsubprotocolss    r+   r   r   Ã  s   € ð �9‰9�\Ó"Ð"r1   c                óÄ   — t        | t        «      st        d«      ‚t        | t        «      rt        d«      ‚| D ]%  }t        j                  |«      rŒt        d|› �«      ‚ y)zT
    Validate that ``subprotocols`` is suitable for :func:`build_subprotocol`.

    zsubprotocols must be a listz&subprotocols must be a list, not a strzinvalid subprotocol: N)Ú
isinstancer   Ú	TypeErrorri   r8   rF   r&   )rv   Úsubprotocols     r+   r   r   Ð  s[   € ô
 �l¤HÔ-ÜÐ5Ó6Ð6Ü�,¤Ô$ÜÐ@ÓAÐAÛ#ˆÜ×"Ñ" ;Õ/ÜÐ4°[°MÐBÓCÐCñ $r1   c                ó>   — t        | «      } t        d«      }d| › d|› �S )z�
    Build a ``WWW-Authenticate`` header for HTTP Basic Auth.

    Args:
        realm: Identifier of the protection space.

    zUTF-8zBasic realm=z
, charset=)rI   )ÚrealmÚcharsets     r+   r   r   Þ  s+   € ô   Ó&€EÜ! 'Ó*€GØ˜%˜ 
¨7¨)Ð4Ð4r1   z[A-Za-z0-9-._~+/]+=*c                óŽ   — t         j                  | |«      }|€t        |d| |«      ‚|j                  «       |j	                  «       fS )z°
    Parse a token68 from ``header`` at the given position.

    Return the token value and the new position.

    Raises:
        InvalidHeaderFormat: On invalid inputs.

    zexpected token68)Ú_token68_rer4   r	   r9   r5   r:   s       r+   Úparse_token68r€   ï  sD   € ô ×Ñ˜f cÓ*€EØ€}Ü! +Ð/AÀ6È3ÓOÐOØ�;‰;‹=˜%Ÿ)™)›+Ð%Ð%r1   c                ó<   — |t        | «      k  rt        |d| |«      ‚y)z8
    Check that parsing reached the end of header.

    ztrailing dataN)r-   r	   )r.   r/   r;   s      r+   Ú	parse_endr‚   ÿ  s&   € ð
 ŒS�‹[ÒÜ! +¨ÀÈÓLÐLð r1   c                óø  — t        | dd«      \  }}|j                  «       dk7  rt        dd|› �«      ‚t        | |«      dk7  rt	        dd| |«      ‚|dz  }t        | |d«      \  }}t        | |d«       	 t        j                  |j                  «       «      j                  «       }	 |j                  d
d«      \  }}||fS # t        j                  $ r t        dd«      d	‚w xY w# t        $ r t        dd«      d	‚w xY w)a!  
    Parse an ``Authorization`` header for HTTP Basic Auth.

    Return a ``(username, password)`` tuple.

    Args:
        header: Value of the ``Authorization`` header.

    Raises:
        InvalidHeaderFormat: On invalid inputs.
        InvalidHeaderValue: On unsupported inputs.

    r   ÚAuthorizationÚbasiczunsupported scheme: Ú zexpected space after schemer   z#expected base64-encoded credentialsNr"   z&expected username:password credentials)r<   Úlowerr
   r0   r	   r€   r‚   Úbase64Ú	b64decodeÚencodeÚdecodeÚbinasciiÚErrorÚsplitr&   )r.   Úschemer/   Úbasic_credentialsÚ	user_passÚusernameÚpasswords          r+   r   r     s5  € ô  ˜f a¨Ó9�K€FˆCØ‡|�|ƒ~˜Ò Ü ØØ" 6 (Ð+ó
ð 	
ô �&˜#Ó #Ò%Ü!ØÐ:¸FÀCó
ð 	
ð ˆ1�H€CÜ*¨6°3¸ÓHÑÐ�sÜˆf�c˜?Ô+ðÜ×$Ñ$Ð%6×%=Ñ%=Ó%?Ó@×GÑGÓIˆ	ðØ&Ÿ_™_¨S°!Ó4Ñˆ�(ð �XÐÐøô �>‰>ò Ü ØØ1ó
ð ð	ðûô ò Ü ØØ4ó
ð ð	ðús   Á31B> Â%C" Â>!CÃ"C9c                óˆ   — d| vsJ ‚| › d|› �}t        j                  |j                  «       «      j                  «       }d|z   S )z€
    Build an ``Authorization`` header for HTTP Basic Auth.

    This is the reverse of :func:`parse_authorization_basic`.

    r"   zBasic )rˆ   Ú	b64encoderŠ   r‹   )r’   r“   r‘   r�   s       r+   r   r   8  sQ   € ð �hÑÐÐØ�*˜A˜h˜ZÐ(€IÜ×(Ñ(¨×)9Ñ)9Ó);Ó<×CÑCÓEÐØÐ'Ñ'Ð'r1   )r'   ri   r(   Úintr)   ÚboolÚreturnri   )r.   ri   r/   r–   r˜   z
str | None)r.   ri   r/   r–   r˜   r–   )r.   ri   r/   r–   r;   ri   r˜   ztuple[str, int])rH   ri   r˜   ri   )
rM   z(Callable[[str, int, str], tuple[T, int]]r.   ri   r/   r–   r;   ri   r˜   zlist[T])r.   ri   r/   r–   r;   ri   r˜   ztuple[ConnectionOption, int])r.   ri   r˜   zlist[ConnectionOption])r.   ri   r/   r–   r;   ri   r˜   ztuple[UpgradeProtocol, int])r.   ri   r˜   zlist[UpgradeProtocol])r.   ri   r/   r–   r;   ri   r˜   ztuple[ExtensionParameter, int])r.   ri   r/   r–   r;   ri   r˜   ztuple[ExtensionHeader, int])r.   ri   r˜   zlist[ExtensionHeader])r^   r   rc   zlist[ExtensionParameter]r˜   ri   )rq   zSequence[ExtensionHeader]r˜   ri   )r.   ri   r/   r–   r;   ri   r˜   ztuple[Subprotocol, int])r.   ri   r˜   zlist[Subprotocol])rv   úSequence[Subprotocol]r˜   ri   )rv   r™   r˜   ÚNone)r|   ri   r˜   ri   )r.   ri   r/   r–   r;   ri   r˜   rš   )r.   ri   r˜   ztuple[str, str])r’   ri   r“   ri   r˜   ri   )<Ú
__future__r   rˆ   rŒ   r#   ÚreÚtypingr   r   r   r   Ú
exceptionsr	   r
   r   r   r   r   r   r   Ú__all__r   r   r0   Úcompiler3   r6   r8   r<   r?   r@   rB   rE   rG   rI   rP   rS   r   rX   rY   r   r`   re   r   Úparse_extension_listrj   r   Úbuild_extension_listrs   r   Úparse_subprotocol_listr   Úbuild_subprotocol_listr   r   r   r€   r‚   r   r   © r1   r+   Ú<module>r¦      sa  ðÝ "ã Û Û Û 	ß 4Ó 4ç ?÷÷ ò€ñ ˆCƒL€óó8	7ð ˆ"�*‰*�YÓ
€óð ˆB�J‰JÐ6Ó7€	ó&ð  �B—J‘JØJóÐ ð
 ˆb�j‰jÐ8Ó9€óDð  ˆr�z‰zÐ6Ó7€ð ˆB�J‰J�Ó'€	ó
5ð?Ø8ð?àð?ð 
ð?ð ð	?ð
 ó?ðD-Øð-Øð-Ø(+ð-à!ó-ó Hð  ˆr�z‰zØEó€ð
=Øð=Øð=Ø(+ð=à ó=ó$Dð !Øð!Øð!Ø(+ð!à#ó!ðH8Øð8Øð8Ø(+ð8à ó8ó2Sð4 'Ð ðØ
ðØ%=ðàóó&	ð 'Ð ð(Øð(Øð(Ø(+ð(àó(ó 
Sð +Ð ó#ð +Ð óDó5ð ˆb�j‰jÐ0Ó1€ó&ó Mó-ô`(r1   