← Back
Editing: http.cpython-311.pyc
� �=Xc � � � d dl mZ d dlZd dlZd dlmZ ddlmZ ddlm Z ddgZ d Zd Zdd�Z ej d� � Z ej d� � Zdd�Zdd�Zdd�Zdd�ZdS ) � )�annotationsN)�Tuple� )�Headers)� SecurityError�read_request� read_response� i �value�bytes�return�strc �. � | � d�� � S )zG Decode a bytestring for interpolating into an error message. �backslashreplace)�errors)�decode)r s �8/usr/lib/python3/dist-packages/websockets/legacy/http.py�dr s � � �<�<�1�<�2�2�2� s [-!#$%&\'*+.^_`|~0-9a-zA-Z]+s [\x09\x20-\x7e\x80-\xff]*�stream�asyncio.StreamReader�Tuple[str, Headers]c � � K � t | � � � d{V ��}n"# t $ r}t d� � |�d}~ww xY w |� dd� � \ }}}n.# t $ r! t dt |� � � �� � d�w xY w|dk rt dt |� � � �� � �|dk rt d t |� � � �� � �|� d d� � }t | � � � d{V ��}||fS )a� Read an HTTP/1.1 GET request and return ``(path, headers)``. ``path`` isn't URL-decoded or validated in any way. ``path`` and ``headers`` are expected to contain only ASCII characters. Other characters are represented with surrogate escapes. :func:`read_request` doesn't attempt to read the request body because WebSocket handshake requests don't have one. If the request contains a body, it may be read from ``stream`` after this coroutine returns. Args: stream: input to read the request from Raises: EOFError: if the connection is closed without a full HTTP request SecurityError: if the request exceeds a security limit ValueError: if the request isn't well formatted Nz1connection closed while reading HTTP request line� r zinvalid HTTP request line: s GETzunsupported HTTP method: � HTTP/1.1�unsupported HTTP version: �ascii�surrogateescape)� read_line�EOFError�split� ValueErrorr r �read_headers)r �request_line�exc�method�raw_path�version�path�headerss r r r - sS � � � �8U�&�v�.�.�.�.�.�.�.�.����� U� U� U��J�K�K�QT�T�����U����T�$0�$6�$6�t�Q�$?�$?�!���'�'��� T� T� T��H�q����H�H�I�I�t�S�T���� �����@�Q�v�Y�Y�@�@�A�A�A��+����B�a��j�j�B�B�C�C�C��?�?�7�$5�6�6�D� ��(�(�(�(�(�(�(�(�G���=�s � � 9�4�9�A �+B�Tuple[int, str, Headers]c � � K � t | � � � d{V ��}n"# t $ r}t d� � |�d}~ww xY w |� dd� � \ }}}n.# t $ r! t dt |� � � �� � d�w xY w|dk rt dt |� � � �� � � t |� � }n.# t $ r! t dt |� � � �� � d�w xY wd |cxk rd k s!n t dt |� � � �� � �t � |� � st dt |� � � �� � �|� � � }t | � � � d{V ��}|||fS ) a� Read an HTTP/1.1 response and return ``(status_code, reason, headers)``. ``reason`` and ``headers`` are expected to contain only ASCII characters. Other characters are represented with surrogate escapes. :func:`read_request` doesn't attempt to read the response body because WebSocket handshake responses don't have one. If the response contains a body, it may be read from ``stream`` after this coroutine returns. Args: stream: input to read the response from Raises: EOFError: if the connection is closed without a full HTTP response SecurityError: if the response exceeds a security limit ValueError: if the response isn't well formatted Nz0connection closed while reading HTTP status liner r zinvalid HTTP status line: r r zinvalid HTTP status code: �d i� zunsupported HTTP status code: zinvalid HTTP reason phrase: ) r r r! r"