� <��g����ddlmZddlZddlZddlmZmZddlmZm Z m Z ddl m Z m Z ddlmZmZddlmZmZgd �Zdd�Zdd�Zdd�Zdd�ZdS)�)� annotationsN�)�Headers�MultipleValuesError)� InvalidHeader�InvalidHeaderValue�InvalidUpgrade)�parse_connection� parse_upgrade)�ConnectionOption�UpgradeProtocol)� accept_key� generate_key)� build_request� check_request�build_response�check_response�headersr�return�strc�J�t��}d|d<d|d<||d<d|d<|S)z� Build a handshake request to send to the server. Update request headers passed in argument. Args: headers: Handshake request headers. Returns: ``key`` that must be passed to :func:`check_response`. � websocket�Upgrade� Connection�Sec-WebSocket-Key�13�Sec-WebSocket-Version)r�r�keys �k/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/websockets/legacy/handshake.pyrrs<�� �.�.�C�$�G�I��%�G�L��#&�G� � �'+�G� #�$� �J�c��td�|�d��D��g��}td�|D����s#tdd�|�����td�|�d��D��g��}t |��dkr|d���d ks#tdd�|����� |d }n@#t$r}td ��|�d }~wt$r}td d ��|�d }~wwxYw tj |� ��d ���}n(#tj$r}td |��|�d }~wwxYwt |��dkrtd |��� |d}n@#t$r}td��|�d }~wt$r}tdd ��|�d }~wwxYw|dkrtd|���|S)ab Check a handshake request received from the client. This function doesn't verify that the request is an HTTP/1.1 or higher GET request and doesn't perform ``Host`` and ``Origin`` checks. These controls are usually performed earlier in the HTTP request handling code. They're the responsibility of the caller. Args: headers: Handshake request headers. Returns: ``key`` that must be passed to :func:`build_response`. Raises: InvalidHandshake: If the handshake request is invalid. Then, the server must return a 400 Bad Request error. c�,�g|]}t|����S��r ��.0�values r � <listcomp>z!check_request.<locals>.<listcomp>:�!��L�L�L�U� �%� � �L�L�Lr!rc3�FK�|]}|���dkV��dS��upgradeN��lowerr&s r � <genexpr>z check_request.<locals>.<genexpr>=�/����B�B�e�u�{�{�}�}� �)�B�B�B�B�B�Br!�, c�,�g|]}t|����Sr$�r r&s r r)z!check_request.<locals>.<listcomp>A� ��F�F�F�%��u� � �F�F�Fr!r�rrrN�multiple valuesT)�validate�rr)�sum�get_all�anyr �join�lenr/�KeyErrorrr�base64� b64decode�encode�binascii�Errorr)r� connectionr-�s_w_key�exc�raw_key� s_w_versions r rr%sm��(*-�L�L�g�o�o�l�.K�.K�L�L�L�b�*�*�J� �B�B�z�B�B�B� B� B�B��\�4�9�9�Z�+@�+@�A�A�A�%(�F�F�7�?�?�9�+E�+E�F�F�F��&�&�G� ��L�L�A� � �'�!�*�"2�"2�"4�"4� �"C�"C��Y�� � �'�(:�(:�;�;�;�M��-�.���� �:�:�:��/�0�0�c�9����� �M�M�M��/�1B�C�C��L�����M����H��"�7�>�>�#3�#3�d�C�C�C���� �>�H�H�H� �!4�g�>�>�C�G�����H���� �7�|�|�r��� �!4�g�>�>�>�Q��5�6� � �� �>�>�>��3�4�4�#�=����� �Q�Q�Q��3�5F�G�G�S�P�����Q�����d��� �!8�+�F�F�F� �Ns`�,C5�5 D2�?D� D2�D-�-D2�6(E�F�.E?�?F�+F4�4 G1�>G� G1�G,�,G1r�Nonec�>�d|d<d|d<t|��|d<dS)z� Build a handshake response to send to the client. Update response headers passed in argument. Args: headers: Handshake response headers. key: Returned by :func:`check_request`. rrr�Sec-WebSocket-AcceptN)�acceptrs r rres/��%�G�I��%�G�L��&,�S�k�k�G� "�#�#�#r!c��td�|�d��D��g��}td�|D����s#tdd�|�����td�|�d��D��g��}t |��dkr|d���d ks#tdd �|����� |d }n@#t$r}td ��|�d }~wt$r}td d ��|�d }~wwxYw|t|��krtd |���d S)a� Check a handshake response received from the server. This function doesn't verify that the response is an HTTP/1.1 or higher response with a 101 status code. These controls are the responsibility of the caller. Args: headers: Handshake response headers. key: Returned by :func:`build_request`. Raises: InvalidHandshake: If the handshake response is invalid. c�,�g|]}t|����Sr$r%r&s r r)z"check_response.<locals>.<listcomp>�r*r!rc3�FK�|]}|���dkV��dSr,r.r&s r r0z!check_response.<locals>.<genexpr>�r1r!� c�,�g|]}t|����Sr$r4r&s r r)z"check_response.<locals>.<listcomp>�r5r!rr6rrr2rLNr7) r:r;r<r r=r>r/r?rrrMr)rrrEr-� s_w_acceptrGs r rrus��� *-�L�L�g�o�o�l�.K�.K�L�L�L�b�*�*�J� �B�B�z�B�B�B� B� B�A��\�3�8�8�J�+?�+?�@�@�@�%(�F�F�7�?�?�9�+E�+E�F�F�F��&�&�G� ��L�L�A� � �'�!�*�"2�"2�"4�"4� �"C�"C��Y�� � �'�(:�(:�;�;�;�P��3�4� � �� �=�=�=��2�3�3��<����� �P�P�P��2�4E�F�F�C�O�����P�����V�C�[�[� � � �!7��D�D�D�!� s$�,C5�5 D2�?D� D2�D-�-D2)rrrr)rrrrrrJ)� __future__rr@rC�datastructuresrr� exceptionsrrr rr r �typingr r �utilsrrMr�__all__rrrrr$r!r �<module>rZs��"�"�"�"�"�"� � � � �����9�9�9�9�9�9�9�9�J�J�J�J�J�J�J�J�J�J�5�5�5�5�5�5�5�5�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6� Q� P� P������*=�=�=�=�@ 2� 2� 2� 2� )E�)E�)E�)E�)E�)Er!
Memory