AlkantarClanX12

Your IP : 18.221.183.34


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.opt-2.pyc



���]���@sHddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddddddd	d
ddd
dddddddgZdZdZ
dZdZdZdZe�jejj�dd�ejjj�D�ZdZdZdZejd �jZejd!�jZejd"�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$XGd/d0�d0e)�Z,ej-d0�Gd1d�de.�Z/Gd2d�de/�Z0Gd3d�de/�Z1Gd4d�de/�Z2Gd5d�de/�Z3Gd6d	�d	e/�Z4Gd7d
�d
e/�Z5Gd8d�de/�Z6Gd9d
�d
e6�Z7Gd:d�de6�Z8Gd;d�de6�Z9Gd<d�de/�Z:Gd=d�de/�Z;Gd>d�de<e:�Z=e/Z>dS)?�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�+/opt/alt/python35/lib64/python3.5/client.py�
<dictcomp>ks	rii�ds[^:\s][^:\r\n]*s\n(?![ \t])|\r(?![ \t\n])z[- ]ZPATCHZPOST�PUT�datacCs�y|jd�SWnotk
r�}zOt|j|j|j|jd|j�||j|j�|f�d�WYdd}~XnXdS)Nzlatin-1z`%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') if you want to send it encoded in UTF-8.)�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)N�:r�)�lower�len�keys�isspace�append)�selfr&�nZlstZhit�linerrr�getallmatchingheaders�s
	z!HTTPMessage.getallmatchingheadersN)�__name__�
__module__�__qualname__r4rrrrr)�sr)cCs�g}xq|jtd�}t|�tkr:td��|j|�t|�tkritdt��|d	kr	Pq	Wdj|�jd�}t	j
jd|�j|�S)
Nr+zheader linezgot more than %d headers�
�
�z
iso-8859-1�_class)r8r9r:)
�readline�_MAXLINEr-rr0�_MAXHEADERSr�join�decode�email�parserZParserZparsestr)�fpr;�headersr3Zhstringrrr�
parse_headers�s

rEcs�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)�makefilerC�
debuglevel�_methodrD�msg�_UNKNOWN�version�status�reason�chunked�
chunk_left�length�
will_close)r1�sockrH�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�)�strrCr<r=r-rrH�print�reprr�split�
ValueError�
startswith�_close_connr�int)r1r3rLrMrNrrr�_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-encodingrOTFzcontent-lengthr���HEAD)rbrc)rDraZCONTINUErCr<r=r-r�striprHrZ�coderMrNrLr^rrErJ�getr,rOrP�_check_closerRrQr`r]Z
NO_CONTENTZNOT_MODIFIEDrI)r1rLrMrN�skip�hdrZtr_encrQrrr�begin,sf			
		

zHTTPResponse.begincCs�|jjd�}|jdkrS|jjd�}|rOd|j�krOdSdS|jjd�ridS|r�d|j�kr�dS|jjd�}|r�d|j�kr�dSdS)N�
connectionre�closeTFz
keep-alivezproxy-connection)rDrkrLr,)r1�connZpconnrrrrl|szHTTPResponse._check_closecCs |j}d|_|j�dS)N)rCrq)r1rCrrrr_�s		zHTTPResponse._close_connc
s,zt�j�Wd|jr'|j�XdS)N)�superrqrCr_)r1)�	__class__rrrq�s	zHTTPResponse.closecs't�j�|jr#|jj�dS)N)rs�flushrC)r1)rtrrru�s
	zHTTPResponse.flushcCsdS)NTr)r1rrr�readable�szHTTPResponse.readablecCs
|jdkS)N)rC)r1rrr�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)Nr:rhr)
rCrIr_�	bytearray�readinto�
memoryview�tobytesrO�_readall_chunkedrQ�read�
_safe_readr
)r1�amt�br2�srrrr}�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)Nrrh)	rCrIr_rO�_readinto_chunkedrQr-rzry)r1r�r2rrrry�s$
	


	
zHTTPResponse.readintocCs�|jjtd�}t|�tkr4td��|jd�}|dkr_|d|�}yt|d�SWntk
r�|j��YnXdS)Nr+z
chunk size�;r�)	rCr<r=r-r�findr`r]r_)r1r3�irrr�_read_next_chunk_size�s

z"HTTPResponse._read_next_chunk_sizecCsSxL|jjtd�}t|�tkr7td��|s>P|dkrPqWdS)Nr+ztrailer line�
�
r:)r�r�r:)rCr<r=r-r)r1r3rrr�_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)NrWr:r)rPr~r�r]r
r�r_)r1rPrrr�_get_chunk_lefts	



	zHTTPResponse._get_chunk_leftcCs�g}yPx<|j�}|dkr%P|j|j|��d|_qWdj|�SWn'tk
rtdj|���YnXdS)Nrr:)r�r0r~rPr?r
)r1�valuerPrrrr|3s

zHTTPResponse._readall_chunkedcCs�d}t|�}y�x�|j�}|dkr4|St|�|krj|j|�}|||_||S|d|�}|j|�}||d�}||7}d|_qWWn.tk
r�tt|d|����YnXdS)Nr)rzr�r-�_safe_readintorPr
�bytes)r1r��total_bytes�mvbrPr2�temp_mvbrrrr�As$


zHTTPResponse._readinto_chunkedcCs|g}xf|dkrn|jjt|t��}|sNtdj|�|��|j|�|t|�8}q	Wdj|�S)Nrr:)rCr}�min�	MAXAMOUNTr
r?r0r-)r1rr��chunkrrrr~Ys
zHTTPResponse._safe_readcCs�d}t|�}x�|t|�kr�tt|�kr^|dt�}|jj|�}n|jj|�}|s�tt|d|��t|���||d�}||7}qW|S)Nr)rzr-r�rCryr
r�)r1r�r�r�r�r2rrrr�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)Nrhr:rr�ii@)	rCrIrO�_read1_chunkedrQ�read1r]r_r-)r1r2�resultrrrr��s"	
*	


zHTTPResponse.read1cCsH|jdks|jdkr"dS|jr8|j|�S|jj|�S)Nrhr:)rCrIrO�
_peek_chunked�peek)r1r2rrrr��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)Nrhr:r)rCrIrOrsr<rQr_r-)r1�limitr�)rtrrr<�s	*	

zHTTPResponse.readlinecCs�|j�}|dks$|dkr(dSd|ko?|knsJ|}|jj|�}|jt|�8_|s�td��|S)Nrr:)r�rCr�rPr-r
)r1r2rPr}rrrr��szHTTPResponse._read1_chunkedcCsSy|j�}Wntk
r(dSYnX|dkr9dS|jj|�d|�S)Nr:)r�r
rCr�)r1r2rPrrrr��s
	zHTTPResponse._peek_chunkedcCs
|jj�S)N)rC�fileno)r1rrrr��szHTTPResponse.filenocCsd|jdkrt��|jj|�p-|}t|t�sOt|d�rS|Sdj|�SdS)N�__iter__z, )rDrZget_all�
isinstancerY�hasattrr?)r1r&�defaultrDrrr�	getheader�s	zHTTPResponse.getheadercCs+|jdkrt��t|jj��S)N)rDr�list�items)r1rrr�
getheaders�s	zHTTPResponse.getheaderscCs|S)Nr)r1rrrr��szHTTPResponse.__iter__cCs|jS)N)rD)r1rrr�info�szHTTPResponse.infocCs|jS)N)rU)r1rrr�geturl�szHTTPResponse.geturlcCs|jS)N)rM)r1rrr�getcode�szHTTPResponse.getcode���r�r�)!r5r6r7rVrarorlr_rqrurvrwr}ryr�r�r�r|r�r~r�r�r�r<r�r�r�r�r�r�r�r�r�rr)rtrr�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)-rrezHTTP/1.1r+rNcCs�||_||_d|_g|_d|_t|_d|_d|_d|_	i|_
|j||�\|_|_
tj|_dS)N)�timeout�source_addressrS�_buffer�_HTTPConnection__response�_CS_IDLE�_HTTPConnection__staterI�_tunnel_host�_tunnel_port�_tunnel_headers�
_get_hostport�host�port�socket�create_connection�_create_connection)r1r�r�r�r�rrrrV�s										zHTTPConnection.__init__cCsV|jrtd��|j||�\|_|_|rE||_n
|jj�dS)Nz.Can't set up tunnel for established connection)rS�RuntimeErrorr�r�r�r��clear)r1r�r�rDrrr�
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+rXznonnumeric port: '%s'r�[r�r�)�rfindr`r]�default_portr)r1r�r�r��jrrrr�"s
#	&zHTTPConnection._get_hostportcCs
||_dS)N)rH)r1�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�
rTzTunnel connection failed: %d %sr+zheader line�
r:rzheader:)r�r�r:)r�r�r�sendr�r��response_classrSrIra�http�
HTTPStatusZOKrq�OSErrorrirCr<r=r-rrHrZr@)r1Zconnect_strZ
connect_bytes�headerr�Z
header_strZheader_bytes�responserLrj�messager3rrr�_tunnel9s2	



	zHTTPConnection._tunnelcCs]|j|j|jf|j|j�|_|jjtjtj	d�|j
rY|j�dS)Nr+)r�r�r�r�r�rS�
setsockoptr��IPPROTO_TCP�TCP_NODELAYr�r�)r1rrr�connectXs
$	zHTTPConnection.connectcCsYt|_z&|j}|r.d|_|j�Wd|j}|rTd|_|j�XdS)N)r�r�rSrqr�)r1rSr�rrrrqas					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
dt|���YnXdS)Nrzsend:i r}zsendIng a read()ableFr�Tzencoding file using iso-8859-1z
iso-8859-1z9data should be a bytes-like object or an iterable, got %r)rS�	auto_openr�rrHrZr[r��mode�AttributeErrorr}r�sendall�	TypeErrorr��collections�Iterable�type)r1r�	blocksizerr�Z	datablock�drrrr�osF	
	





zHTTPConnection.sendcCs|jj|�dS)N)r�r0)r1r�rrr�_output�szHTTPConnection._outputcCs\|jjd�dj|j�}|jdd�=|j|�|dk	rX|j|�dS)Nr:s
)r:r:)r��extendr?r�)r1�message_bodyrJrrr�_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	�d
kr�d|d}|
|jkr�|jd|�n)|jd�}|jdd
||
f�|s|jdd�ndS)N�/z%s %s %srerXr�r�ZidnaZHostr*r�[�]z%s:%szAccept-Encoding�identity)r�rwr�r��_CS_REQ_STARTEDr
rI�_validate_path�
_http_vsn_strr��_encode_request�	_http_vsnr^rrr �	putheaderr�r�r�r�r�r�r@)r1rTrU�	skip_host�skip_accept_encoding�requestZnetloc�nilZ
netloc_encr�r�Zhost_encrrr�
putrequest�sN		

				

zHTTPConnection.putrequestcCs
|jd�S)Nr�)r)r1r�rrrr�1szHTTPConnection._encode_requestcCsCtj|�}|r?djd|j�t��}t|��dS)NzJURL can't contain control characters. {url!r} (found at least {matched!r})Zmatched)�!_contains_disallowed_url_pchar_re�search�format�group�localsr)r1rU�matchrJrrrr�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)Nrr�zInvalid header name %rzlatin-1zInvalid header value %rs
	s: )r�r�rr�r�_is_legal_header_namer]r��	enumerater�r`rY�_is_illegal_header_valuer?r�)r1r��valuesr�Z	one_valuer�rrrr�@s"	zHTTPConnection.putheadercCs5|jtkrt|_n	t��|j|�dS)N)r�r��_CS_REQ_SENTrr�)r1r�rrr�
endheaders\s		zHTTPConnection.endheaderscCs|j||||�dS)N)�
_send_request)r1rTrU�bodyrDrrrr�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_BODYrYr-r��os�fstatr��st_sizer�r�rHrZr�)r1r�rTZthelenZmethod_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�rr�r�r�rYr(r�)	r1rTrUr�rDZheader_namesZskipsrnr�rrrr��s

zHTTPConnection._send_requestcCs|jr!|jj�r!d|_|jtks9|jrHt|j��|jdkr{|j|j|jd|j�}n|j|jd|j�}y`y|j	�Wnt
k
r�|j��YnXt|_|j
r�|j�n	||_|SWn|j��YnXdS)NrrT)r�rwr�r�rrHr�rSrIro�ConnectionErrorrqr�rR)r1r�rrr�getresponse�s,	

		
	
zHTTPConnection.getresponse) r5r6r7r�r�rr��	HTTP_PORTr�r�rHr��_GLOBAL_DEFAULT_TIMEOUTrVr�r�r�r�r�rqr�r�r�r�r�r�r�r�r�rr�rrrrrr�s6		0|csXeZdZeZdddejddddd�fdd�Z�fdd�Z�S)�HTTPSConnectionN�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)rsrrV�key_file�	cert_file�sslZ_create_default_https_contextZverify_modeZ	CERT_NONEr
r]Zload_cert_chain�_context�_check_hostname)
r1r�r�rrr�r�rr
Zwill_verify)rtrrrV�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)N�server_hostname)rsr�r�r�rZwrap_socketrSr
rrZmatch_hostnameZgetpeercert�	Exception�shutdownr��	SHUT_RDWRrq)r1r)rtrrr��s
		

zHTTPSConnection.connect)	r5r6r7�
HTTPS_PORTr�r�r
rVr�rr)rtrr�s	rc@seZdZdS)rN)r5r6r7rrrrrsc@seZdZdS)rN)r5r6r7rrrrrsc@seZdZdS)rN)r5r6r7rrrrrsc@seZdZdd�ZdS)rcCs|f|_||_dS)N)�argsrL)r1rLrrrrVszUnknownProtocol.__init__N)r5r6r7rVrrrrrsc@seZdZdS)rN)r5r6r7rrrrr"sc@seZdZdS)r	N)r5r6r7rrrrr	%sc@s7eZdZddd�Zdd�Zdd�ZdS)r
NcCs"|f|_||_||_dS)N)r�partial�expected)r1rrrrrrV)s	zIncompleteRead.__init__cCsE|jdk	rd|j}nd}d|jjt|j�|fS)Nz, %i more expectedrXz%s(%i bytes read%s))rrtr5r-r)r1�errr�__repr__-s
zIncompleteRead.__repr__cCs
t|�S)N)r[)r1rrr�__str__4szIncompleteRead.__str__)r5r6r7rVrrrrrrr
(sc@seZdZdS)rN)r5r6r7rrrrr7sc@seZdZdS)r
N)r5r6r7rrrrr
:sc@seZdZdS)rN)r5r6r7rrrrr=sc@seZdZdS)rN)r5r6r7rrrrr@sc@seZdZdd�ZdS)rcCs+|st|�}|f|_||_dS)N)r[rr3)r1r3rrrrVDszBadStatusLine.__init__N)r5r6r7rVrrrrrCsc@seZdZdd�ZdS)rcCstj|dt|f�dS)Nz&got more than %d bytes when reading %s)rrVr=)r1Z	line_typerrrrVKszLineTooLong.__init__N)r5r6r7rVrrrrrJsc@seZdZdd�ZdS)rcOs'tj|d�tj|||�dS)NrX)rrV�ConnectionResetError)r1�pos�kwrrrrVPszRemoteDisconnected.__init__N)r5r6r7rVrrrrrOs)?Zemail.parserrAZ
email.messager��ior��rer�r�Zurllib.parser�__all__r	rrKr�r�r��globals�updater��__members__r�rr�r=r>�compile�	fullmatchr�r�r�r�r�r(r�ZMessager)rE�BufferedIOBaserrr�ImportErrorrr0rrrrrrr	r
rr
rrrrrrrrrrr�<module>Gsv				����
0