� <��g�����ddlmZddlZddlmZmZddlmZmZm Z ddl m Z m Z ddl mZmZddl mZdd lmZ dd lmZn#e$r dd lmZYnwxYwGd �d e ��Zdd�Zdd�ZeZddl mZdd�Zdd�ZdS) �)� annotationsN)� Awaitable�Sequence)�Any�Callable� NamedTuple�)� extensions�frames)� PayloadTooBig� ProtocolError)� BytesLike)�Data)� apply_maskc��eZdZUded<ded<ded<dZded<dZded <dZded <ed d ���Zd!d�Z d"d�Z e ddd�d#d���Z dd�d$d�Z dS)%�Frame�bool�finz frames.Opcode�opcode�bytes�dataF�rsv1�rsv2�rsv3�return� frames.Framec�p�tj|j|j|j|j|j|j��S�N)r rrrrrrr��selfs �i/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/websockets/legacy/framing.py� new_framezFrame.new_frames4���|� �K� �I� �H� �I� �I� �I�  � � ��strc�*�t|j��Sr)r$r"rs r!�__str__z Frame.__str__&s���4�>�"�"�"r#�Nonec�4�|j���Sr)r"�checkrs r!r)z Frame.check)s���~�#�#�%�%�%r#N)�max_sizer �reader�!Callable[[int], Awaitable[bytes]]�maskr*� int | Noner �%Sequence[extensions.Extension] | Nonec��K�|d���d{V��}tjd|��\}}|dzrdnd}|dzrdnd} |dzrdnd} |d zrdnd} tj|d z��} n"#t$r} t d ��| �d} ~ wwxYw|dzrdnd|krt d ���|d z}|dkr)|d���d{V��}tjd|��\}n.|d kr(|d���d{V��}tjd|��\}|�||krt ||���|r|d���d{V��}||���d{V��}|rt||��}tj| ||| | | ��}|�g}t|��D]}|� ||���}�|� ��||j |j |j|j|j|j��S)a@ Read a WebSocket frame. Args: reader: Coroutine that reads exactly the requested number of bytes, unless the end of file is reached. mask: Whether the frame should be masked i.e. whether the read happens on the server side. max_size: Maximum payload size in bytes. extensions: List of extensions, applied in reverse order. Raises: PayloadTooBig: If the frame exceeds ``max_size``. ProtocolError: If the frame contains incorrect values. r Nz!BB�TF�@� ��zinvalid opcodezincorrect masking��~z!H�z!Q�)r*)�struct�unpackr �Opcode� ValueErrorr r rr�reversed�decoder)rrrrrr)�clsr+r-r*r r�head1�head2rrrrr�exc�length� mask_bitsr"� extensions r!�readz Frame.read,s�����6�V�A�Y�Y���������}�U�D�1�1� ��u��j�(�3�d�d�e���z�)�4�t�t�u���z�)�4�t�t�u���z�)�4�t�t�u�� ;��]�5�:�#5�6�6�F�F��� ;� ;� ;�� 0�1�1�s� :����� ;�����J�&� 1�D�D�E�d� :� :�� 3�4�4� 4���#�� �S�=�=������?�?�?�?�?�?�D�� �d�D�1�1�I�V�V� �s�]�]������?�?�?�?�?�?�D�� �d�D�1�1�I�V� � �F�X�$5�$5����1�1� 1� � (�$�f�Q�i�i�������I��V�F�^�^�#�#�#�#�#�#�� � /��d�I�.�.�D��L���s�D�$��E�E� � � ��J�!�*�-�-� G� G�I�!�(�(��X�(�F�F�I�I��������s� �M� � � �N� �N� �N� �N�  � � s�A)�) B�3B�B)r �write�Callable[[bytes], Any]c�P�||j�||�����dS)a� Write a WebSocket frame. Args: frame: Frame to write. write: Function that writes bytes. mask: Whether the frame should be masked i.e. whether the write happens on the client side. extensions: List of extensions, applied in order. Raises: ProtocolError: If the frame contains incorrect values. )r-r N)r"� serialize)r rHr-r s r!rHz Frame.write{s/��0 ��d�n�&�&�D�Z�&�H�H�I�I�I�I�Ir#)rr)rr$)rr') r+r,r-rr*r.r r/rr)rHrIr-rr r/rr')�__name__� __module__� __qualname__�__annotations__rrr�propertyr"r&r)� classmethodrGrH�r#r!rrs������� �I�I�I������K�K�K��D������D������D����� � � � ��X� �#�#�#�#�&�&�&�&�� $�<@� L �L �L �L �L ��[�L �f=A� J�J�J�J�J�J�J�Jr#rrrr�tuple[int, bytes]c���t|t��r%tjj|���fSt|t ��rtjj|fStd���)a� Convert a string or byte-like object to an opcode and a bytes-like object. This function is designed for data frames. If ``data`` is a :class:`str`, return ``OP_TEXT`` and a :class:`bytes` object encoding ``data`` in UTF-8. If ``data`` is a bytes-like object, return ``OP_BINARY`` and a bytes-like object. Raises: TypeError: If ``data`` doesn't have a supported type. �data must be str or bytes-like) � isinstancer$r r<�TEXT�encoder�BINARY� TypeError�rs r!� prepare_datar\�s_�� �$����:��}�!�4�;�;�=�=�0�0� �D�)� $� $�:��}�#�T�)�)��8�9�9�9r#rc��t|t��r|���St|t��rt |��St d���)ai Convert a string or byte-like object to bytes. This function is designed for ping and pong frames. If ``data`` is a :class:`str`, return a :class:`bytes` object encoding ``data`` in UTF-8. If ``data`` is a bytes-like object, return a :class:`bytes` object. Raises: TypeError: If ``data`` doesn't have a supported type. rU)rVr$rXrrrZr[s r!� prepare_ctrlr^�sQ���$����:��{�{�}�}�� �D�)� $� $�:��T�{�{���8�9�9�9r#)�Close�tuple[int, str]c�F�tj|��}|j|jfS)z� Parse the payload from a close frame. Returns: Close code and reason. Raises: ProtocolError: If data is ill-formed. UnicodeDecodeError: If the reason isn't valid UTF-8. )r_�parse�code�reason)r�closes r!� parse_closerf�s"�� �K�� � �E� �:�u�|� #�#r#rc�intrdr$c�F�t||�����S)z3 Serialize the payload for a close frame. )r_rK)rcrds r!�serialize_closeri�s �� ��v� � � (� (� *� *�*r#)rrrrS)rrrr)rrrr`)rcrgrdr$rr)� __future__rr:�collections.abcrr�typingrrr�r r � exceptionsr r rr�speedupsr� ImportError�utilsrr\r^� encode_datar_rfrirRr#r!�<module>rss���"�"�"�"�"�"� � � � �/�/�/�/�/�/�/�/�,�,�,�,�,�,�,�,�,�,�!�!�!�!�!�!�!�!�5�5�5�5�5�5�5�5�������������#�%�%�%�%�%�%�%���#�#�#�"�"�"�"�"�"�"�"�#����@J�@J�@J�@J�@J�J�@J�@J�@J�F:�:�:�:�0:�:�:�:�0� ������� $� $� $� $� +�+�+�+�+�+s�A� A�A
Memory