AlkantarClanX12

Your IP : 18.225.56.78


Current Path : /opt/alt/python38/lib64/python3.8/http/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/http/__pycache__/client.cpython-38.pyc

U

i�f���@sfdZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZdddddd	d
ddd
ddddddddgZdZ
dZdZdZdZdZe��ejj�dd�ejj��D�ZdZdZe�d �jZe�d!�jZe�d"�Z e�d#�Z!d$d%d&hZ"dBd(d)�Z#Gd*d+�d+ej$j%�Z&d,d-�Z'e&fd.d/�Z(Gd0d�dej)�Z*Gd1d�d�Z+zddl,Z,Wne-k
�r`YnXGd2d3�d3e+�Z.e�/d3�Gd4d�de0�Z1Gd5d�de1�Z2Gd6d�de1�Z3Gd7d�de1�Z4Gd8d	�d	e1�Z5Gd9d
�d
e1�Z6Gd:d�de1�Z7Gd;d
�d
e1�Z8Gd<d�de8�Z9Gd=d�de8�Z:Gd>d�de8�Z;Gd?d�de1�Z<Gd@d�de1�Z=GdAd�de>e<�Z?e1Z@dS)Ca�
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�Pi�ZUNKNOWNZIdlezRequest-startedzRequest-sentcCsi|]}||j�qS�)�phrase)�.0�vrr�0/opt/alt/python38/lib64/python3.8/http/client.py�
<dictcomp>jsri�ds[^:\s][^:\r\n]*s\n(?![ \t])|\r(?![ \t\n])z[- ]z[-]ZPATCHZPOSTZPUT�datac
Cshz|�d�WStk
rb}z8t|j|j|j|jd|��||j|j�|f�d�W5d}~XYnXdS)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�errrrr�_encode�s���r(c@seZdZdd�ZdS)�HTTPMessagecCsj|��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.

        �:rN�)�lower�len�keys�isspace�append)�selfr&�nZlstZhit�linerrr�getallmatchingheaders�s
z!HTTPMessage.getallmatchingheadersN)�__name__�
__module__�__qualname__r4rrrrr)�sr)cCsXg}|�td�}t|�tkr&td��|�|�t|�tkrHtdt��|dkrqTq|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��
�
�)�readline�_MAXLINEr-rr0�_MAXHEADERSr)�fp�headersr3rrr�
_read_headers�s
rBcCs,t|�}d�|��d�}tjj|d��|�S)aGParses 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)rB�join�decode�email�parserZParserZparsestr)r@rDrAZhstringrrr�
parse_headers�s
rIcseZdZd@dd�Zdd�Zdd�Zd	d
�Zdd�Z�fd
d�Z�fdd�Z	dd�Z
dd�ZdAdd�Zdd�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)FrrNcCsR|�d�|_||_||_d|_|_t|_t|_t|_	t|_
t|_t|_t|_
dS)N�rb)Zmakefiler@�
debuglevel�_methodrA�msg�_UNKNOWN�version�status�reason�chunked�
chunk_left�length�
will_close)r1�sockrK�method�urlrrr�__init__�szHTTPResponse.__init__cCst|j�td�d�}t|�tkr*td��|jdkrBtdt|��|sNt	d��z|�
dd�\}}}WnFtk
r�z|�
dd�\}}d}Wntk
r�d}YnXYnX|�d	�s�|�
�t|��z$t|�}|d
ks�|dkr�t|��Wntk
�rt|��YnX|||fS)Nr+rCzstatus linerzreply:z-Remote end closed connection without response��zHTTP/ri�)�strr@r=r>r-rrK�print�reprr�split�
ValueError�
startswith�_close_connr�int)r1r3rOrPrQrrr�_read_statuss2

zHTTPResponse._read_statusc	Cs�|jdk	rdS|��\}}}|tkr&qHt|j�}|jdkrDtd|�~q||_|_|�	�|_
|dkrnd|_n|�d�r�d|_nt
|��t|j�|_|_|jdkr�|j��D]\}}td|d|�q�|j�d	�}|r�|��d
kr�d|_d|_nd|_|��|_d|_|j�d
�}|�rb|j�sbzt|�|_Wntk
�rLd|_YnX|jdk�rhd|_nd|_|tk�s�|tk�s�d|k�r�dk�s�n|jdk�r�d|_|j�s�|j�s�|jdk�r�d|_dS)Nrzheaders:)zHTTP/1.0zHTTP/0.9�
zHTTP/1.��header:r*�transfer-encodingrRTF�content-lengthr���HEAD)rArdZCONTINUErBr@rKr]�coderP�striprQrOrarrIrM�items�getr,rRrS�_check_closerUrTrcr`Z
NO_CONTENTZNOT_MODIFIEDrL)	r1rOrPrQZskipped_headers�hdr�valZtr_encrTrrr�begin5sf







�
�
���zHTTPResponse.begincCsv|j�d�}|jdkr.|r*d|��kr*dSdS|j�d�r>dS|rRd|��krRdS|j�d�}|rrd|��krrdSdS)NZ
connectionrf�closeTFz
keep-alivezproxy-connection)rArorOr,)r1ZconnZpconnrrrrp}s
zHTTPResponse._check_closecCs|j}d|_|��dS�N)r@rt)r1r@rrrrb�szHTTPResponse._close_conncs$zt���W5|jr|��XdSru)r@rb�superrt�r1��	__class__rrrt�szHTTPResponse.closecst���|jr|j��dSru)rv�flushr@rwrxrrrz�s
zHTTPResponse.flushcCsdS)zAlways returns TrueTrrwrrr�readable�szHTTPResponse.readablecCs
|jdkS)z!True if the connection is closed.N)r@rwrrr�isclosed�szHTTPResponse.isclosedcCs�|jdkrdS|jdkr$|��dS|dk	rRt|�}|�|�}t|�d|���S|jr`|��S|j	dkrv|j�
�}n6z|�|j	�}Wntk
r�|���YnXd|_	|��|SdS)Nr<rkr)
r@rLrb�	bytearray�readinto�
memoryview�tobytesrR�_readall_chunkedrT�read�
_safe_readr
)r1�amt�br2�srrrr��s*



zHTTPResponse.readcCs�|jdkrdS|jdkr$|��dS|jr4|�|�S|jdk	r^t|�|jkr^t|�d|j�}|j�|�}|s||r||��n&|jdk	r�|j|8_|js�|��|S)z^Read up to len(b) bytes into bytearray b and return the number
        of bytes read.
        Nrrk)	r@rLrbrR�_readinto_chunkedrTr-rr~)r1r�r2rrrr~�s$





zHTTPResponse.readintocCsr|j�td�}t|�tkr$td��|�d�}|dkrB|d|�}zt|d�WStk
rl|���YnXdS)Nr+z
chunk size�;r�)	r@r=r>r-r�findrcr`rb)r1r3�irrr�_read_next_chunk_sizes
z"HTTPResponse._read_next_chunk_sizecCs:|j�td�}t|�tkr$td��|s*q6|dkrq6qdS)Nr+ztrailer liner9)r@r=r>r-r�r1r3rrr�_read_and_discard_trailersz&HTTPResponse._read_and_discard_trailercCsl|j}|sh|dk	r|�d�z|��}Wntk
rDtd��YnX|dkrb|��|��d}||_|S)NrZr<r)rSr�r�r`r
r�rb)r1rSrrr�_get_chunk_left s
zHTTPResponse._get_chunk_leftcCsp|jtkst�g}z6|��}|dkr&q>|�|�|��d|_qd�|�WStk
rjtd�|���YnXdS�Nrr<)	rRrN�AssertionErrorr�r0r�rSrEr
)r1�valuerSrrrr�8szHTTPResponse._readall_chunkedcCs�|jtkst�d}t|�}zv|��}|dkr2|WSt|�|kr\|�|�}|||_||WS|d|�}|�|�}||d�}||7}d|_qWn(tk
r�tt	|d|����YnXdS)Nr)
rRrNr�rr�r-�_safe_readintorSr
�bytes)r1r�Ztotal_bytesZmvbrSr2Ztemp_mvbrrrr�Fs$



zHTTPResponse._readinto_chunkedcCs.|j�|�}t|�|kr*t||t|���|S)aRead the number of bytes requested.

        This function should be used when <amt> bytes "should" be present for
        reading. If the bytes are truly not available (due to EOF), then the
        IncompleteRead exception can be used to detect the problem.
        )r@r�r-r
)r1r�rrrrr�^szHTTPResponse._safe_readcCs:t|�}|j�|�}||kr6tt|d|��||��|S)z2Same as _safe_read, but for reading into a buffer.N)r-r@r~r
r�)r1r�r�r2rrrr�js
zHTTPResponse._safe_readinto���cCs�|jdks|jdkrdS|jr(|�|�S|jdk	rJ|dksD||jkrJ|j}|j�|�}|sh|rh|��n|jdk	r�|jt|�8_|S)zvRead with at most one underlying system call.  If at least one
        byte is buffered, return that instead.
        Nrkr<r)r@rLrR�_read1_chunkedrT�read1rbr-)r1r2�resultrrrr�rs


zHTTPResponse.read1cCs4|jdks|jdkrdS|jr(|�|�S|j�|�S)Nrkr<)r@rLrR�
_peek_chunked�peek)r1r2rrrr��s

zHTTPResponse.peekcs�|jdks|jdkrdS|jr*t��|�S|jdk	rL|dksF||jkrL|j}|j�|�}|sj|rj|��n|jdk	r�|jt|�8_|S)Nrkr<r)r@rLrRrvr=rTrbr-)r1�limitr�rxrrr=�s

zHTTPResponse.readlinecCsd|��}|dks|dkrdSd|kr0|ks6n|}|j�|�}|jt|�8_|s`td��|Sr�)r�r@r�rSr-r
)r1r2rSr�rrrr��szHTTPResponse._read1_chunkedcCsDz|��}Wntk
r"YdSX|dkr0dS|j�|�d|�S)Nr<)r�r
r@r�)r1r2rSrrrr��szHTTPResponse._peek_chunkedcCs
|j��Sru)r@�filenorwrrrr��szHTTPResponse.filenocCsF|jdkrt��|j�|�p|}t|t�s4t|d�s8|Sd�|�SdS)axReturns the value of the header matching *name*.

        If there are multiple matching headers, the values are
        combined into a single string separated by commas and spaces.

        If no matching header is found, returns *default* or None if
        the *default* is not specified.

        If the headers are unknown, raises http.client.ResponseNotReady.

        N�__iter__z, )rArZget_all�
isinstancer\�hasattrrE)r1r&�defaultrArrr�	getheader�s
zHTTPResponse.getheadercCs|jdkrt��t|j���S)z&Return list of (header, value) tuples.N)rAr�listrnrwrrr�
getheaders�s
zHTTPResponse.getheaderscCs|Srurrwrrrr��szHTTPResponse.__iter__cCs|jS)ajReturns an instance of the class mimetools.Message containing
        meta-information associated with the URL.

        When the method is HTTP, these headers are those returned by
        the server at the head of the retrieved HTML page (including
        Content-Length and Content-Type).

        When the method is FTP, a Content-Length header will be
        present if (as is now usual) the server passed back a file
        length in response to the FTP retrieval request. A
        Content-Type header will be present if the MIME type can be
        guessed.

        When the method is local-file, returned headers will include
        a Date representing the file's last-modified time, a
        Content-Length giving file size, and a Content-Type
        containing a guess at the file's type. See also the
        description of the mimetools module.

        )rArwrrr�info�szHTTPResponse.infocCs|jS)aZReturn the real URL of the page.

        In some cases, the HTTP server redirects a client to another
        URL. The urlopen() function handles this transparently, but in
        some cases the caller needs to know which URL the client was
        redirected to. The geturl() method can be used to get at this
        redirected URL.

        )rXrwrrr�geturl�s
zHTTPResponse.geturlcCs|jS)zuReturn the HTTP status code that was sent with the response,
        or None if the URL is not an HTTP URL.

        )rPrwrrr�getcode�szHTTPResponse.getcode)rNN)N)r�)r�)r�)N)"r5r6r7rYrdrsrprbrtrzr{r|r�r~r�r�r�r�r�r�r�r�r�r=r�r�r�r�r�r�r�r�r��
__classcell__rrrxrr�s<	
!H

 "

	

c@s
eZdZdZdZeZeZdZ	dZ
edd��Zedd��Z
d	ejd	d
fdd�Zd7d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd8d d!�Zd9d"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z d:dd.�d/d0�Z!d	ifdd.�d1d2�Z"d3d4�Z#d5d6�Z$d	S);rrfzHTTP/1.1r+rcCst|tj�S)zFTest whether a file-like object is a text or a binary stream.
        )r��io�
TextIOBase)�streamrrr�
_is_textIOszHTTPConnection._is_textIOcCsf|dkr|��tkrdSdSt|d�r*dSzt|�}|jWStk
rNYnXt|t�rbt|�SdS)aGet the content-length based on the body.

        If the body is None, we set Content-Length: 0 for methods that expect
        a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
        any method if the body is a str or bytes-like object and not a file.
        Nrr�)	�upper�_METHODS_EXPECTING_BODYr�r�nbytes�	TypeErrorr�r\r-)�bodyrWZmvrrr�_get_content_lengths

z"HTTPConnection._get_content_lengthN� cCsn||_||_||_d|_g|_d|_t|_d|_d|_	d|_
i|_|�||�\|_
|_|�|j
�tj|_dSru)�timeout�source_address�	blocksizerV�_buffer�_HTTPConnection__response�_CS_IDLE�_HTTPConnection__staterL�_tunnel_host�_tunnel_port�_tunnel_headers�
_get_hostport�host�port�_validate_host�socketZcreate_connection�_create_connection)r1r�r�r�r�r�rrrrY4szHTTPConnection.__init__cCs<|jrtd��|�||�\|_|_|r.||_n
|j��dS)aDSet up host and port for HTTP CONNECT tunnelling.

        In a connection that uses HTTP CONNECT tunneling, the host passed to the
        constructor is used as a proxy server that relays all communication to
        the endpoint passed to `set_tunnel`. This done by sending an HTTP
        CONNECT request to the proxy server when the connection is established.

        This method must be called before the HTTP connection has been
        established.

        The headers argument should be a mapping of extra HTTP headers to send
        with the CONNECT request.
        z.Can't set up tunnel for established connectionN)rV�RuntimeErrorr�r�r�r��clear)r1r�r�rArrr�
set_tunnelJszHTTPConnection.set_tunnelcCs�|dkr�|�d�}|�d�}||kr�zt||dd��}WnHtk
r�||dd�dkrh|j}ntd||dd���YnX|d|�}n|j}|r�|ddkr�|ddkr�|dd�}||fS)	Nr*�]r+r[znonnumeric port: '%s'r�[r�)�rfindrcr`�default_portr)r1r�r�r��jrrrr�bs

zHTTPConnection._get_hostportcCs
||_dSru)rK)r1�levelrrr�set_debuglevelvszHTTPConnection.set_debuglevelcCs�d|j|jf}|�d�}|�|�|j��D](\}}d||f}|�d�}|�|�q.|�d�|j|j|jd�}|�	�\}}	}
|	t
jjkr�|�
�td|	|
��f��|j�td�}t|�tkr�td	��|s�q�|d
kr�q�|jdkr�td|���q�dS)
NzCONNECT %s:%d HTTP/1.0
�asciiz%s: %s
rr:�rWzTunnel connection failed: %d %sr+r8r9rrg)r�r�r�sendr�rn�response_classrVrLrd�http�
HTTPStatusZOKrt�OSErrorrmr@r=r>r-rrKr]rF)r1Zconnect_strZ
connect_bytes�headerr�Z
header_strZheader_bytes�responserOrl�messager3rrr�_tunnelys4�



�
zHTTPConnection._tunnelcCsB|�|j|jf|j|j�|_|j�tjtj	d�|j
r>|��dS)z3Connect to the host and port specified in __init__.r+N)r�r�r�r�r�rVZ
setsockoptr�ZIPPROTO_TCPZTCP_NODELAYr�r�rwrrr�connect�s
�zHTTPConnection.connectcCsBt|_z|j}|r d|_|��W5|j}|r<d|_|��XdS)z(Close the connection to the HTTP server.N)r�r�r�rtrV)r1r�rVrrrrt�szHTTPConnection.closecCs|jdkr |jr|��nt��|jdkr8tdt|��t|d�r�|jdkrTtd�|�|�}|rt|jdkrttd�|�	|j
�}|s�q�|r�|�d�}|j�|�qtdSz|j�|�WnLt
k
�rt|tjj�r�|D]}|j�|�q�nt
dt|���YnXdS)	z�Send `data' to the server.
        ``data`` can be a string object, a bytes object, an array object, a
        file-like object that supports a .read() method, or an iterable object.
        Nrzsend:r��sendIng a read()able�encoding file using iso-8859-1rCz9data should be a bytes-like object or an iterable, got %r)rV�	auto_openr�rrKr]r^r�r�r�r�rZsendallr�r��collections�abc�Iterable�type)r1rr�	datablock�drrrr��s8






�zHTTPConnection.sendcCs|j�|�dS)zuAdd a line of output to the current request buffer.

        Assumes that the line does *not* end with \r\n.
        N)r�r0)r1r�rrr�_output�szHTTPConnection._outputccs^|jdkrtd�|�|�}|r2|jdkr2td�|�|j�}|sDqZ|rR|�d�}|Vq2dS)Nrr�r�rC)rKr]r�r�r�r)r1r{rr�rrr�_read_readable�s


zHTTPConnection._read_readableFcCs |j�d�d�|j�}|jdd�=|�|�|dk	�rt|d�rN|�|�}nZzt|�WnFtk
r�zt|�}Wn$tk
r�tdt	|���YnXYnX|f}|D]R}|s�|j
dkr�td�q�|r�|jdkr�t
|�d	�d
��d�|d}|�|�q�|�r|jdk�r|�d�dS)
z�Send the currently buffered request and clear the buffer.

        Appends an extra \r\n to the buffer.
        A message_body may be specified, to be appended to the request.
        )r<r<r:Nr�zAmessage_body should be a bytes-like object or an iterable, got %rrzZero length chunk ignoredrf�Xz
r�s0

)r��extendrEr�r�r�rr��iterr�rKr]�	_http_vsnr-r)r1�message_body�encode_chunkedrMZchunks�chunkrrr�_send_output�s:


�
�zHTTPConnection._send_outputcCs�|jr|j��rd|_|jtkr(t|_n
t|j��|�|�||_|pHd}|�|�d|||j	f}|�
|�|��|jdk�r�|�s�d}|�
d�r�t|�\}}}}}|r�z|�d�}Wntk
r�|�d�}YnX|�d	|�n�|jr�|j}	|j}
n|j}	|j}
z|	�d�}Wn tk
�r4|	�d�}YnX|	�d
�dk�rRd|d
}|
|jk�rl|�d	|�n|�d�}|�d	d||
f�|�s�|�dd�ndS)a`Send a request to the server.

        `method' specifies an HTTP request method, e.g. 'GET'.
        `url' specifies the object being requested, e.g. '/index.html'.
        `skip_host' if True does not add automatically a 'Host:' header
        `skip_accept_encoding' if True does not add automatically an
           'Accept-Encoding:' header
        N�/z%s %s %srfr[r�r�ZidnaZHostr*r�[�]z%s:%szAccept-EncodingZidentity)r�r|r�r��_CS_REQ_STARTEDr
�_validate_methodrL�_validate_path�
_http_vsn_strr��_encode_requestr�rarrr �	putheaderr�r�r�r�r�r�rF)r1rWrX�	skip_host�skip_accept_encoding�requestZnetlocZnilZ
netloc_encr�r�Zhost_encrrr�
putrequest sP






zHTTPConnection.putrequestcCs
|�d�S)Nr�)r)r1r�rrrr��szHTTPConnection._encode_requestcCs,t�|�}|r(td|�d|���d���dS)z&Validate a method name for putrequest.z)method can't contain control characters. � (found at least �)N)�$_contains_disallowed_method_pchar_re�searchr`�group)r1rW�matchrrrr��s

�zHTTPConnection._validate_methodcCs,t�|�}|r(td|�d|���d���dS)zValidate a url for putrequest.�&URL can't contain control characters. r�r�N��!_contains_disallowed_url_pchar_rer�rr�)r1rXr�rrrr��s
zHTTPConnection._validate_pathcCs,t�|�}|r(td|�d|���d���dS)z9Validate a host so it doesn't contain control characters.r�r�r�Nr)r1r�r�rrrr��s
zHTTPConnection._validate_hostcGs�|jtkrt��t|d�r$|�d�}t|�s:td|f��t|�}t|�D]\\}}t|d�rl|�d�||<nt	|t
�r�t|��d�||<t||�rJtd||f��qJd�
|�}|d|}|�|�dS)	zkSend a request header line to the server.

        For example: h.putheader('Accept', 'text/html')
        rr�zInvalid header name %rrzInvalid header value %rs
	s: N)r�r�rr�r�_is_legal_header_namer`r��	enumerater�rcr\�_is_illegal_header_valuerEr�)r1r��valuesr�Z	one_valuer�rrrr��s"





zHTTPConnection.putheader�r�cCs*|jtkrt|_nt��|j||d�dS)z�Indicate that the last header line has been sent to the server.

        This method sends the request to the server.  The optional message_body
        argument can be used to pass a message body associated with the
        request.
        rN)r�r��_CS_REQ_SENTrr�)r1r�r�rrr�
endheaders�s
zHTTPConnection.endheaderscCs|�|||||�dS)z&Send a complete request to the server.N)�
_send_request)r1rWrXr�rAr�rrrr��szHTTPConnection.requestcCs�tdd�|D��}i}d|kr&d|d<d|kr6d|d<|j||f|�d|kr�d	|kr�d
}|�||�}|dkr�|dk	r�|jdkr�td|�d
}|�dd�q�|�dt|��nd
}|��D]\}	}
|�|	|
�q�t|t�r�t	|d�}|j
||d�dS)Ncss|]}|��VqdSru)r,)r�krrr�	<genexpr>�sz/HTTPConnection._send_request.<locals>.<genexpr>r�r+r�zaccept-encodingr�rirhFrzUnable to determine size of %rTzTransfer-EncodingrRzContent-Lengthr�r)�	frozensetr�r�rKr]r�r\rnr�r(r)r1rWrXr�rAr�Zheader_namesZskipsZcontent_lengthrqr�rrrr	�s0	


zHTTPConnection._send_requestcCs�|jr|j��rd|_|jtks&|jr0t|j��|jdkrR|j|j|j|jd�}n|j|j|jd�}z\z|�	�Wnt
k
r�|���YnX|jt
ks�t�t|_|jr�|��n||_|WS|���YnXdS)a)Get the response from the server.

        If the HTTPConnection is in the correct state, returns an
        instance of HTTPResponse or of whatever object is returned by
        the response_class variable.

        If a request has not been sent or if a previous response has
        not be handled, ResponseNotReady is raised.  If the HTTP
        response indicates that the connection should be closed, then
        it will be closed before the response is returned.  When the
        connection is closed, the underlying socket is closed.
        Nrr�)r�r|r�rrrKr�rVrLrs�ConnectionErrorrtrUrNr�r�)r1r�rrr�getresponses0

�
zHTTPConnection.getresponse)NN)NF)FF)N)%r5r6r7r�r�rr��	HTTP_PORTr�r�rK�staticmethodr�r�r��_GLOBAL_DEFAULT_TIMEOUTrYr�r�r�r�r�rtr�r�r�r�r�r�r�r�r�r�rr�r	rrrrrrsL

�

	&
6�
	
�.csHeZdZdZeZdddejdfdddd��fdd�Z�fdd�Z	�Z
S)	�HTTPSConnectionz(This class allows communication via SSL.Nr�)�context�check_hostnamer�cs�tt|�j|||||	d�|dk	s2|dk	s2|dk	rHddl}
|
�dtd�||_||_|dkrtt�	�}|j
dk	rtd|_
|jtjk}|dkr�|j
}|r�|s�td��|s�|r�|�||�|j
dk	r�d|_
||_|dk	r�||j_
dS)N)r�rzTkey_file, cert_file and check_hostname are deprecated, use a custom context instead.rZTzMcheck_hostname needs a SSL context with either CERT_OPTIONAL or CERT_REQUIRED)rvrrY�warnings�warn�DeprecationWarning�key_file�	cert_file�sslZ_create_default_https_contextZpost_handshake_authZverify_modeZ	CERT_NONErr`Zload_cert_chain�_context)r1r�r�rrr�r�rrr�rZwill_verifyrxrrrYcs<���

zHTTPSConnection.__init__cs6t���|jr|j}n|j}|jj|j|d�|_dS)z(Connect to a host on a given (SSL) port.)�server_hostnameN)rvr�r�r�rZwrap_socketrV)r1rrxrrr��s

�zHTTPSConnection.connect)r5r6r7�__doc__�
HTTPS_PORTr�r�rrYr�r�rrrxrr\s��$rc@seZdZdS)rN�r5r6r7rrrrr�sc@seZdZdS)rNrrrrrr�sc@seZdZdS)rNrrrrrr�sc@seZdZdd�ZdS)rcCs|f|_||_dSru)�argsrO)r1rOrrrrY�szUnknownProtocol.__init__N�r5r6r7rYrrrrr�sc@seZdZdS)rNrrrrrr�sc@seZdZdS)r	Nrrrrrr	�sc@s$eZdZddd�Zdd�ZejZdS)r
NcCs|f|_||_||_dSru)r �partial�expected)r1r"r#rrrrY�szIncompleteRead.__init__cCs2|jdk	rd|j}nd}d|jjt|j�|fS)Nz, %i more expectedr[z%s(%i bytes read%s))r#ryr5r-r")r1�errr�__repr__�s
�zIncompleteRead.__repr__)N)r5r6r7rYr%r"�__str__rrrrr
�s
c@seZdZdS)rNrrrrrr�sc@seZdZdS)r
Nrrrrrr
�sc@seZdZdS)rNrrrrrr�sc@seZdZdS)rNrrrrrr�sc@seZdZdd�ZdS)rcCs|st|�}|f|_||_dSru)r^r r3r�rrrrY�szBadStatusLine.__init__Nr!rrrrr�sc@seZdZdd�ZdS)rcCst�|dt|f�dS)Nz&got more than %d bytes when reading %s)rrYr>)r1Z	line_typerrrrY�s�zLineTooLong.__init__Nr!rrrrr�sc@seZdZdd�ZdS)rcOs"t�|d�tj|f|�|�dS)Nr[)rrY�ConnectionResetError)r1�pos�kwrrrrY�szRemoteDisconnected.__init__Nr!rrrrr�s)r)ArZemail.parserrGZ
email.messager�r��rer�Zcollections.abcr�Zurllib.parser�__all__rrrNr�r�r�globals�updater��__members__rrr>r?�compile�	fullmatchrr�rrr�r�r(r�ZMessager)rBrI�BufferedIOBaserrr�ImportErrorrr0�	Exceptionrrrrrr	r
rr
rrrrr'rrrrrr�<module>s�F�



W8