File: //lib64/python3.9/http/__pycache__/client.cpython-39.pyc
a
    �DOg��  �                   @   sN  d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z
ddlmZ g d�Z
dZdZdZdZd	Zd
Ze� �ejj� dd� ejj�� D �Zd
ZdZdZe�d�jZe�d�j Z!e�d�Z"e�d�Z#h d�Z$d@dd�Z%G dd� dej&j'�Z(dd� Z)e(fdd�Z*G dd� dej+�Z,G d d!� d!�Z-zddl.Z.W n e/�yH   Y n0 G d"d#� d#e-�Z0e
�1d#� G d$d%� d%e2�Z3G d&d'� d'e3�Z4G d(d)� d)e3�Z5G d*d+� d+e3�Z6G d,d-� d-e3�Z7G d.d/� d/e3�Z8G d0d1� d1e3�Z9G d2d3� d3e3�Z:G d4d5� d5e:�Z;G d6d7� d7e:�Z<G d8d9� d9e:�Z=G d:d;� d;e3�Z>G d<d=� d=e3�Z?G d>d?� d?e@e>�ZAe3ZBdS )Aa�
  HTTP/1.1 client library
<intro stuff goes here>
<other stuff, too>
HTTPConnection goes through a number of "states", which define when a client
may legally make another request or fetch the response for a particular
request. This diagram details these state transitions:
    (null)
      |
      | HTTPConnection()
      v
    Idle
      |
      | putrequest()
      v
    Request-started
      |
      | ( putheader() )*  endheaders()
      v
    Request-sent
      |\_____________________________
      |                              | getresponse() raises
      | response = getresponse()     | ConnectionError
      v                              v
    Unread-response                Idle
    [Response-headers-read]
      |\____________________
      |                     |
      | response.read()     | putrequest()
      v                     v
    Idle                  Req-started-unread-response
                     ______/|
                   /        |
   response.read() |        | ( putheader() )*  endheaders()
                   v        v
       Request-started    Req-sent-unread-response
                            |
                            | response.read()
                            v
                          Request-sent
This diagram presents the following rules:
  -- a second request may not be started until {response-headers-read}
  -- a response [object] cannot be retrieved until {request-sent}
  -- there is no differentiation between an unread response body and a
     partially read response body
Note: this enforcement is applied by the HTTPConnection class. The
      HTTPResponse class does not enforce this state machine, which
      implies sophisticated clients may accelerate the request/response
      pipeline. Caution should be taken, though: accelerating the states
      beyond the above pattern may imply knowledge of the server's
      connection-close behavior for certain requests. For example, it
      is impossible to tell whether the server will close the connection
      UNTIL the response headers have been read; this means that further
      requests cannot be placed into the pipeline until it is known that
      the server will NOT be closing the connection.
Logical State                  __state            __response
-------------                  -------            ----------
Idle                           _CS_IDLE           None
Request-started                _CS_REQ_STARTED    None
Request-sent                   _CS_REQ_SENT       None
Unread-response                _CS_IDLE           <response_class>
Req-started-unread-response    _CS_REQ_STARTED    <response_class>
Req-sent-unread-response       _CS_REQ_SENT       <response_class>
�    N)�urlsplit)�HTTPResponse�HTTPConnection�
HTTPException�NotConnected�UnknownProtocol�UnknownTransferEncoding�UnimplementedFileMode�IncompleteRead�
InvalidURL�ImproperConnectionState�CannotSendRequest�CannotSendHeader�ResponseNotReady�
BadStatusLine�LineTooLong�RemoteDisconnected�error�	responses�P   i�  ZUNKNOWNZIdlezRequest-startedzRequest-sentc                 C   s   i | ]}||j �qS � )�phrase)�.0�vr   r   �#/usr/lib64/python3.9/http/client.py�
<dictcomp>k   �    r   i   i   �d   s   [^:\s][^:\r\n]*s   \n(?![ \t])|\r(?![ \t\n])z[ - ]z[ -]>   ZPATCHZPOST�PUT�datac              
   C   sj   z| � d�W S  tyd } z@t|j|j|j|jd|�� | |j|j� |f �d�W Y d}~n
d}~0 0 dS )z<Call data.encode("latin-1") but show a better error message.�latin-1z`%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') if you want to send it encoded in UTF-8.N)�encode�UnicodeEncodeError�encoding�object�start�end�title)r   �name�errr   r   r   �_encode�   s    ���r*   c                   @   s   e Zd Zdd� ZdS )�HTTPMessagec                 C   sj   |� � d }t|�}g }d}| �� D ]@}|d|� � � |krBd}n|dd� �� sVd}|r$|�|� q$|S )a�  Find all header lines matching a given header name.
        Look through the list of headers and find all lines matching a given
        header name (and their continuation lines).  A list of the lines is
        returned, without interpretation.  If the header does not occur, an
        empty list is returned.  If the header occurs multiple times, all
        occurrences are returned.  Case is not important in the header name.
        �:r   N�   )�lower�len�keys�isspace�append)�selfr(   �nZlstZhit�liner   r   r   �getallmatchingheaders�   s    
z!HTTPMessage.getallmatchingheadersN)�__name__�
__module__�__qualname__r6   r   r   r   r   r+   �   s   r+   c                 C   sX   g }| � td �}t|�tkr&td��|�|� t|�tkrHtdt ��|dv rqTq|S )z�Reads potential header lines into a list from a file pointer.
    Length of line is limited by _MAXLINE, and number of
    headers is limited by _MAXHEADERS.
    r-   �header linezgot more than %d headers��   
�   
r   )�readline�_MAXLINEr/   r   r2   �_MAXHEADERSr   )�fp�headersr5   r   r   r   �
_read_headers�   s    
rC   c                 C   s,   t | �}d�|��d�}tjj|d��|�S )aG  Parses only RFC2822 headers from a file pointer.
    email Parser wants to see strings rather than bytes.
    But a TextIOWrapper around self.rfile would buffer too many bytes
    from the stream, bytes which we later need to read as bytes.
    So we read the correct bytes here, as bytes, for email Parser
    to parse.
    r   �
iso-8859-1)�_class)rC   �join�decode�email�parserZParserZparsestr)rA   rE   rB   Zhstringr   r   r   �
parse_headers�   s    
rJ   c                       s  e Zd Zd@dd�Zdd� Zdd� Zd	d
� Zdd� Z� fd
d�Z� fdd�Z	dd� Z
dd� ZdAdd�Zdd� Z
dd� Zdd� Zdd� Zdd � Zd!d"� Zd#d$� Zd%d&� ZdBd(d)�ZdCd*d+�ZdD� fd,d-�	Zd.d/� Zd0d1� Zd2d3� ZdEd4d5�Zd6d7� Zd8d9� Zd:d;� Zd<d=� Zd>d?� Z �  Z!S )Fr   r   Nc                 C   sR   |� d�| _|| _|| _d  | _| _t| _t| _t| _	t| _
t| _t| _t| _
d S )N�rb)�makefilerA   �
debuglevel�_methodrB   �msg�_UNKNOWN�version�status�reason�chunked�
chunk_left�length�
will_close)r3   �sockrM   �method�urlr   r   r   �__init__�   s    zHTTPResponse.__init__c                 C   s  t | j�td �d�}t|�tkr*td��| jdkrBtdt|�� |sNt	d��z|�
d d�\}}}W nB ty�   z|�
d d�\}}d}W n ty�   d}Y n0 Y n0 |�d	�s�| �
�  t|��z$t|�}|d
k s�|dkr�t|��W n t�y   t|��Y n0 |||fS )Nr-   rD   zstatus liner   zreply:z-Remote end closed connection without response�   � zHTTP/r   i�  )�strrA   r>