AlkantarClanX12

Your IP : 18.217.208.220


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/http/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/http/__pycache__/client.cpython-35.pyc



��Yf���@sNdZddlZddlZddlZddlZddlZddlZddlZddl	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&d,d-�Z'Gd.d�dej(�Z)Gd/d�d�Z*yddl+Z+Wne,k
r�Yn$XGd0d1�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)@a�
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/python35/lib64/python3.5/http/client.py�
<dictcomp>ks	rii�ds[^:\s][^:\r\n]*s\n(?![ \t])|\r(?![ \t\n])z[- ]ZPATCHZPOSTZPUT�datacCs�y|jd�SWnotk
r�}zOt|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�sr'c@seZdZdd�ZdS)�HTTPMessagecCs�|j�d}t|�}g}d}xh|j�D]Z}|d|�j�|kr`d}n|dd�j�s|d}|r5|j|�q5W|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(�sr(cCs�g}xq|jtd�}t|�tkr:td��|j|�t|�tkritdt��|d	kr	Pq	Wdj|�jd�}t	j
jd|�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

rDcs�eZdZddddd�Zdd�Zdd�Zd	d
�Zdd�Z�fd
d�Z�fdd�Z	dd�Z
dd�Zddd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd@d(d)�ZdAd*d+�ZdB�fd,d-�Zd.d/�Zd0d1�Zd2d3�Zdd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Z �S)CrrNcCsw|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__cCsit|jjtd�d�}t|�tkr=td��|jdkr_tdt|��|sqt	d��y|j
dd�\}}}WnOtk
r�y"|j
dd�\}}d}Wntk
r�d}YnXYnX|jd	�s|j
�t|��y4t|�}|d
ks.|dkr:t|��Wntk
r[t|��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	rdSx�|j�\}}}|tkr8Pxg|jjtd�}t|�tkrotd��|j�}|s�P|j	dkr;t
d|�q;WqW||_|_|j�|_
|dkr�d|_n'|jd�r�d	|_nt|��t|j�|_|_|j	dkrSx$|jD]}t
d|d
d�q6W|jjd�}|r�|j�d
kr�d|_d|_n	d|_|j�|_d|_|jjd�}|jjd�}|r3|jr3yt|�|_Wntk
rd|_Yq<X|jdkr<d|_n	d|_|tks|tksd|kokdkns|jdkr�d|_|jr�|jr�|jdkr�d|_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�}|jdkrS|jjd�}|rOd|j�krOdSdS|jjd�ridS|r�d|j�kr�dS|jjd�}|r�d|j�kr�dSdS)NZ
connectionrd�closeTFz
keep-alivezproxy-connection)rCrjrKr+)r0ZconnZpconnrrrrk|szHTTPResponse._check_closecCs |j}d|_|j�dS)N)rBro)r0rBrrrr^�s		zHTTPResponse._close_connc
s,zt�j�Wd|jr'|j�XdS)N)�superrorBr^)r0)�	__class__rrro�s	zHTTPResponse.closecs't�j�|jr#|jj�dS)N)rp�flushrB)r0)rqrrrr�s
	zHTTPResponse.flushcCsdS)NTr)r0rrr�readable�szHTTPResponse.readablecCs
|jdkS)z!True if the connection is closed.N)rB)r0rrr�isclosed�szHTTPResponse.isclosedcCs�|jdkrdS|jdkr0|j�dS|dk	rqt|�}|j|�}t|�d|�j�S|jr�|j�S|j	dkr�|jj
�}nAy|j|j	�}Wntk
r�|j��YnXd|_	|j�|SdS)Nr9rgr)
rBrHr^�	bytearray�readinto�
memoryview�tobytesrN�_readall_chunkedrP�read�
_safe_readr
)r0�amt�br1�srrrrz�s*
	


	
zHTTPResponse.readcCs�|jdkrdS|jdkr0|j�dS|jrF|j|�S|jdk	r�t|�|jkr�t|�d|j�}|jj|�}|r�|r�|j�n1|jdk	r�|j|8_|js�|j�|S)Nrrg)	rBrHr^rN�_readinto_chunkedrPr,rwrv)r0r}r1rrrrv�s$
	


	
zHTTPResponse.readintocCs�|jjtd�}t|�tkr4td��|jd�}|dkr_|d|�}yt|d�SWntk
r�|j��YnXdS)Nr*z
chunk size�;r�)	rBr;r<r,r�findr_r\r^)r0r2�irrr�_read_next_chunk_size�s

z"HTTPResponse._read_next_chunk_sizecCsSxL|jjtd�}t|�tkr7td��|s>P|dkrPqWdS)Nr*ztrailer line�
�
r9)r�r�r9)rBr;r<r,r)r0r2rrr�_read_and_discard_trailer
sz&HTTPResponse._read_and_discard_trailercCs�|j}|s�|dk	r(|jd�y|j�}Wntk
rXtd��YnX|dkr|j�|j�d}||_|S)NrVr9r)rOr{r�r\r
r�r^)r0rOrrr�_get_chunk_lefts	



	zHTTPResponse._get_chunk_leftcCs�|jtkst�g}yPx<|j�}|dkr:P|j|j|��d|_q!Wdj|�SWn'tk
r�tdj|���YnXdS)Nrr9)	rNrJ�AssertionErrorr�r/r{rOr>r
)r0�valuerOrrrry3s

zHTTPResponse._readall_chunkedcCs�|jtkst�d}t|�}y�x�|j�}|dkrI|St|�|kr|j|�}|||_||S|d|�}|j|�}||d�}||7}d|_q-WWn.tk
r�tt	|d|����YnXdS)Nr)
rNrJr�rwr�r,�_safe_readintorOr
�bytes)r0r}�total_bytes�mvbrOr1�temp_mvbrrrrAs&


zHTTPResponse._readinto_chunkedcCs|g}xf|dkrn|jjt|t��}|sNtdj|�|��|j|�|t|�8}q	Wdj|�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)rBrz�min�	MAXAMOUNTr
r>r/r,)r0r|r~�chunkrrrr{Ys
zHTTPResponse._safe_readcCs�d}t|�}x�|t|�kr�tt|�kr^|dt�}|jj|�}n|jj|�}|s�tt|d|��t|���||d�}||7}qW|S)z2Same as _safe_read, but for reading into a buffer.rN)rwr,r�rBrvr
r�)r0r}r�r�r�r1rrrr�ps%zHTTPResponse._safe_readintor*cCs�|jdks|jdkr"dS|jr8|j|�S|jdk	rk|dksb||jkrk|j}y|jj|�}Wn3tk
r�|dkr��|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.
        Nrgr9rr�ii@)	rBrHrN�_read1_chunkedrP�read1r\r^r,)r0r1�resultrrrr��s"	
*	


zHTTPResponse.read1cCsH|jdks|jdkr"dS|jr8|j|�S|jj|�S)Nrgr9)rBrHrN�
_peek_chunked�peek)r0r1rrrr��s
	
zHTTPResponse.peekcs�|jdks|jdkr"dS|jr;t�j|�S|jdk	rn|dkse||jkrn|j}|jj|�}|r�|r�|j�n$|jdk	r�|jt|�8_|S)Nrgr9r)rBrHrNrpr;rPr^r,)r0�limitr�)rqrrr;�s	*	

zHTTPResponse.readlinecCs�|j�}|dks$|dkr(dSd|ko?|knsJ|}|jj|�}|jt|�8_|s�td��|S)Nrr9)r�rBr�rOr,r
)r0r1rOrzrrrr��szHTTPResponse._read1_chunkedcCsSy|j�}Wntk
r(dSYnX|dkr9dS|jj|�d|�S)Nr9)r�r
rBr�)r0r1rOrrrr��s
	zHTTPResponse._peek_chunkedcCs
|jj�S)N)rB�fileno)r0rrrr��szHTTPResponse.filenocCsd|jdkrt��|jj|�p-|}t|t�sOt|d�rS|Sdj|�SdS)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)N)rC)r0rrr�info�szHTTPResponse.infocCs|jS)N)rT)r0rrr�geturl�szHTTPResponse.geturlcCs|jS)N)rL)r0rrr�getcode�szHTTPResponse.getcode���r�r�)!r4r5r6rUr`rnrkr^rorrrsrtrzrvr�r�r�ryrr{r�r�r�r;r�r�r�r�r�r�r�r�r�rr)rqrr�s<	!P
 	
	c@s<eZdZdZdZeZeZdZ	dZ
dejddd�Z
dddd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zddd�Zdddd�Zdd�Zdd �Zd!d"�Zdd#d$�Zdid%d&�Zd'd(�Zd)d*�Zd+d,�ZdS)-rrdzHTTP/1.1r*rNcCs�||_||_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�rrrrU�s										zHTTPConnection.__init__cCsV|jrtd��|j||�\|_|_|rE||_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_tunnel
s	zHTTPConnection.set_tunnelcCs	|dkr�|jd�}|jd�}||kr�yt||dd��}WnVtk
r�||dd�dkr�|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�"s
#	&zHTTPConnection._get_hostportcCs
||_dS)N)rG)r0�levelrrr�set_debuglevel6szHTTPConnection.set_debuglevelcCshd|j|jf}|jd�}|j|�xI|jj�D]8\}}d||f}|jd�}|j|�qBW|jd�|j|jd|j�}|j	�\}}	}
|	t
jjkr�|j
�td|	|
j�f��xn|jjtd�}t|�tkr*td	��|s1P|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 line�
r9rzheader:)r�r�r9)r�r�r�sendr�r��response_classrRrHr`�http�
HTTPStatusZOKro�OSErrorrhrBr;r<r,rrGrYr?)r0Zconnect_strZ
connect_bytes�headerr�Z
header_strZheader_bytes�responserKri�messager2rrr�_tunnel9s2	



	zHTTPConnection._tunnelcCs]|j|j|jf|j|j�|_|jjtjtj	d�|j
rY|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�connectXs
$	zHTTPConnection.connectcCsYt|_z&|j}|r.d|_|j�Wd|j}|rTd|_|j�XdS)z(Close the connection to the HTTP server.N)r�r�rRror�)r0rRr�rrrroas					zHTTPConnection.closecCs�|jdkr.|jr%|j�n	t��|jdkrPtdt|��d}t|d�r|jdkr~td�d}y
|j}Wnt	k
r�Yn,Xd|kr�d	}|jdkr�td
�x?|j
|�}|s�P|r�|jd�}|jj|�q�WdSy|jj|�Wn^t
k
r�t|tj�rqx7|D]}|jj|�qTWnt
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 rzzsendIng a read()ableFr}Tzencoding file using iso-8859-1z
iso-8859-1z9data should be a bytes-like object or an iterable, got %r)rR�	auto_openr�rrGrYrZr��mode�AttributeErrorrzrZsendall�	TypeErrorr��collections�Iterable�type)r0rZ	blocksizerr�Z	datablock�drrrr�osF	
	





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._outputcCs\|jjd�dj|j�}|jdd�=|j|�|dk	rX|j|�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
N)r9r9)r��extendr>r�)r0�message_bodyrIrrr�_send_output�s
zHTTPConnection._send_outputFc
Cs |jr!|jj�r!d|_|jtkr<t|_nt|j��||_|p]d}|j|�d|||jf}|j	|j
|��|jdkr|sd}|jd�r�t
|�\}}}}}|r.y|jd�}Wn!tk
r|jd�}YnX|jd	|�n�|jrL|j}	|j}
n|j}	|j}
y|	jd�}Wn!tk
r�|	jd�}YnX|	jd
�dkr�d|d
}|
|jkr�|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%s %s %srdrWr�r�ZidnaZHostr)r�[�]z%s:%szAccept-EncodingZidentity)r�rtr�r��_CS_REQ_STARTEDr
rH�_validate_path�
_http_vsn_strr��_encode_request�	_http_vsnr]rrr�	putheaderr�r�r�r�r�r�r?)r0rSrT�	skip_host�skip_accept_encoding�requestZnetlocZnilZ
netloc_encr�r�Zhost_encrrr�
putrequest�sN		

				

zHTTPConnection.putrequestcCs
|jd�S)Nr�)r)r0r�rrrr�1szHTTPConnection._encode_requestcCsCtj|�}|r?djd|j�t��}t|��dS)zValidate a url for putrequest.zJURL can't contain control characters. {url!r} (found at least {matched!r})ZmatchedN)�!_contains_disallowed_url_pchar_re�search�format�group�localsr)r0rT�matchrIrrrr�5s
	zHTTPConnection._validate_pathcGs |jtkrt��t|d�r6|jd�}t|�sUtd|f��t|�}x�t|�D]�\}}t|d�r�|jd�||<n(t	|t
�r�t|�jd�||<t||�rntd||f��qnWdj
|�}|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.putheadercCs5|jtkrt|_n	t��|j|�dS)a�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.  The message body will be sent in the same packet as the
        message headers if it is a string, otherwise it is sent as a separate
        packet.
        N)r�r��_CS_REQ_SENTrr�)r0r�rrr�
endheaders\s		zHTTPConnection.endheaderscCs|j||||�dS)z&Send a complete request to the server.N)�
_send_request)r0rSrT�bodyrCrrrr�kszHTTPConnection.requestcCs�d}|j�tk}|dkr3|r3d}n�|dk	r�ytt|��}Wnhtk
r�y"ttj|j��j�}Wn1t	t
fk
r�|jdkr�td�YnXYnX|dk	r�|j
d|�dS)N�0rz
Cannot stat!!zContent-Length)�upper�_METHODS_EXPECTING_BODYrXr,r��os�fstatr��st_sizer�r�rGrYr�)r0r�rSZthelenZmethod_expects_bodyrrr�_set_content_lengthos	
"z"HTTPConnection._set_content_lengthc	Cs�tjdd�|D��}i}d|kr8d|d<d|krNd|d<|j|||�d|kr}|j||�x*|j�D]\}}|j||�q�Wt|t�r�t|d	�}|j	|�dS)
NcSsg|]}|j��qSr)r+)r�krrr�
<listcomp>�s	z0HTTPConnection._send_request.<locals>.<listcomp>r�r*r�zaccept-encodingr�zcontent-lengthr�)
�dict�fromkeysr�r�r�r�r�rXr'r�)	r0rSrTr�rCZheader_namesZskipsrmr�rrrr��s

zHTTPConnection._send_requestcCs'|jr!|jj�r!d|_|jtks9|jrHt|j��|jdkr{|j|j|jd|j�}n|j|jd|j�}yuy|j	�Wnt
k
r�|j��YnX|jt
ks�t�t|_|jr�|j�n	||_|SWn|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.
        NrrS)r�rtr�r�rrGr�rRrHrn�ConnectionErrorrorQrJr�r�)r0r�rrr�getresponse�s.	

		
	
zHTTPConnection.getresponse) r4r5r6r�r�rr��	HTTP_PORTr�r�rGr��_GLOBAL_DEFAULT_TIMEOUTrUr�r�r�r�r�ror�r�r�r�r�r�r�r�r�r�r�r�rrrrr�s6		0|cs^eZdZdZeZdddejddddd�fdd�Z�fdd�Z	�S)	�HTTPSConnectionz(This class allows communication via SSL.N�context�check_hostnamec
s�tt|�j||||�||_||_|dkrItj�}|jtjk}	|dkrp|j	}|r�|	r�t
d��|s�|r�|j||�||_||_
dS)NzMcheck_hostname needs a SSL context with either CERT_OPTIONAL or CERT_REQUIRED)rprrU�key_file�	cert_file�sslZ_create_default_https_contextZverify_modeZ	CERT_NONErr\Zload_cert_chain�_context�_check_hostname)
r0r�r�rrr�r�rrZwill_verify)rqrrrU�s			
	zHTTPSConnection.__init__cs�t�j�|jr"|j}n	|j}|jj|jd|�|_|jjr�|jr�yt	j
|jj�|�Wn5tk
r�|jj
tj�|jj��YnXdS)z(Connect to a host on a given (SSL) port.�server_hostnameN)rpr�r�r�rZwrap_socketrRrrrZmatch_hostnameZgetpeercert�	ExceptionZshutdownr�Z	SHUT_RDWRro)r0r	)rqrrr��s
		

zHTTPSConnection.connect)
r4r5r6�__doc__�
HTTPS_PORTr�r�rrUr�rr)rqrr�s	rc@seZdZdS)rN)r4r5r6rrrrrsc@seZdZdS)rN)r4r5r6rrrrrsc@seZdZdS)rN)r4r5r6rrrrrsc@seZdZdd�ZdS)rcCs|f|_||_dS)N)�argsrK)r0rKrrrrUszUnknownProtocol.__init__N)r4r5r6rUrrrrrsc@seZdZdS)rN)r4r5r6rrrrr"sc@seZdZdS)r	N)r4r5r6rrrrr	%sc@s7eZdZddd�Zdd�Zdd�ZdS)r
NcCs"|f|_||_||_dS)N)r
�partial�expected)r0rrrrrrU)s	zIncompleteRead.__init__cCsE|jdk	rd|j}nd}d|jjt|j�|fS)Nz, %i more expectedrWz%s(%i bytes read%s))rrqr4r,r)r0�errr�__repr__-s
zIncompleteRead.__repr__cCs
t|�S)N)rZ)r0rrr�__str__4szIncompleteRead.__str__)r4r5r6rUrrrrrrr
(sc@seZdZdS)rN)r4r5r6rrrrr7sc@seZdZdS)r
N)r4r5r6rrrrr
:sc@seZdZdS)rN)r4r5r6rrrrr=sc@seZdZdS)rN)r4r5r6rrrrr@sc@seZdZdd�ZdS)rcCs+|st|�}|f|_||_dS)N)rZr
r2)r0r2rrrrUDszBadStatusLine.__init__N)r4r5r6rUrrrrrCsc@seZdZdd�ZdS)rcCstj|dt|f�dS)Nz&got more than %d bytes when reading %s)rrUr<)r0Z	line_typerrrrUKszLineTooLong.__init__N)r4r5r6rUrrrrrJsc@seZdZdd�ZdS)rcOs'tj|d�tj|||�dS)NrW)rrU�ConnectionResetError)r0�pos�kwrrrrUPszRemoteDisconnected.__init__N)r4r5r6rUrrrrrOs)@rZemail.parserr@Z
email.messager��ior��rer�r�Zurllib.parser�__all__r�rrJr�r�r��globals�updater�Z__members__r�rr�r<r=�compile�	fullmatchr�r�r�r�r�r'r�ZMessager(rD�BufferedIOBaserrr�ImportErrorrr/r
rrrrrr	r
rr
rrrrrrrrrrr�<module>Esx				����
0