Your IP : 3.144.14.16


Current Path : /lib64/python3.6/http/__pycache__/
Upload File :
Current File : //lib64/python3.6/http/__pycache__/client.cpython-36.opt-1.pyc

3

�me���@s`dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZdddddd	d
ddd
ddddddddgZdZ
dZdZdZdZdZe�jejj�dd�ejjj�D�ZdZdZd Zejd!�jZejd"�jZ ejd#�Z!d$d%d&hZ"d@d(d)�Z#Gd*d+�d+ej$j%�Z&e&fd,d-�Z'Gd.d�dej(�Z)Gd/d�d�Z*yddl+Z+Wne,k
�rZYnXGd0d1�d1e*�Z-ej.d1�Gd2d�de/�Z0Gd3d�de0�Z1Gd4d�de0�Z2Gd5d�de0�Z3Gd6d	�d	e0�Z4Gd7d
�d
e0�Z5Gd8d�de0�Z6Gd9d
�d
e0�Z7Gd:d�de7�Z8Gd;d�de7�Z9Gd<d�de7�Z:Gd=d�de0�Z;Gd>d�de0�Z<Gd?d�de=e;�Z>e0Z?dS)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�Pi�ZUNKNOWNZIdlezRequest-startedzRequest-sentcCsi|]}|j|�qS�)�phrase)�.0�vrr�/usr/lib64/python3.6/client.py�
<dictcomp>ksrii�ds[^:\s][^:\r\n]*s\n(?![ \t])|\r(?![ \t\n])z[- ]ZPATCHZPOSTZPUT�datacCsfy
|jd�Stk
r`}z:t|j|j|j|jd|j�||j|j�|f�d�WYdd}~XnXdS)z<Call data.encode("latin-1") but show a better error message.zlatin-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)�HTTPMessagecCsn|j�d}t|�}g}d}xL|j�D]@}|d|�j�|krDd}n|dd�j�sXd}|r&|j|�q&W|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__r3rrrrr(�sr(cCs|g}xR|jtd�}t|�tkr(td��|j|�t|�tkrJtdt��|d	krPqWdj|�jd�}t	j
j|d�j|�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*zheader linezgot more than %d headers�
�
�z
iso-8859-1)�_class)r7r8r9)
�readline�_MAXLINEr,rr/�_MAXHEADERSr�join�decode�email�parserZParserZparsestr)�fpr:�headersr2Zhstringrrr�
parse_headers�s

rDcseZdZd@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&�ZdCd(d)�ZdEd*d+�ZdG�fd,d-�	Zd.d/�Zd0d1�Zd2d3�ZdHd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Z �Z!S)IrrNcCsR|jd�|_||_||_d|_|_t|_t|_t|_	t|_
t|_t|_t|_
dS)N�rb)�makefilerB�
debuglevel�_methodrC�msg�_UNKNOWN�version�status�reason�chunked�
chunk_left�length�
will_close)r0�sockrG�method�urlrrr�__init__�szHTTPResponse.__init__cCst|jjtd�d�}t|�tkr*td��|jdkrBtdt|��|sNt	d��y|j
dd�\}}}WnFtk
r�y|j
dd�\}}d}Wntk
r�d}YnXYnX|jd	�s�|j
�t|��y$t|�}|d
ks�|dkr�t|��Wntk
�rt|��YnX|||fS)Nr*z
iso-8859-1zstatus linerzreply:z-Remote end closed connection without response��zHTTP/ri�)�strrBr;r<r,rrG�print�reprr�split�
ValueError�
startswith�_close_connr�int)r0r2rKrLrMrrr�_read_statuss2

zHTTPResponse._read_statuscCs|jdk	rdSxh|j�\}}}|tkr(PxJ|jjtd�}t|�tkrNtd��|j�}|s\P|j	dkr*t
d|�q*WqW||_|_|j�|_
|dkr�d|_n|jd�r�d	|_nt|��t|j�|_|_|j	dk�r�x&|jD]}t
d|d
|jj|��q�W|jjd�}|�r,|j�dk�r,d
|_d|_nd|_|j�|_d|_|jjd�}|jjd�}|�r�|j�r�yt|�|_Wntk
�r�d|_YnX|jdk�r�d|_nd|_|tk�s�|tk�s�d|k�o�dkn�s�|jdk�r�d|_|j�r|j�r|jdk�rd
|_dS)Nr*zheader linerzheader:�HTTP/1.0�HTTP/0.9�
zHTTP/1.�r)ztransfer-encodingrNTFzcontent-lengthr���HEAD)rarb)rCr`ZCONTINUErBr;r<r,r�striprGrY�coderLrMrKr]rrDrI�getr+rNrO�_check_closerQrPr_r\Z
NO_CONTENTZNOT_MODIFIEDrH)r0rKrLrM�skip�hdrZtr_encrPrrr�begin,sf






zHTTPResponse.begincCs�|jjd�}|jdkr:|jjd�}|r6d|j�kr6dSdS|jjd�rJdS|r^d|j�kr^dS|jjd�}|r~d|j�kr~dSdS)NZ
connectionrd�closeTFz
keep-alivezproxy-connection)rCrirKr+)r0ZconnZpconnrrrrj|s
zHTTPResponse._check_closecCs|j}d|_|j�dS)N)rBrn)r0rBrrrr^�szHTTPResponse._close_connc
s$zt�j�Wd|jr|j�XdS)N)�superrnrBr^)r0)�	__class__rrrn�szHTTPResponse.closecst�j�|jr|jj�dS)N)ro�flushrB)r0)rprrrq�s
zHTTPResponse.flushcCsdS)zAlways returns TrueTr)r0rrr�readable�szHTTPResponse.readablecCs
|jdkS)z!True if the connection is closed.N)rB)r0rrr�isclosed�szHTTPResponse.isclosedcCs�|jdkrdS|jdkr$|j�dS|dk	rRt|�}|j|�}t|�d|�j�S|jr`|j�S|j	dkrv|jj
�}n6y|j|j	�}Wntk
r�|j��YnXd|_	|j�|SdS)Nr9rfr)
rBrHr^�	bytearray�readinto�
memoryview�tobytesrN�_readall_chunkedrP�read�
_safe_readr
)r0�amt�br1�srrrry�s*



zHTTPResponse.readcCs�|jdkrdS|jdkr$|j�dS|jr4|j|�S|jdk	r^t|�|jkr^t|�d|j�}|jj|�}|r~|r~|j�n&|jdk	r�|j|8_|js�|j�|S)z^Read up to len(b) bytes into bytearray b and return the number
        of bytes read.
        Nrrf)	rBrHr^rN�_readinto_chunkedrPr,rvru)r0r|r1rrrru�s$






zHTTPResponse.readintocCsp|jjtd�}t|�tkr$td��|jd�}|dkrB|d|�}y
t|d�Stk
rj|j��YnXdS)Nr*z
chunk size�;r�)	rBr;r<r,r�findr_r\r^)r0r2�irrr�_read_next_chunk_sizes

z"HTTPResponse._read_next_chunk_sizecCs>x8|jjtd�}t|�tkr&td��|s,P|dkrPqWdS)Nr*ztrailer line�
r8r9)r�r8r9)rBr;r<r,r)r0r2rrr�_read_and_discard_trailersz&HTTPResponse._read_and_discard_trailercCsl|j}|sh|dk	r|jd�y|j�}Wntk
rDtd��YnX|dkrb|j�|j�d}||_|S)NrVr9r)rOrzr�r\r
r�r^)r0rOrrr�_get_chunk_left s
zHTTPResponse._get_chunk_leftcCsdg}y8x,|j�}|dkrP|j|j|��d|_qWdj|�Stk
r^tdj|���YnXdS)Nrr9)r�r/rzrOr>r
)r0�valuerOrrrrx8s

zHTTPResponse._readall_chunkedcCs�d}t|�}yvxp|j�}|dkr$|St|�|krL|j|�}|||_||S|d|�}|j|�}||d�}||7}d|_qWWn(tk
r�tt|d|����YnXdS)Nr)rvr�r,�_safe_readintorOr
�bytes)r0r|�total_bytes�mvbrOr1�temp_mvbrrrr~Fs$


zHTTPResponse._readinto_chunkedcCsXg}xH|dkrL|jjt|t��}|s4tdj|�|��|j|�|t|�8}qWdj|�S)aVRead the number of bytes requested, compensating for partial reads.

        Normally, we have a blocking socket, but a read() can be interrupted
        by a signal (resulting in a partial read).

        Note that we cannot distinguish between EOF and an interrupt when zero
        bytes have been read. IncompleteRead() will be raised in this
        situation.

        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.
        rr9)rBry�min�	MAXAMOUNTr
r>r/r,)r0r{r}�chunkrrrrz^s

zHTTPResponse._safe_readcCs�d}t|�}xt|t|�kr�tt|�kr@|dt�}|jj|�}n|jj|�}|sjtt|d|��t|���||d�}||7}qW|S)z2Same as _safe_read, but for reading into a buffer.rN)rvr,r�rBrur
r�)r0r|r�r�r�r1rrrr�uszHTTPResponse._safe_readintor*cCs�|jdks|jdkrdS|jr(|j|�S|jdk	rJ|dksD||jkrJ|j}y|jj|�}Wn*tk
r�|dkrt�|jjd�}YnX|r�|r�|j�n|jdk	r�|jt|�8_|S)zvRead with at most one underlying system call.  If at least one
        byte is buffered, return that instead.
        Nrfr9rr�ii@)	rBrHrN�_read1_chunkedrP�read1r\r^r,)r0r1�resultrrrr��s"



zHTTPResponse.read1cCs4|jdks|jdkrdS|jr(|j|�S|jj|�S)Nrfr9)rBrHrN�
_peek_chunked�peek)r0r1rrrr��s

zHTTPResponse.peekcs�|jdks|jdkrdS|jr*t�j|�S|jdk	rL|dksF||jkrL|j}|jj|�}|rl|rl|j�n|jdk	r�|jt|�8_|S)Nrfr9r)rBrHrNror;rPr^r,)r0�limitr�)rprrr;�s


zHTTPResponse.readlinecCsf|j�}|dks|dkrdSd|ko.|kns8|}|jj|�}|jt|�8_|sbtd��|S)Nrr9)r�rBr�rOr,r
)r0r1rOryrrrr��szHTTPResponse._read1_chunkedcCsBy|j�}Wntk
r dSX|dkr.dS|jj|�d|�S)Nr9)r�r
rBr�)r0r1rOrrrr��szHTTPResponse._peek_chunkedcCs
|jj�S)N)rB�fileno)r0rrrr��szHTTPResponse.filenocCsH|jdkrt��|jj|�p|}t|t�s6t|d�r:|Sdj|�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, )rCrZget_all�
isinstancerX�hasattrr>)r0r%�defaultrCrrr�	getheader�s
zHTTPResponse.getheadercCs|jdkrt��t|jj��S)z&Return list of (header, value) tuples.N)rCr�list�items)r0rrr�
getheaders�s
zHTTPResponse.getheaderscCs|S)Nr)r0rrrr��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.

        )rC)r0rrr�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.

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

        )rL)r0rrr�getcodeszHTTPResponse.getcode)rNN)N���)r�r�)r�r�)r�)N)"r4r5r6rUr`rmrjr^rnrqrrrsryrur�r�r�rxr~rzr�r�r�r;r�r�r�r�r�r�r�r�r��
__classcell__rr)rprr�s<	
!P

 "

	

c@s�eZdZdZdZeZeZdZ	dZ
edd��Zedd��Z
d	ejd	fd
d�Zd.dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd/dd �Zd0d!d"�Zd#d$�Zd1dd%�d&d'�Zd	ifdd%�d(d)�Zd*d+�Zd,d-�Z d	S)2rrdzHTTP/1.1r*rcCst|tj�S)zFTest whether a file-like object is a text or a binary stream.
        )r��io�
TextIOBase)�streamrrr�
_is_textIO(szHTTPConnection._is_textIOcCsd|dkr|j�tkrdSdSt|d�r*dSyt|�}|jStk
rLYnXt|t�r`t|�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.
        Nrry)	�upper�_METHODS_EXPECTING_BODYr�rv�nbytes�	TypeErrorr�rXr,)�bodyrSZmvrrr�_get_content_length.s

z"HTTPConnection._get_content_lengthNcCs\||_||_d|_g|_d|_t|_d|_d|_d|_	i|_
|j||�\|_|_
tj|_dS)N)�timeout�source_addressrR�_buffer�_HTTPConnection__response�_CS_IDLE�_HTTPConnection__staterH�_tunnel_host�_tunnel_port�_tunnel_headers�
_get_hostport�host�port�socketZcreate_connection�_create_connection)r0r�r�r�r�rrrrUNszHTTPConnection.__init__cCs<|jrtd��|j||�\|_|_|r.||_n
|jj�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 HTML 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)rR�RuntimeErrorr�r�r�r��clear)r0r�r�rCrrr�
set_tunnelaszHTTPConnection.set_tunnelcCs�|dkr�|jd�}|jd�}||kr�yt||dd��}WnHtk
r�||dd�dkrh|j}ntd||dd���YnX|d|�}n|j}|r�|ddkr�|ddkr�|dd	�}||fS)
Nr)�]r*rWznonnumeric port: '%s'r�[r�r�)�rfindr_r\�default_portr)r0r�r�r��jrrrr�ys

zHTTPConnection._get_hostportcCs
||_dS)N)rG)r0�levelrrr�set_debuglevel�szHTTPConnection.set_debuglevelcCsd|j|jf}|jd�}|j|�x6|jj�D](\}}d||f}|jd�}|j|�q0W|jd�|j|j|jd�}|j	�\}}	}
|	t
jjkr�|j
�td|	|
j�f��xP|jjtd�}t|�tkr�td	��|s�P|dkr�P|jdkr�td
|j��q�WdS)NzCONNECT %s:%d HTTP/1.0
�asciiz%s: %s
zlatin-1�
)rSzTunnel connection failed: %d %sr*zheader liner8r9rzheader:)r�r8r9)r�r�r�sendr�r��response_classrRrHr`�http�
HTTPStatusZOKrn�OSErrorrgrBr;r<r,rrGrYr?)r0Zconnect_strZ
connect_bytes�headerr�Z
header_strZheader_bytes�responserKrh�messager2rrr�_tunnel�s2





zHTTPConnection._tunnelcCsB|j|j|jf|j|j�|_|jjtjtj	d�|j
r>|j�dS)z3Connect to the host and port specified in __init__.r*N)r�r�r�r�r�rRZ
setsockoptr�ZIPPROTO_TCPZTCP_NODELAYr�r�)r0rrr�connect�s
zHTTPConnection.connectcCsBt|_z|j}|r d|_|j�Wd|j}|r<d|_|j�XdS)z(Close the connection to the HTTP server.N)r�r�rRrnr�)r0rRr�rrrrn�szHTTPConnection.closecCs|jdkr |jr|j�nt��|jdkr8tdt|��d}t|d�r�|jdkrXtd�|j|�}|rx|jdkrxtd�x.|j	|�}|s�P|r�|j
d�}|jj|�qzWdSy|jj|�WnNtk
�r
t
|tj�r�x*|D]}|jj|�q�Wntd	t|���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:i ryzsendIng a read()ablezencoding file using iso-8859-1z
iso-8859-1z9data should be a bytes-like object or an iterable, got %r)rR�	auto_openr�rrGrYrZr�r�ryrZsendallr�r��collections�Iterable�type)r0r�	blocksizer�	datablock�drrrr��s:







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

        Assumes that the line does *not* end with \r\n.
        N)r�r/)r0r}rrr�_output�szHTTPConnection._outputccsdd}|jdkrtd�|j|�}|r6|jdkr6td�x(|j|�}|sHP|rV|jd�}|Vq8WdS)Ni rzsendIng a read()ablezencoding file using iso-8859-1z
iso-8859-1)rGrYr�ryr)r0rrr�rr�rrr�_read_readable�s



zHTTPConnection._read_readableFcCs$|jjd
�dj|j�}|jdd�=|j|�|dk	�r t|d�rN|j|�}nZyt|�WnFtk
r�yt|�}Wn$tk
r�tdt	|���YnXYnX|f}xZ|D]R}|s�|j
dkr�td�q�|r�|jdkr�t
|�d	�d
�jd�|d}|j|�q�W|�r |jdk�r |jd�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.
        r9s
NryzAmessage_body should be a bytes-like object or an iterable, got %rrzZero length chunk ignoredrd�Xz
r�s0

)r9r9)r��extendr>r�r�r�rvr��iterr�rGrY�	_http_vsnr,r)r0�message_body�encode_chunkedrIZchunksr�rrr�_send_outputs4




zHTTPConnection._send_outputc

Cs�|jr|jj�rd|_|jtkr(t|_n
t|j��||_|s@d}tj|�}|rht	d|�d|j
��d���d|||jf}|j|j
d��|jdk�r�|�s�d	}|jd
�r�t|�\}}}}}|r�y|j
d�}	Wntk
r�|j
d�}	YnX|jd|	�n�|j�r|j}
|j}n|j}
|j}y|
j
d�}Wn tk
�rJ|
j
d�}YnX|
jd
�dk�rhd|d}||jk�r�|jd|�n|jd�}|jdd||f�|�s�|jdd�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&URL can't contain control characters. z (found at least �)z%s %s %sr�rdrWr�ZidnaZHostr)r�[�]z%s:%szAccept-EncodingZidentity)r�rsr�r��_CS_REQ_STARTEDr
rH�!_contains_disallowed_url_pchar_re�searchr�group�
_http_vsn_strr�rr�r]rr�	putheaderr�r�r�r�r�r�r?)
r0rSrT�	skip_host�skip_accept_encoding�match�requestZnetlocZnilZ
netloc_encr�r�Zhost_encrrr�
putrequest9sT





zHTTPConnection.putrequestcGs�|jtkrt��t|d�r$|jd�}t|�s:td|f��t|�}xht|�D]\\}}t|d�rn|jd�||<nt	|t
�r�t|�jd�||<t||�rLtd||f��qLWdj
|�}|d|}|j|�dS)	zkSend a request header line to the server.

        For example: h.putheader('Accept', 'text/html')
        rr�zInvalid header name %rzlatin-1zInvalid header value %rs
	s: N)r�r�rr�r�_is_legal_header_namer\r��	enumerater�r_rX�_is_illegal_header_valuer>r�)r0r��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.
        )r�N)r�r��_CS_REQ_SENTrr�)r0r�r�rrr�
endheaders�s
zHTTPConnection.endheaderscCs|j|||||�dS)z&Send a complete request to the server.N)�
_send_request)r0rSrTr�rCr�rrrr��szHTTPConnection.requestcCs�tdd�|D��}i}d|kr&d|d<d|kr6d|d<|j||f|�d|kr�d	|kr�d
}|j||�}|dkr�|dk	r�|jdkr�td|�d
}|jdd�q�|jdt|��nd
}x |j�D]\}	}
|j|	|
�q�Wt|t�r�t	|d�}|j
||d�dS)Ncss|]}|j�VqdS)N)r+)r�krrr�	<genexpr>�sz/HTTPConnection._send_request.<locals>.<genexpr>r�r*r�zaccept-encodingr�zcontent-lengthztransfer-encodingFrzUnable to determine size of %rTzTransfer-EncodingrNzContent-Lengthr�)r�)�	frozensetr�r�rGrYr�rXr�r�r'r�)r0rSrTr�rCr�Zheader_namesZskipsZcontent_lengthrlr�rrrr��s0	


zHTTPConnection._send_requestcCs�|jr|jj�rd|_|jtks&|jr0t|j��|jdkrR|j|j|j|jd�}n|j|j|jd�}yLy|j	�Wnt
k
r�|j��YnXt|_|j
r�|j�n||_|S|j��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.
        Nr)rS)r�rsr�r�rrGr�rRrHrm�ConnectionErrorrnr�rQ)r0r�rrr�getresponses,


zHTTPConnection.getresponse)NN)NF)FF)N)!r4r5r6r�r�rr��	HTTP_PORTr�r�rG�staticmethodr�r�r��_GLOBAL_DEFAULT_TIMEOUTrUr�r�r�r�r�rnr�r�r�r�r�r�r�r�r�r�rrrrrs: 
	'
6

.csFeZdZdZeZdddejdfddd��fdd�Z�fdd�Z	�Z
S)�HTTPSConnectionz(This class allows communication via SSL.N)�context�check_hostnamecs�tt|�j||||�|dk	s.|dk	s.|dk	rDddl}	|	jdtd�||_||_|dkr`tj	�}|j
tjk}
|dkrz|j}|r�|
r�t
d��|s�|r�|j||�||_||_dS)NrzTkey_file, cert_file and check_hostname are deprecated, use a custom context instead.rVzMcheck_hostname needs a SSL context with either CERT_OPTIONAL or CERT_REQUIRED)rorrU�warnings�warn�DeprecationWarning�key_file�	cert_file�sslZ_create_default_https_contextZverify_modeZ	CERT_NONErr\Zload_cert_chain�_context�_check_hostname)r0r�r�rrr�r�rrrZwill_verify)rprrrUas(
zHTTPSConnection.__init__cs�t�j�|jr|j}n|j}|jj|j|d�|_|jjr�|jr�yt	j
|jj�|�Wn.tk
r�|jj
tj�|jj��YnXdS)z(Connect to a host on a given (SSL) port.)�server_hostnameN)ror�r�r�r	Zwrap_socketrRrr
rZmatch_hostnameZgetpeercert�	ExceptionZshutdownr�Z	SHUT_RDWRrn)r0r)rprrr�|s



zHTTPSConnection.connect)r4r5r6�__doc__�
HTTPS_PORTr�r�r�rUr�r�rr)rprrZsrc@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdd�ZdS)rcCs|f|_||_dS)N)�argsrK)r0rKrrrrU�szUnknownProtocol.__init__N)r4r5r6rUrrrrr�sc@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdS)r	N)r4r5r6rrrrr	�sc@s&eZdZddd�Zdd�Zdd�ZdS)	r
NcCs|f|_||_||_dS)N)r�partial�expected)r0rrrrrrU�szIncompleteRead.__init__cCs2|jdk	rd|j}nd}d|jjt|j�|fS)Nz, %i more expectedrWz%s(%i bytes read%s))rrpr4r,r)r0�errr�__repr__�s

zIncompleteRead.__repr__cCst|�S)N)rZ)r0rrr�__str__�szIncompleteRead.__str__)N)r4r5r6rUrrrrrrr
�s
c@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdS)r
N)r4r5r6rrrrr
�sc@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdS)rN)r4r5r6rrrrr�sc@seZdZdd�ZdS)rcCs|st|�}|f|_||_dS)N)rZrr2)r0r2rrrrU�szBadStatusLine.__init__N)r4r5r6rUrrrrr�sc@seZdZdd�ZdS)rcCstj|dt|f�dS)Nz&got more than %d bytes when reading %s)rrUr<)r0Z	line_typerrrrU�szLineTooLong.__init__N)r4r5r6rUrrrrr�sc@seZdZdd�ZdS)rcOs"tj|d�tj|f|�|�dS)NrW)rrU�ConnectionResetError)r0�pos�kwrrrrU�szRemoteDisconnected.__init__N)r4r5r6rUrrrrr�s)r)@r
Zemail.parserr@Z
email.messager�r��os�rer�r�Zurllib.parser�__all__r�rrJr�r�r��globals�updater��__members__r�rr�r<r=�compile�	fullmatchr�r�r�r�r�r'r�ZMessager(rD�BufferedIOBaserrr�ImportErrorrr/rrrrrrr	r
rr
rrrrrrrrrrr�<module>Es�


>;6