� <��g�>��~�ddlmZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z mZddlmZmZmZmZmZmZgd�Ze d ��Zd d �dTd�ZdUd�Zejd��ZdVd�Zejd��ZdWd�Zejd��Zejd ��ZdWd!�Z ejd"��Z!ejd#��Z"dXd%�Z#dYd)�Z$dZd+�Z%d[d-�Z&ejd.��Z'd\d0�Z(d]d2�Z)d^d4�Z*d_d6�Z+d`d8�Z,e,Z-dad=�Z.dbd@�Z/e/Z0dcdB�Z1dddD�Z2e2Z3dedG�Z4e4Z5dfdI�Z6dgdK�Z7ejdL��Z8dWdM�Z9dhdN�Z:didP�Z;djdS�Z<dS)k�)� annotationsN)�Sequence)�Callable�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�TF)�always_include_port�host�str�port�int�secure�boolr�returnc�� tj|��}|jdkrd|�d�}n#t$rYnwxYw|s ||rdndkr|�d|��}|S)z# Build a ``Host`` header. ��[�]i��P�:)� ipaddress� ip_address�version� ValueError)rr r"r�addresss �b/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/websockets/headers.pyrr's�����&�t�,�,�� �?�a� � ��t�;�;�;�D��� � � � � �� ����� �d�f�'<�s�s�"�=�=�������� �Ks �(� 5�5�header�pos� str | Nonec�<�|t|��krdn||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)r1r2s r0� peek_aheadr6Is"���#�f�+�+�%�%�4�4�6�#�;�6�z[\t ]*c�h�t�||��}|�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)r1r2r:s r0� parse_OWSr<Xs1�� �M�M�&�#� &� &�E� � � � � �9�9�;�;�r7z[-!#$%&\'*+.^_`|~0-9a-zA-Z]+� header_name�tuple[str, int]c��t�||��}|�t|d||���|���|���fS)z� Parse a token from ``header`` at the given position. Return the token value and the new position. Raises: InvalidHeaderFormat: On invalid inputs. Nzexpected token)� _token_rer:r �groupr;�r1r2r=r:s r0� parse_tokenrCjsL�� �O�O�F�C� (� (�E� �}�!�+�/?���M�M�M� �;�;�=�=�%�)�)�+�+� %�%r7zC"(?:[\x09\x20-\x21\x23-\x5b\x5d-\x7e]|\\[\x09\x20-\x7e\x80-\xff])*"z\\([\x09\x20-\x7e\x80-\xff])c���t�||��}|�t|d||���t�d|���dd���|���fS)z� Parse a quoted string from ``header`` at the given position. Return the unquoted value and the new position. Raises: InvalidHeaderFormat: On invalid inputs. Nzexpected quoted stringz\1r�����)�_quoted_string_rer:r � _unquote_re�subrAr;rBs r0�parse_quoted_stringrI�sf�� � #� #�F�C� 0� 0�E� �}�!�+�/G��QT�U�U�U� �?�?�5�%�+�+�-�-��"��"5� 6� 6�� � � � � C�Cr7z[\x09\x20-\x7e\x80-\xff]*z ([\x22\x5c])�valuec��t�|��}|�td���dt�d|��zdzS)zh Format ``value`` as a quoted string. This is the reverse of :func:`parse_quoted_string`. Nz-invalid characters for quoted-string encoding�"z\\\1)� _quotable_re� fullmatchr.� _quote_rerH)rJr:s r0�build_quoted_stringrP�sI�� � "� "�5� )� )�E� �}��H�I�I�I� ����w��.�.� .�� 4�4r7� parse_item�(Callable[[str, int, str], tuple[T, int]]�list[T]c�R�t||��dkr't||dz��}t||��dk�'g} ||||��\}}|�|��t||��}|t|��krn�t||��dkrt||dz��}nt |d||���t||��dkr't||dz��}t||��dk�'|t|��krn��|t|��ksJ�|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. �,rTzexpected comma)r6r<�appendr5r )rQr1r2r=�items�items r0� parse_listrY�sX��> �V�S� !� !�S� (� (����a��(�(�� �V�S� !� !�S� (� (� �E���J�v�s�K�8�8� ��c� � � �T�������$�$�� �#�f�+�+� � � � �f�c� "� "�c� )� )��F�C�!�G�,�,�C�C�%�k�3C�V�S�Q�Q� Q����%�%��,�,��F�C�!�G�,�,�C����%�%��,�,� �#�f�+�+� � � �-�4 �#�f�+�+� � � � � �Lr7�tuple[ConnectionOption, int]c�X�t|||��\}}tt|��|fS)z� Parse a Connection option from ``header`` at the given position. Return the protocol value and the new position. Raises: InvalidHeaderFormat: On invalid inputs. )rCrr �r1r2r=rXs r0�parse_connection_optionr]�s/���F�C��5�5�I�D�#� � �$� '� '�� ,�,r7�list[ConnectionOption]c�0�tt|dd��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)rYr]�r1s r0rr�s�� �-�v�q�,� G� G�Gr7z>[-!#$%&\'*+.^_`|~0-9a-zA-Z]+(?:/[-!#$%&\'*+.^_`|~0-9a-zA-Z]+)?�tuple[UpgradeProtocol, int]c���t�||��}|�t|d||���tt|�����|���fS)z� Parse an Upgrade protocol from ``header`` at the given position. Return the protocol value and the new position. Raises: InvalidHeaderFormat: On invalid inputs. Nzexpected protocol)� _protocol_rer:r rrrAr;rBs r0�parse_upgrade_protocolre sX�� � � �v�s� +� +�E� �}�!�+�/B�F�C�P�P�P� ������� /� /������ <�<r7�list[UpgradeProtocol]c�0�tt|dd��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)rYreras r0rrs�� �,�f�a�� C� C�Cr7�tuple[ExtensionParameter, int]c��t|||��\}}t||��}d}t||��dkr�t||dz��}t||��dkrC|}t|||��\}}t�|���t |d||���nt|||��\}}t||��}||f|fS)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�=rrLzinvalid quoted header content)rCr<r6rIr@rNr )r1r2r=�namerJ� pos_befores r0�parse_extension_item_paramrn.s����F�C��5�5�I�D�#� �F�C� � �C��E��&�#���#�%�%����a��(�(�� �f�c� "� "�c� )� )��J�,�V�S�+�F�F�J�E�3��"�"�5�)�)�1�)��!@�&�*����2� %�V�S�+�>�>�J�E�3����$�$�� �%�=�#� �r7�tuple[ExtensionHeader, int]c�H�t|||��\}}t||��}g}t||��dkrPt||dz��}t|||��\}}|�|��t||��dk�Pt t |��|f|fS)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)rCr<r6rnrVrr )r1r2r=rl� parameters� parameters r0�parse_extension_itemrtRs����F�C��5�5�I�D�#� �F�C� � �C��J� �V�S� !� !�S� (� (����a��(�(��3�F�C��M�M�� �3����)�$�$�$� �V�S� !� !�S� (� (� ��� %� %�z� 2�C� 7�7r7�list[ExtensionHeader]c�0�tt|dd��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. rzSec-WebSocket-Extensions)rYrtras r0rrks��. �*�F�A�7Q� R� R�Rr7rlr rr�Sequence[ExtensionParameter]c�n�d�tt|��gd�|D��z��S)zc Build an extension definition. This is the reverse of :func:`parse_extension_item`. z; c�*�g|]\}}|�|n|�d|����S)Nrk�)�.0rlrJs r0� <listcomp>z(build_extension_item.<locals>.<listcomp>�sD�� � � ���e��M�D�D�$�'8�'8��'8�'8� � � r7)�joinrr)rlrrs r0�build_extension_itemr~�sK�� �9�9� �c�4���� � � *� � � � � � �r7� extensions�Sequence[ExtensionHeader]c�@�d�d�|D����S)zl Build a ``Sec-WebSocket-Extensions`` header. This is the reverse of :func:`parse_extension`. �, c3�<K�|]\}}t||��V��dS)N)r~)r{rlrrs r0� <genexpr>z"build_extension.<locals>.<genexpr>�sB������3C�4���T�:�.�.������r7�r})rs r0rr�s6�� �9�9���GQ���� � �r7�tuple[Subprotocol, int]c�X�t|||��\}}tt|��|fS)z� Parse a subprotocol from ``header`` at the given position. Return the subprotocol value and the new position. Raises: InvalidHeaderFormat: On invalid inputs. )rCrrr\s r0�parse_subprotocol_itemr��s.���F�C��5�5�I�D�#� � �T� "� "�C� '�'r7�list[Subprotocol]c�0�tt|dd��S)z� Parse a ``Sec-WebSocket-Protocol`` header. Return a list of WebSocket subprotocols. Raises: InvalidHeaderFormat: On invalid inputs. rzSec-WebSocket-Protocol)rYr�ras r0rr�s�� �,�f�a�9Q� R� R�Rr7� subprotocols�Sequence[Subprotocol]c�,�d�|��S)zl Build a ``Sec-WebSocket-Protocol`` header. This is the reverse of :func:`parse_subprotocol`. r�r�)r�s r0rr�s�� �9�9�\� "� "�"r7�Nonec���t|t��std���t|t��rtd���|D].}t�|��st d|������/dS)zT Validate that ``subprotocols`` is suitable for :func:`build_subprotocol`. zsubprotocols must be a listz&subprotocols must be a list, not a strzinvalid subprotocol: N)� isinstancer� TypeErrorrr@rNr.)r�� subprotocols r0rr�s��� �l�H� -� -�7��5�6�6�6��,��$�$�B��@�A�A�A�#�D�D� ��"�"�;�/�/� D��B�[�B�B�C�C� C� D�D�Dr7�realmc�N�t|��}td��}d|�d|��S)z� Build a ``WWW-Authenticate`` header for HTTP Basic Auth. Args: realm: Identifier of the protection space. zUTF-8z Basic realm=z , charset=)rP)r��charsets r0rr�s4�� �� &� &�E�!�'�*�*�G� 4�%� 4� 4�7� 4� 4�4r7z[A-Za-z0-9-._~+/]+=*c��t�||��}|�t|d||���|���|���fS)z� Parse a token68 from ``header`` at the given position. Return the token value and the new position. Raises: InvalidHeaderFormat: On invalid inputs. Nzexpected token68)� _token68_rer:r rAr;rBs r0� parse_token68r��sN�� � � �f�c� *� *�E� �}�!�+�/A�6�3�O�O�O� �;�;�=�=�%�)�)�+�+� %�%r7c�P�|t|��krt|d||���dS)z8 Check that parsing reached the end of header. z trailing dataN)r5r )r1r2r=s r0� parse_endr�s1��  �S��[�[���!�+����L�L�L��r7�tuple[str, str]c�X�t|dd��\}}|���dkrtdd|�����t||��dkrt dd||���|dz }t ||d��\}}t ||d�� tj|� ����� ��}n$#tj $rtdd��d �wxYw |� d d��\}}n#t$rtdd ��d �wxYw||fS) 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�basiczunsupported scheme: � zexpected space after schemerz#expected base64-encoded credentialsNr*z&expected username:password credentials)rC�lowerr r6r r�r��base64� b64decode�encode�decode�binascii�Error�splitr.)r1�schemer2�basic_credentials� user_pass�username�passwords r0rrs��� �f�a��9�9�K�F�C� �|�|�~�~�� � � � � +�6� +� +� � � ��&�#���#�%�%�!� �:�F�C� � � ��1�H�C�*�6�3��H�H���s� �f�c�?�+�+�+���$�%6�%=�%=�%?�%?�@�@�G�G�I�I� � �� �>���� � � 1� � �� ����� �&�_�_�S�!�4�4���(�(�� ���� � � 4� � �� ����� �X� �s�8C � !C+�/D � D%r�r�c��d|vsJ�|�d|��}tj|��������}d|zS)z� Build an ``Authorization`` header for HTTP Basic Auth. This is the reverse of :func:`parse_authorization_basic`. r*zBasic )r�� b64encoder�r�)r�r�r�r�s r0rr?s]�� �h� � � � ��(�(�h�(�(�I��(��)9�)9�);�);�<�<�C�C�E�E�� �'� '�'r7) rrr r!r"r#rr#r$r)r1rr2r!r$r3)r1rr2r!r$r!)r1rr2r!r=rr$r>)rJrr$r) rQrRr1rr2r!r=rr$rS)r1rr2r!r=rr$rZ)r1rr$r^)r1rr2r!r=rr$rb)r1rr$rf)r1rr2r!r=rr$ri)r1rr2r!r=rr$ro)r1rr$ru)rlr rrrwr$r)rr�r$r)r1rr2r!r=rr$r�)r1rr$r�)r�r�r$r)r�r�r$r�)r�rr$r)r1rr2r!r=rr$r�)r1rr$r�)r�rr�rr$r)=� __future__rr�r�r+�re�collections.abcr�typingrrr� exceptionsr r r r r rrr�__all__rrr6�compiler9r<r@rCrFrGrIrMrOrPrYr]rrdrerrnrtr�parse_extension_listr~r�build_extension_listr�r�parse_subprotocol_listr�build_subprotocol_listrrr�r�r�rrrzr7r0�<module>r�s���"�"�"�"�"�"� � � � ��������� � � � �$�$�$�$�$�$�*�*�*�*�*�*�*�*�*�*�?�?�?�?�?�?�?�?����������������� � � �� �G�C�L�L��!&� ������D 7� 7� 7� 7� �"�*�Y� � �� � � � � �B�J�6� 7� 7� � &� &� &� &� �B�J�J���� �b�j�8�9�9� � D� D� D� D� �r�z�6�7�7� � �B�J�� '� '� � 5� 5� 5� 5�?�?�?�?�D -� -� -� -� H� H� H� H� �r�z�E��� � =�=�=�=�$ D� D� D� D� !�!�!�!�H8�8�8�8�2S�S�S�S�4'������& � � � �'�� (� (� (� (� S� S� S� S�+��#�#�#�#�+�� D� D� D� D� 5� 5� 5� 5��b�j�0�1�1� � &� &� &� &� M�M�M�M�-�-�-�-�` (� (� (� (� (� (r7
Memory