AlkantarClanX12

Your IP : 3.145.39.176


Current Path : /proc/self/root/usr/lib64/python3.6/urllib/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.6/urllib/__pycache__/request.cpython-36.opt-2.pyc

3

��f~��)@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ddl)m*Z*m+Z+yddl,Z,Wne-k
�r"dZ.YnXdZ.ddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'g!Z/d(ej0dd)�Z1da2de
j3fddddd*�d+d�Z4d,d�Z5gZ6d}d-d$�Z7d.d%�Z8e	j9d/e	j:�Z;d0d1�Z<Gd2d�d�Z=Gd3d�d�Z>d4d �Z?Gd5d	�d	�Z@Gd6d�de@�ZAGd7d
�d
e@�ZBGd8d�de@�ZCd9d:�ZDGd;d
�d
e@�ZEGd<d�d�ZFGd=d�deF�ZGGd>d�deG�ZHGd?d�d�ZIGd@d�deIe@�ZJGdAd�deIe@�ZKejLZMGdBd�d�ZNGdCd�de@eN�ZOGdDd�de@eN�ZPGdEdF�dFe@�ZQGdGd�deQ�ZReSejTdH��r.GdIdJ�dJeQ�ZUe/jVdJ�GdKd�de@�ZWGdLd�de@�ZXdMdN�ZYdOdP�ZZGdQd�de@�Z[dRdS�Z\GdTd�de@�Z]GdUd�de]�Z^GdVd�de@�Z_dWZ`ejadXk�r�ddYlbmcZcmdZdndZd"�Zcd[d!�ZdiZeGd\d&�d&�ZfGd]d'�d'ef�Zgdahd^d_�Zidajd`da�Zkdaldbdc�Zmdanddde�ZoGdfdg�dg�Zpdhdi�Zqd~djdk�Zrdldm�Zsejtdnk�r�ddolumvZvmwZwdpdq�Zxdrds�Zydtdu�Zzdvd#�Z{n6ejadXk�r�dwdx�Z|dyd#�Z{dzd{�Z}d|du�ZzneqZ{erZzdS)�N)�URLError�	HTTPError�ContentTooShortError)�urlparse�urlsplit�urljoin�unwrap�quote�unquote�	splittype�	splithost�	splitport�	splituser�splitpasswd�	splitattr�
splitquery�
splitvalue�splittag�to_bytes�unquote_to_bytes�
urlunparse)�
addinfourl�addclosehookFT�Request�OpenerDirector�BaseHandler�HTTPDefaultErrorHandler�HTTPRedirectHandler�HTTPCookieProcessor�ProxyHandler�HTTPPasswordMgr�HTTPPasswordMgrWithDefaultRealm�HTTPPasswordMgrWithPriorAuth�AbstractBasicAuthHandler�HTTPBasicAuthHandler�ProxyBasicAuthHandler�AbstractDigestAuthHandler�HTTPDigestAuthHandler�ProxyDigestAuthHandler�HTTPHandler�FileHandler�
FTPHandler�CacheFTPHandler�DataHandler�UnknownHandler�HTTPErrorProcessor�urlopen�install_opener�build_opener�pathname2url�url2pathname�
getproxies�urlretrieve�
urlcleanup�	URLopener�FancyURLopenerz%d.%d�)�cafile�capath�	cadefault�contextc
Cs�|s|s|rfddl}|jdtd�|dk	r2td��ts>td��tjtjj||d�}t	|d�}t
|�}	n0|r~t	|d�}t
|�}	ntdkr�t
�a}	nt}	|	j|||�S)NrzJcafile, capath and cadefault are deprecated, use a custom context instead.r:zDYou can't pass both context and any of cafile, capath, and cadefaultzSSL support not available)r;r<)r>)
�warnings�warn�DeprecationWarning�
ValueError�	_have_ssl�sslZcreate_default_contextZPurposeZSERVER_AUTH�HTTPSHandlerr2�_opener�open)
�url�data�timeoutr;r<r=r>r?Z
https_handler�opener�rL�&/usr/lib64/python3.6/urllib/request.pyr0�s*<




cCs|adS)N)rF)rKrLrLrMr1�scCs4t|�\}}tjt||����}|j�}|dkrD|rDtjj|�|fS|rTt|d�}nt	j
dd�}|j}tj
|�|��||f}	d}
d
}d}d}
d	|kr�t|d
�}|r�||
|
|�xB|j|
�}|s�P|t|�7}|j|�|
d7}
|r�||
|
|�q�WWdQRXWdQRX|dk�r0||k�r0td||f|	��|	S)N�file�wbF)�deletei��rzcontent-lengthzContent-Lengthz1retrieval incomplete: got only %i out of %i bytesi ���)r�
contextlib�closingr0�info�os�path�normpathrG�tempfileZNamedTemporaryFile�name�_url_tempfiles�append�int�read�len�writer)rH�filename�
reporthookrIZurl_typerX�fp�headers�tfp�result�bs�sizer_�blocknum�blockrLrLrMr6�sD


$cCsHx0tD](}ytj|�Wqtk
r,YqXqWtdd�=trDdadS)N)r\rW�unlink�OSErrorrF)Z	temp_filerLrLrMr7%s


z:\d+$cCs<|j}t|�d}|dkr&|jdd�}tjd|d�}|j�S)NrR��Host)�full_urlr�
get_header�_cut_port_re�sub�lower)�requestrH�hostrLrLrM�request_host4srwc@s�eZdZdidddfdd�Zedd��Zejdd��Zejdd��Zed	d
��Zejdd
��Zejdd
��Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd#dd�Zdd �Zd!d"�ZdS)$rNFc	Csp||_i|_i|_d|_||_d|_x |j�D]\}}|j||�q.W|dkrVt|�}||_	||_
|rl||_dS)N)rpre�unredirected_hdrs�_datarI�_tunnel_host�items�
add_headerrw�origin_req_host�unverifiable�method)	�selfrHrIrer}r~r�key�valuerLrLrM�__init__FszRequest.__init__cCs|jrdj|j|j�S|jS)Nz{}#{})�fragment�format�	_full_url)r�rLrLrMrpXszRequest.full_urlcCs(t|�|_t|j�\|_|_|j�dS)N)rr�rr��_parse)r�rHrLrLrMrp^s
cCsd|_d|_d|_dS)Nrn)r�r��selector)r�rLrLrMrpescCs|jS)N)ry)r�rLrLrMrIkszRequest.datacCs(||jkr$||_|jd�r$|jd�dS)NzContent-length)ry�
has_header�
remove_header)r�rIrLrLrMrIos

cCs
d|_dS)N)rI)r�rLrLrMrIyscCsNt|j�\|_}|jdkr(td|j��t|�\|_|_|jrJt|j�|_dS)Nzunknown url type: %r)	rr��typerBrprrvr�r
)r��restrLrLrMr�}s
zRequest._parsecCs|jdk	rdnd}t|d|�S)N�POST�GETr)rI�getattr)r�Zdefault_methodrLrLrM�
get_method�szRequest.get_methodcCs|jS)N)rp)r�rLrLrM�get_full_url�szRequest.get_full_urlcCs4|jdkr|jr|j|_n||_|j|_||_dS)N�https)r�rzrvrpr�)r�rvr�rLrLrM�	set_proxy�s

zRequest.set_proxycCs|j|jkS)N)r�rp)r�rLrLrM�	has_proxy�szRequest.has_proxycCs||j|j�<dS)N)re�
capitalize)r�r��valrLrLrMr|�szRequest.add_headercCs||j|j�<dS)N)rxr�)r�r�r�rLrLrM�add_unredirected_header�szRequest.add_unredirected_headercCs||jkp||jkS)N)rerx)r��header_namerLrLrMr��s
zRequest.has_headercCs|jj||jj||��S)N)re�getrx)r�r��defaultrLrLrMrq�szRequest.get_headercCs |jj|d�|jj|d�dS)N)re�poprx)r�r�rLrLrMr��szRequest.remove_headercCs"|jj�}|j|j�t|j��S)N)rx�copy�updatere�listr{)r��hdrsrLrLrM�header_items�s
zRequest.header_items)N)�__name__�
__module__�__qualname__r��propertyrp�setter�deleterrIr�r�r�r�r�r|r�r�rqr�r�rLrLrLrMrDs(

c@sNeZdZdd�Zdd�Zdd�Zdd�Zd	ejfd
d�Z	ddd
�Z
dd�Zd	S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NzPython-urllib/%sz
User-agent)�__version__�
addheaders�handlers�handle_open�handle_error�process_response�process_request)r�Zclient_versionrLrLrMr��szOpenerDirector.__init__cCsZt|d�stdt|���d}�xt|�D�]}|dkr:q*|jd�}|d|�}||dd�}|jd	�r�|jd�|d}||dd�}yt|�}Wntk
r�YnX|jj	|i�}	|	|j|<n>|d
kr�|}|j
}	n*|dkr�|}|j}	n|dkr*|}|j}	nq*|	j
|g�}
|
�r&tj|
|�n
|
j|�d
}q*W|�rVtj|j|�|j|�dS)N�
add_parentz%expected BaseHandler instance, got %rF�redirect_request�do_open�
proxy_open�_rR�errorrG�responseruT)r�r�r�)�hasattr�	TypeErrorr��dir�find�
startswithr^rBr�r�r�r�r��
setdefault�bisectZinsortr]r�r�)r��handlerZadded�meth�i�protocolZ	condition�j�kind�lookupr�rLrLrM�add_handler�sJ



zOpenerDirector.add_handlercCsdS)NrL)r�rLrLrM�close�szOpenerDirector.closec	Gs<|j|f�}x*|D]"}t||�}||�}|dk	r|SqWdS)N)r�r�)	r��chainr��	meth_name�argsr�r��funcrgrLrLrM�_call_chain�s

zOpenerDirector._call_chainNc
Cs�t|t�rt||�}n|}|dk	r(||_||_|j}|d}x(|jj|g�D]}t||�}||�}qLW|j	||�}	|d}x*|j
j|g�D]}t||�}|||	�}	q�W|	S)NZ_requestZ	_response)�
isinstance�strrrIrJr�r�r�r��_openr�)
r��fullurlrIrJ�reqr�r�Z	processorr�r�rLrLrMrG�s"


zOpenerDirector.opencCsP|j|jdd|�}|r|S|j}|j|j||d|�}|r>|S|j|jdd|�S)Nr�Zdefault_openr��unknown�unknown_open)r�r�r�)r�r�rIrgr�rLrLrMr�s


zOpenerDirector._opencGs~|d
kr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|�}|r^|S|rz|dd	f|}|j|�SdS)N�httpr�r:z
http_error_%srRZ_errorrr��http_error_default)r�r�)r�r�)r��protor��dictr�Zhttp_errZ	orig_argsrgrLrLrMr�'s 

zOpenerDirector.error)N)r�r�r�r�r�r�r��socket�_GLOBAL_DEFAULT_TIMEOUTrGr�r�rLrLrLrMr�s/
c	Gs�t�}ttttttttt	g	}t
tjd�r2|j
t�t�}xN|D]F}x@|D]8}t|t�rlt||�r�|j|�qHt||�rH|j|�qHWq>Wx|D]}|j|�q�Wx|D]}|j|��q�Wx&|D]}t|t�r�|�}|j|�q�W|S)N�HTTPSConnection)rrr.r)rrr+r*r/r-r�r��clientr]rE�setr�r��
issubclass�add�remover�)r�rKZdefault_classes�skip�klassZcheck�hrLrLrMr2@s0	









c@s(eZdZdZdd�Zdd�Zdd�ZdS)	ri�cCs
||_dS)N)�parent)r�r�rLrLrMr�gszBaseHandler.add_parentcCsdS)NrL)r�rLrLrMr�jszBaseHandler.closecCst|d�sdS|j|jkS)N�
handler_orderT)r�r�)r��otherrLrLrM�__lt__ns
zBaseHandler.__lt__N)r�r�r�r�r�r�r�rLrLrLrMrdsc@seZdZdZdd�ZeZdS)r/i�cCsJ|j|j|j�}}}d|ko*dknsF|jjd|||||�}|S)N��i,r�)�code�msgrVr�r�)r�rur�r�r�r�rLrLrM�
http_response{s
z HTTPErrorProcessor.http_responseN)r�r�r�r�r��https_responserLrLrLrMr/wsc@seZdZdd�ZdS)rcCst|j||||��dS)N)rrp)r�r�rdr�r�r�rLrLrMr��sz*HTTPDefaultErrorHandler.http_error_defaultN)r�r�r�r�rLrLrLrMr�sc@s4eZdZdZdZdd�Zdd�ZeZZZ	dZ
dS)	r��
c	sx|j�}|dkr|dkp&|dko&|dks:t|j||||��|jdd	�}d�t�fdd
�|jj�D��}t|||jdd�S)N�-�.�/�3r��HEADr�� z%20�content-length�content-typec3s&|]\}}|j��kr||fVqdS)N)rt)�.0�k�v)�CONTENT_HEADERSrLrM�	<genexpr>�sz7HTTPRedirectHandler.redirect_request.<locals>.<genexpr>T)rer}r~)r�r�r�r�)r�r�)r�r�r�)r�r�)	r�rrp�replacer�rer{rr})	r�r�rdr�r�re�newurl�mZ
newheadersrL)r�rMr��s
z$HTTPRedirectHandler.redirect_requestc
CsNd|kr|d}nd|kr$|d}ndSt|�}|jdkrRt||d||f||��|jrp|jrpt|�}d|d	<t|�}t|d
tj	d�}t
|j|�}|j||||||�}|dkr�dSt
|d��r|j}	|_|	j|d
�|jks�t|	�|jk�rt|j||j|||��ni}	|_|_|	j|d
�d|	|<|j�|j�|jj||jd�S)N�location�urir�r��ftprnz+%s - Redirection to url '%s' is not allowed�/r:z
iso-8859-1)�encoding�safe�
redirect_dictrrR)rJ)r�r�r�rn)r�schemerrXZnetlocr�rr	�stringZpunctuationrrpr�r�rr��max_repeatsr`�max_redirections�inf_msgr_r�r�rGrJ)
r�r�rdr�r�rer��urlparts�newZvisitedrLrLrM�http_error_302�s@



z"HTTPRedirectHandler.http_error_302zoThe HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
N)r�r�r�rrr�r	�http_error_301�http_error_303�http_error_307rrLrLrLrMr�s&<c	Cs�t|�\}}|jd�s d}|}n:|jd�s6td|��|jdd�}|dkrNd}|d|�}t|�\}}|dk	r|t|�\}}nd}}||||fS)Nr�z//zproxy URL with no authority: %rr:rRrS)rr�rBr�rr)	�proxyrZr_scheme�	authority�endZuserinfo�hostport�user�passwordrLrLrM�_parse_proxy�s

rc@s"eZdZdZddd�Zdd�ZdS)r�dNcCsL|dkrt�}||_x2|j�D]&\}}t|d||||jfdd��qWdS)Nz%s_opencSs||||�S)NrL)�rr
r�r�rLrLrM�<lambda>%sz'ProxyHandler.__init__.<locals>.<lambda>)r5�proxiesr{�setattrr�)r�rr�rHrLrLrMr�s
zProxyHandler.__init__cCs�|j}t|�\}}}}|dkr"|}|jr6t|j�r6dS|rv|rvdt|�t|�f}	tj|	j��jd�}
|j	dd|
�t|�}|j
||�||ks�|dkr�dS|jj||j
d�SdS)Nz%s:%s�asciizProxy-authorizationzBasic r�)rJ)r�rrv�proxy_bypassr
�base64�	b64encode�encode�decoder|r�r�rGrJ)r�r�r
r�Z	orig_typeZ
proxy_typerrrZ	user_passZcredsrLrLrMr�(s zProxyHandler.proxy_open)N)r�r�r�r�r�r�rLrLrLrMrs

c@s6eZdZdd�Zdd�Zdd�Zd
dd	�Zd
d�ZdS)r cCs
i|_dS)N)�passwd)r�rLrLrMr�FszHTTPPasswordMgr.__init__cs`t|t�r|g}|�jkr$i�j|<x6dD].�t��fdd�|D��}||f�j||<q*WdS)NTFcsg|]}�j|���qSrL)�
reduce_uri)r��u)�default_portr�rLrM�
<listcomp>Qsz0HTTPPasswordMgr.add_password.<locals>.<listcomp>)TF)r�r�r�tuple)r��realmr�rr�reduced_urirL)r"r�rM�add_passwordIs



zHTTPPasswordMgr.add_passwordc	Cs`|jj|i�}xLdD]D}|j||�}x2|j�D]&\}}x|D]}|j||�r<|Sq<Wq.WqWdS)NTF)TF)NN)rr�r r{�	is_suburi)	r�r%�authuriZdomainsr"�reduced_authuriZurisZauthinfor�rLrLrM�find_user_passwordTs

z"HTTPPasswordMgr.find_user_passwordTc
Cs�t|�}|dr.|d}|d}|dp*d}nd}|}d}t|�\}}|r~|dkr~|dk	r~ddd�j|�}	|	dk	r~d||	f}||fS)	NrRrr:r��Pi�)r�r�z%s:%d)rr
r�)
r�r�r"�partsrrrXrv�portZdportrLrLrMr ^s zHTTPPasswordMgr.reduce_uricCsR||krdS|d|dkr dStj|d|df�}t|�t|d�krNdSdS)NTrFrR)�	posixpath�commonprefixr`)r��base�test�commonrLrLrMr(uszHTTPPasswordMgr.is_suburiN)T)r�r�r�r�r'r+r r(rLrLrLrMr Ds


c@seZdZdd�ZdS)r!cCs0tj|||�\}}|dk	r"||fStj|d|�S)N)r r+)r�r%r)rrrLrLrMr+�s

z2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)r�r�r�r+rLrLrLrMr!�scs<eZdZ�fdd�Zd
�fdd�	Zddd�Zdd	�Z�ZS)r"csi|_t�j||�dS)N)�
authenticated�superr�)r�r��kwargs)�	__class__rLrMr��sz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<|j||�|dk	r&t�jd|||�t�j||||�dS)N)�update_authenticatedr5r')r�r%r�rr�is_authenticated)r7rLrMr'�sz)HTTPPasswordMgrWithPriorAuth.add_passwordcCsFt|t�r|g}x0dD](}x"|D]}|j||�}||j|<q WqWdS)NTF)TF)r�r�r r4)r�r�r9r"r!r&rLrLrMr8�s


z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDx>dD]6}|j||�}x$|jD]}|j||�r|j|SqWqWdS)NTF)TF)r r4r()r�r)r"r*r�rLrLrMr9�s

z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)r�r�r�r�r'r8r9�
__classcell__rLrL)r7rMr"�s

c@sTeZdZejdej�Zddd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZeZ
eZdS)r#z1(?:^|,)[ 	]*([^ 	,]+)[ 	]+realm=(["']?)([^"']*)\2NcCs"|dkrt�}||_|jj|_dS)N)r rr')r�Zpassword_mgrrLrLrMr��sz!AbstractBasicAuthHandler.__init__ccstd}xFtjj|�D]6}|j�\}}}|d	kr:tjdtd�||fVd}qW|sp|rb|j�d}nd}|dfVdS)
NF�"�'zBasic Auth Realm was unquoted�Trrn)r;r<)r#�rx�finditer�groupsr?r@�UserWarning�split)r��headerZfound_challengeZmorr	r%rLrLrM�_parse_realm�s
z%AbstractBasicAuthHandler._parse_realmc	Cs~|j|�}|sdSd}xL|D]D}x>|j|�D]0\}}|j�dkrF|}q,|dk	r,|j|||�Sq,WqW|dk	rztd|f��dS)N�basiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allrDrt�retry_http_basic_authrB)	r��authreqrvr�reZunsupportedrCrr%rLrLrM�http_error_auth_reqed�s

z.AbstractBasicAuthHandler.http_error_auth_reqedcCs||jj||�\}}|dk	rtd||f}dtj|j��jd�}|j|jd�|krTdS|j|j|�|j	j
||jd�SdSdS)Nz%s:%szBasic r)rJ)rr+rrrrrq�auth_headerr�r�rGrJ)r�rvr�r%r�pw�raw�authrLrLrMrF�sz.AbstractBasicAuthHandler.retry_http_basic_authcCsxt|jd�s|jj|j�r"|S|jd�st|jjd|j�\}}dj||�j�}tj	|�j
�}|jddj|j���|S)Nr9�
Authorizationz{0}:{1}zBasic {})
r�rr9rpr�r+r�rrZstandard_b64encoderr��strip)r�r�rrZcredentialsZauth_strrLrLrM�http_requests
z%AbstractBasicAuthHandler.http_requestcCsLt|jd�rHd|jko dknr8|jj|jd�n|jj|jd�|S)Nr9r�i,TF)r�rr�r8rp)r�r�r�rLrLrMr�s
z&AbstractBasicAuthHandler.http_response)N)r�r�r��re�compile�Ir>r�rDrHrFrOr��
https_requestr�rLrLrLrMr#�s

c@seZdZdZdd�ZdS)r$rMcCs|j}|jd|||�}|S)Nzwww-authenticate)rprH)r�r�rdr�r�rerHr�rLrLrM�http_error_401 s
z#HTTPBasicAuthHandler.http_error_401N)r�r�r�rIrTrLrLrLrMr$sc@seZdZdZdd�ZdS)r%zProxy-authorizationcCs|j}|jd|||�}|S)Nzproxy-authenticate)rvrH)r�r�rdr�r�rerr�rLrLrM�http_error_407+s
z$ProxyBasicAuthHandler.http_error_407N)r�r�r�rIrUrLrLrLrMr%'sc@sNeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)r&NcCs4|dkrt�}||_|jj|_d|_d|_d|_dS)Nr)r rr'�retried�nonce_count�
last_nonce)r�rrLrLrMr�Es
z"AbstractDigestAuthHandler.__init__cCs
d|_dS)Nr)rV)r�rLrLrM�reset_retry_countNsz+AbstractDigestAuthHandler.reset_retry_countcCs||j|d�}|jdkr*t|jdd|d��n|jd7_|rx|j�d}|j�dkr`|j||�S|j�dkrxtd|��dS)	N�i�zdigest auth failedrRrZdigestrEzEAbstractDigestAuthHandler does not support the following scheme: '%s')r�rVrrprBrt�retry_http_digest_authrB)r�rIrvr�rerGrrLrLrMrHQs


z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|jdd�\}}ttdt|���}|j||�}|rvd|}|jj|jd�|krRdS|j|j|�|j	j
||jd�}|SdS)Nr�rRz	Digest %s)rJ)rB�parse_keqv_list�filter�parse_http_list�get_authorizationrer�rIr�r�rGrJ)r�r�rL�tokenZ	challenge�chalZauth_valZresprLrLrMr[esz0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|tj�f}|jd�td�}tj|�j�}|dd�S)Nz	%s:%s:%s:rrQ�)rW�timeZctimer�_randombytes�hashlib�sha1�	hexdigest)r��nonce�s�b�digrLrLrM�
get_cnonceqsz$AbstractDigestAuthHandler.get_cnoncecCs�y6|d}|d}|jd�}|jdd�}|jdd�}Wntk
rJdSX|j|�\}}	|dkrfdS|jj||j�\}
}|
dkr�dS|jdk	r�|j|j|�}nd}d|
||f}
d|j�|j	f}|d	k�r.||j
kr�|jd
7_nd
|_||_
d|j}|j|�}d||||||�f}|	||
�|�}n2|dk�rT|	||
�d|||�f�}nt
d
|��d|
|||j	|f}|�r�|d|7}|�r�|d|7}|d|7}|�r�|d||f7}|S)Nr%rh�qop�	algorithm�MD5�opaquez%s:%s:%sz%s:%srLrRz%08xz%s:%s:%s:%s:%szqop '%s' is not supported.z>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z
, opaque="%s"z
, digest="%s"z, algorithm="%s"z, qop=auth, nc=%s, cnonce="%s")r��KeyError�get_algorithm_implsrr+rprI�get_entity_digestr�r�rXrWrlr)r�r�rar%rhrmrnrp�H�KDrrJZentdigZA1ZA2ZncvalueZcnonceZnoncebitZrespdigr1rLrLrMr_|sV








z+AbstractDigestAuthHandler.get_authorizationcsD|dkrdd��n|dkr$dd��ntd|���fdd�}�|fS)NrocSstj|jd��j�S)Nr)reZmd5rrg)�xrLrLrMr�sz?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSstj|jd��j�S)Nr)rerfrrg)rvrLrLrMr�sz.Unsupported digest authentication algorithm %rcs�d||f�S)Nz%s:%srL)ri�d)rtrLrMr�s)rB)r�rnrurL)rtrMrr�s

z-AbstractDigestAuthHandler.get_algorithm_implscCsdS)NrL)r�rIrarLrLrMrs�sz+AbstractDigestAuthHandler.get_entity_digest)N)r�r�r�r�rYrHr[rlr_rrrsrLrLrLrMr&:s
	<
c@seZdZdZdZdd�ZdS)r'rMi�cCs*t|j�d}|jd|||�}|j�|S)NrRzwww-authenticate)rrprHrY)r�r�rdr�r�rerv�retryrLrLrMrT�s

z$HTTPDigestAuthHandler.http_error_401N)r�r�r�rIr�rTrLrLrLrMr'�sc@seZdZdZdZdd�ZdS)r(zProxy-Authorizationi�cCs"|j}|jd|||�}|j�|S)Nzproxy-authenticate)rvrHrY)r�r�rdr�r�rervrxrLrLrMrU�s

z%ProxyDigestAuthHandler.http_error_407N)r�r�r�rIr�rUrLrLrLrMr(�sc@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�AbstractHTTPHandlerrcCs
||_dS)N)�_debuglevel)r��
debuglevelrLrLrMr��szAbstractHTTPHandler.__init__cCs
||_dS)N)rz)r��levelrLrLrM�set_http_debuglevel�sz'AbstractHTTPHandler.set_http_debuglevelcCstjjj|j|j��S)N)r�r��HTTPConnection�_get_content_lengthrIr�)r�rurLrLrMr�sz'AbstractHTTPHandler._get_content_lengthcCs
|j}|std��|jdk	r�|j}t|t�r8d}t|��|jd�sN|jdd�|jd�r�|jd�r�|j|�}|dk	r�|jdt|��n|jdd�|}|j	�r�t
|j�\}}t|�\}}	|jd�s�|jd|�x2|j
jD]&\}
}|
j�}
|j|
�s�|j|
|�q�W|S)	Nz
no host givenz\POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.zContent-typez!application/x-www-form-urlencodedzContent-lengthzTransfer-encodingZchunkedro)rvrrIr�r�r�r�r�rr�rr�rr�r�r�)r�rurvrIr�Zcontent_lengthZsel_hostrZselZsel_pathr[r�rLrLrM�do_request_�s>





zAbstractHTTPHandler.do_request_c
s\|j}|std��||fd|ji|��}|j|j�t|j���jt�fdd�|jj	�D���d�d<tdd��j	�D���|j
r�i}d}|�kr��|||<�|=|j|j
|d	�y`y&|j|j
�|j|j�|jd
�d�Wn,tk
�r
}zt|��WYdd}~XnX|j�}	Wn|j��YnX|j�rF|jj�d|_|j�|	_|	j|	_|	S)Nz
no host givenrJc3s"|]\}}|�kr||fVqdS)NrL)r�r�r�)rerLrMr�)sz.AbstractHTTPHandler.do_open.<locals>.<genexpr>r��
Connectioncss|]\}}|j�|fVqdS)N)�title)r�r[r�rLrLrMr�6szProxy-Authorization)rezTransfer-encoding)Zencode_chunked)rvrrJZset_debuglevelrzr�rxr�rer{rzZ
set_tunnelrur�r�rIr�rm�getresponser�Zsockr�rH�reasonr�)
r�Z
http_classr�Zhttp_conn_argsrvr�Ztunnel_headersZproxy_auth_hdr�errrrL)rerMr�s@
"

zAbstractHTTPHandler.do_openN)r)r�r�r�r�r}rr�r�rLrLrLrMry�s

&ryc@seZdZdd�ZejZdS)r)cCs|jtjj|�S)N)r�r�r�r~)r�r�rLrLrM�	http_open`szHTTPHandler.http_openN)r�r�r�r�ryr�rOrLrLrLrMr)^sr�c@s$eZdZddd�Zdd�ZejZdS)rErNcCstj||�||_||_dS)N)ryr��_context�_check_hostname)r�r{r>�check_hostnamerLrLrMr�iszHTTPSHandler.__init__cCs|jtjj||j|jd�S)N)r>r�)r�r�r�r�r�r�)r�r�rLrLrM�
https_opennszHTTPSHandler.https_open)rNN)r�r�r�r�r�ryr�rSrLrLrLrMrEgs
rEc@s.eZdZddd�Zdd�Zdd�ZeZeZdS)	rNcCs$ddl}|dkr|jj�}||_dS)Nr)Zhttp.cookiejar�	cookiejarZ	CookieJar)r�r�r�rLrLrMr�ws
zHTTPCookieProcessor.__init__cCs|jj|�|S)N)r�Zadd_cookie_header)r�rurLrLrMrO}sz HTTPCookieProcessor.http_requestcCs|jj||�|S)N)r�Zextract_cookies)r�rur�rLrLrMr��sz!HTTPCookieProcessor.http_response)N)r�r�r�r�rOr�rSr�rLrLrLrMrvs

c@seZdZdd�ZdS)r.cCs|j}td|��dS)Nzunknown url type: %s)r�r)r�r�r�rLrLrMr��szUnknownHandler.unknown_openN)r�r�r�r�rLrLrLrMr.�scCsRi}xH|D]@}|jdd�\}}|ddkrB|ddkrB|dd�}|||<q
W|S)N�=rRrr;rSrS)rB)�lZparsedZeltr�r�rLrLrMr\�s
r\cCs�g}d}d}}xt|D]l}|r,||7}d}q|rV|dkr@d}qn|dkrLd}||7}q|dkrn|j|�d}q|dkrzd}||7}qW|r�|j|�dd�|D�S)	NrnF�\Tr;�,cSsg|]}|j��qSrL)rN)r��partrLrLrMr#�sz#parse_http_list.<locals>.<listcomp>)r])ri�resr��escaper	ZcurrLrLrMr^�s4	


r^c@s(eZdZdd�ZdZdd�Zdd�ZdS)r*cCs\|j}|dd�dkrN|dd�dkrN|jrN|jdkrN|j|j�krXtd��n
|j|�SdS)Nr:z//r=r��	localhostz-file:// scheme is supported only on localhost)r�rv�	get_namesr�open_local_file)r�r�rHrLrLrM�	file_open�s&

zFileHandler.file_openNcCs`tjdkrZy*ttjd�dtjtj��d�t_Wn$tjk
rXtjd�ft_YnXtjS)Nr�r:)r*�namesr$r��gethostbyname_ex�gethostname�gaierror�
gethostbyname)r�rLrLrMr��s
zFileHandler.get_namescCsddl}ddl}|j}|j}t|�}y�tj|�}|j}|jj	|j
dd�}	|j|�d}
|jd|
pbd||	f�}|r~t
|�\}}|s�|r�t|�|j�kr�|r�d||}
nd|}
tt|d�||
�SWn*tk
r�}zt|��WYdd}~XnXtd��dS)	NrT)�usegmtz6Content-type: %s
Content-length: %d
Last-modified: %s
z
text/plainzfile://�rbzfile not on local host)�email.utils�	mimetypesrvr�r4rW�stat�st_size�utils�
formatdate�st_mtime�
guess_type�message_from_stringr
�_safe_gethostbynamer�rrGrmr)r�r��emailr�rvrbZ	localfile�statsri�modified�mtyperer.Zorigurl�exprLrLrMr��s0
zFileHandler.open_local_file)r�r�r�r�r�r�r�rLrLrLrMr*�s
cCs&y
tj|�Stjk
r dSXdS)N)r�r�r�)rvrLrLrMr��s
r�c@seZdZdd�Zdd�ZdS)r+cCs.ddl}ddl}|j}|s"td��t|�\}}|dkr>|j}nt|�}t|�\}}|rdt|�\}}nd}t	|�}|pvd}|p~d}yt
j|�}Wn*tk
r�}zt|��WYdd}~XnXt
|j�\}	}
|	jd�}ttt	|��}|dd�|d}}|�r|d�r|dd�}y�|j||||||j�}
|�r8d�p:d}x:|
D]2}t|�\}}|j�dk�rB|dk�rB|j�}�qBW|
j||�\}}d}|j|j�d}|�r�|d
|7}|dk	�r�|dk�r�|d|7}tj|�}t|||j�S|jk
�r(}z$td|�}|jtj �d��WYdd}~XnXdS)Nrzftp error: no host givenrnr�rRrR�Dr��a�Ar�rwzContent-type: %s
zContent-length: %d
z
ftp error: %rr:rSrS)r�r�r�rRrwr�)!�ftplibr�rvrr
�FTP_PORTr^rrr
r�r�rmrr�rBr��map�connect_ftprJrrt�upper�retrfiler�rpr�r�r�
all_errors�with_traceback�sys�exc_info)r�r�r�r�rvr.rrr�rX�attrs�dirsrN�fwr��attrr�rd�retrlenrer�r��excrLrLrM�ftp_open�s\



zFTPHandler.ftp_openc	Cst||||||dd�S)NF)�
persistent)�
ftpwrapper)r�rrrvr.r�rJrLrLrMr�1szFTPHandler.connect_ftpN)r�r�r�r�r�rLrLrLrMr+�s5c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)r,cCs"i|_i|_d|_d|_d|_dS)Nr�<rb)�cacherJ�soonest�delay�	max_conns)r�rLrLrMr�8s
zCacheFTPHandler.__init__cCs
||_dS)N)r�)r��trLrLrM�
setTimeout?szCacheFTPHandler.setTimeoutcCs
||_dS)N)r�)r�r�rLrLrM�setMaxConnsBszCacheFTPHandler.setMaxConnscCsr|||dj|�|f}||jkr4tj�|j|j|<n,t||||||�|j|<tj�|j|j|<|j�|j|S)Nr�)�joinr�rcr�rJr��check_cache)r�rrrvr.r�rJr�rLrLrMr�Es

zCacheFTPHandler.connect_ftpcCs�tj�}|j|krTx@t|jj��D].\}}||kr"|j|j�|j|=|j|=q"Wtt|jj���|_t	|j�|j
kr�x6t|jj��D]$\}}||jkr�|j|=|j|=Pq�Wtt|jj���|_dS)N)rcr�r�rJr{r�r��min�valuesr`r�)r�r�r�r�rLrLrMr�Ps

zCacheFTPHandler.check_cachecCs4x|jj�D]}|j�qW|jj�|jj�dS)N)r�r�r��clearrJ)r��connrLrLrM�clear_cacheds
zCacheFTPHandler.clear_cacheN)	r�r�r�r�r�r�r�r�r�rLrLrLrMr,5sc@seZdZdd�ZdS)r-cCs~|j}|jdd�\}}|jdd�\}}t|�}|jd�rNtj|�}|dd�}|sVd}tjd|t|�f�}t	t
j|�||�S)	N�:rRr�z;base64�ztext/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
i����)rprBr�endswithr�decodebytesr�r�r`r�io�BytesIO)r�r�rHrrIZ	mediatypererLrLrM�	data_openks


zDataHandler.data_openN)r�r�r�r�rLrLrLrMr-jsr��nt)r4r3cCst|�S)N)r
)�pathnamerLrLrMr4�scCst|�S)N)r	)r�rLrLrMr3�sc@s�eZdZdZdeZd)dd�Zdd�Zdd�Zd	d
�Z	dd�Z
d*d
d�Zd+dd�Zd,dd�Z
d-dd�Zdd�Zd.dd�Zd/dd�Zdd�Zer�dd�Zd0dd �Zd!d"�Zd#d$�Zd%d&�Zd1d'd(�ZdS)2r8NzPython-urllib/%scKszdd|jji}tj|tdd�|dkr.t�}||_|jd�|_|jd�|_	d|j
fd
g|_g|_t
j|_d|_t|_dS)NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methods�classr=)�
stacklevel�key_file�	cert_filez
User-Agent�Accept�*/*)r�r�)r7r�r?r@rAr5rr�r�r��versionr��_URLopener__tempfilesrWrl�_URLopener__unlink�	tempcache�ftpcache)r�rZx509r�rLrLrMr��szURLopener.__init__cCs|j�dS)N)r�)r�rLrLrM�__del__�szURLopener.__del__cCs|j�dS)N)�cleanup)r�rLrLrMr��szURLopener.closecCsZ|jrFx2|jD](}y|j|�Wqtk
r4YqXqW|jdd�=|jrV|jj�dS)N)r�r�rmr�r�)r�rNrLrLrMr��s
zURLopener.cleanupcGs|jj|�dS)N)r�r])r�r�rLrLrM�	addheader�szURLopener.addheadercCsntt|��}t|dd�}|jrL||jkrL|j|\}}t|d�}t|||�St|�\}}|s`d}||jkr�|j|}t|�\}}	t|	�\}
}|
|f}nd}d|}||_	|j
dd�}t||�s�|dkr�|r�|j|||�S|j
||�Sy,|dk�rt||�|�St||�||�SWnVttfk
�r.�Yn<tk
�rh}
ztd	|
�jtj�d
��WYdd}
~
XnXdS)Nz%/:=&?~#+!$,;'@()*[]|)rr�rNZopen_�-r�r�zsocket errorr:)rrr	r�rGrrrrr�r�r��open_unknown_proxy�open_unknownr�rrrmr�r�r�)r�r�rIrbrerd�urltyperHr
�	proxyhostrvr�r[r�rLrLrMrG�s<




zURLopener.opencCst|�\}}tdd|��dS)Nz	url errorzunknown url type)rrm)r�r�rIr�rHrLrLrMr�szURLopener.open_unknowncCs t|�\}}tdd||��dS)Nz	url errorzinvalid proxy for %s)rrm)r�r
r�rIr�rHrLrLrMr�	szURLopener.open_unknown_proxyc Cs&tt|��}|jr&||jkr&|j|St|�\}}|dkr�|sH|dkr�y.|j|�}|j�}|j�tt|�d�|fSt	k
r�}	zWYdd}	~	XnX|j
||�}�zH|j�}
|r�t
|d�}n|ddl}t|�\}
}t|p�d�\}
}t|p�d�\}}
t
|�pd�\}}
tjj|�d}|j|�\}}|jj|�tj|d�}z�||
f}|jdk	�r^||j|<d}d}d}d}d|
k�r�t|
d	�}|�r�||||�xH|j|�}|�s�P|t|�7}|j|�|d7}|�r�||||��q�WWd|j�XWd|j�X|dk�r"||k�r"td
||f|��|S)
NrNrRrOrrnirQzcontent-lengthzContent-Lengthz1retrieval incomplete: got only %i out of %i bytesi rS)rrr�rr�rVr�r4rrmrGrZrrrWrX�splitextZmkstempr�r]�fdopenr^r_r`rar)r�rHrbrcrIr�Zurl1rdr�r�rerfrZZgarbagerX�suffix�fdrgrhrir_rjrkrLrLrM�retrievesl






zURLopener.retrievecCs(d}d}t|t�r<t|�\}}|r6t|�\}}t|�}|}nt|\}}t|�\}}t|�\}	}
|
}d}|	j�dkrvd}n:t|
�\}}
|r�t|�\}}|r�d|	||
f}t|�r�|}|s�tdd��|r�t|�}t	j
|j��jd�}nd}|�rt|�}t	j
|j��jd�}nd}||�}
i}|�r*d||d<|�r<d||d<|�rJ||d	<d
|d<x|j
D]\}}|||<�qZW|dk	�r�d|d
<|
jd|||�n|
jd||d�y|
j�}Wn"tjjk
�r�td��YnXd|jk�o�dkn�rt||jd||j�S|j||j|j|j|j|�SdS)Nr�z	%s://%s%sz
http errorz
no host givenrzBasic %szProxy-AuthorizationrMror�r�z!application/x-www-form-urlencodedzContent-Typer�r�)rez$http protocol error: bad status liner�i,zhttp:)r�r�rrr
rrtrrmrrrrr�rur�r�r�Z
BadStatusLinerZstatusrr��
http_errorrdr�)r�Zconnection_factoryrHrIZuser_passwdZproxy_passwdrvr�Zrealhostr�r�Z
proxy_authrLZ	http_connrerCr�r�rLrLrM�_open_generic_httpQsr



zURLopener._open_generic_httpcCs|jtjj||�S)N)r�r�r�r~)r�rHrIrLrLrM�	open_http�szURLopener.open_httpc
Csbd|}t||�rPt||�}|dkr6||||||�}	n|||||||�}	|	rP|	S|j|||||�S)Nz
http_error_%d)r�r�r�)
r�rHrd�errcode�errmsgrerIr[rrgrLrLrMr��s

zURLopener.http_errorcCs|j�t||||d��dS)N)r�r)r�rHrdr�r�rerLrLrMr��szURLopener.http_error_defaultcCstjj||j|jd�S)N)r�r�)r�r�r�r�r�)r�rvrLrLrM�_https_connection�szURLopener._https_connectioncCs|j|j||�S)N)r�r�)r�rHrIrLrLrM�
open_https�szURLopener.open_httpscCs^t|t�std��|dd�dkrP|dd�dkrP|dd�j�dkrPtd��n
|j|�SdS)	NzEfile error: proxy support for file protocol currently not implementedr:z//r=r��z
localhost/z-file:// scheme is supported only on localhost)r�r�rrtrBr�)r�rHrLrLrM�	open_file�s

4
zURLopener.open_filecCs\ddl}ddl}t|�\}}t|�}ytj|�}Wn0tk
rb}zt|j|j	��WYdd}~XnX|j
}	|jj|j
dd�}
|j|�d}|jd|p�d|	|
f�}|s�|}
|dd�dkr�d|}
tt|d	�||
�St|�\}}|o�tj|�t�ft�k�rP|}
|dd�dk�r d|}
n|dd
�dk�r>td|��tt|d	�||
�Std
��dS)NrT)r�z6Content-Type: %s
Content-Length: %d
Last-modified: %s
z
text/plainrRr�zfile://r�r:z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)r�r�rr4rWr�rmr�strerrorrbr�r�r�r�r�r�rrGr
r�r�r��thishostrB)r�rHr�r�rvrNZ	localnamer��erir�r�reZurlfiler.rLrLrMr��s: 
zURLopener.open_local_filecCs�t|t�std��ddl}t|�\}}|s2td��t|�\}}t|�\}}|r\t|�\}}nd}t|�}t|ppd�}t|p|d�}t	j
|�}|s�ddl}|j}nt
|�}t|�\}}	t|�}|jd�}
|
dd�|
d}
}|
o�|
d�r�|
dd�}
|
�r|
d�rd|
d<|||dj|
�f}t|j�tk�rlx8t|j�D]*}
|
|k�r>|j|
}|j|
=|j��q>Wy�||jk�r�t|||||
�|j|<|�s�d}nd}x:|	D]2}t|�\}}|j�d	k�r�|dk�r�|j�}�q�W|j|j||�\}}|jd|�d}d}|�r|d|7}|dk	�r:|dk�r:|d|7}tj|�}t||d|�St�k
�r�}z td|�j t!j"�d��WYdd}~XnXdS)NzCftp error: proxy support for ftp protocol currently not implementedrzftp error: no host givenrnr�rRr�rRr�r�r�r�rwzftp:zContent-Type: %s
zContent-Length: %d
zftp error %rr:rSrS)r�r�r�rRrwr�)#r�r�rr�rr
rrr
r�r�r�r�r^rrBr�r`r��MAXFTPCACHEr�r�r�rrtr�r�r�r�r�r�	ftperrorsr�r�r�)r�rHr�rvrXr.rrr�r�r�rNr�r�r�r�r�r�rdr�r�rer�rLrLrM�open_ftp�sp







zURLopener.open_ftpc	Cs<t|t�std��y|jdd�\}}Wntk
rDtdd��YnX|sNd}|jd�}|dkr�d	||d�kr�||dd�}|d|�}nd
}g}|jdtj	dtj
tj����|jd
|�|dkr�tj|j
d��jd�}nt|�}|jdt|��|jd
�|j|�dj|�}tj|�}tj|�}t|||�S)NzEdata error: proxy support for data protocol currently not implementedr�rRz
data errorzbad data URLztext/plain;charset=US-ASCII�;rr�rnzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srrzlatin-1zContent-Length: %d�
)r�r�rrBrBrm�rfindr]rcZstrftimeZgmtimerr�rrr
r`r�r�r�r��StringIOr)	r�rHrIr�Zsemir�r�re�frLrLrM�	open_data3s6






zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)r�r�r�r�r�r�r�r�r�r�r�rGr�r�r�r�r�r�r�rCr�r�r�r�rrrLrLrLrMr8�s,

$


B\


	 :c@s�eZdZdd�Zdd�Zd"dd�Zdd	�Zd#d
d�Zd$dd
�Zd%dd�Z	d&dd�Z
d'dd�Zd(dd�Zd)dd�Z
d*dd�Zd+dd�Zd,dd�Zd d!�ZdS)-r9cOs(tj|f|�|�i|_d|_d|_dS)Nrr�)r8r��
auth_cache�tries�maxtries)r�r�r6rLrLrMr�`szFancyURLopener.__init__cCst||d||�S)Nzhttp:)r)r�rHrdr�r�rerLrLrMr�fsz!FancyURLopener.http_error_defaultNc	
Csn|jd7_zR|jrJ|j|jkrJt|d�r4|j}n|j}|||dd|�S|j||||||�}|Sd|_XdS)NrR�http_error_500i�z)Internal Server Error: Redirect Recursionr)r	r
r�rr��redirect_internal)	r�rHrdr�r�rerIr�rgrLrLrMr	js
zFancyURLopener.http_error_302c	Csxd|kr|d}nd|kr$|d}ndS|j�t|jd||�}t|�}|jd	krnt|||d|||��|j|�S)
Nr�r�r�r�r�r�rnz( Redirection to url '%s' is not allowed.)r�r�r�rn)r�rr�rrrrG)	r�rHrdr�r�rerIr�rrLrLrMr|s


z FancyURLopener.redirect_internalcCs|j||||||�S)N)r	)r�rHrdr�r�rerIrLrLrMr
�szFancyURLopener.http_error_301cCs|j||||||�S)N)r	)r�rHrdr�r�rerIrLrLrMr�szFancyURLopener.http_error_303cCs2|dkr|j||||||�S|j|||||�SdS)N)r	r�)r�rHrdr�r�rerIrLrLrMr�szFancyURLopener.http_error_307Fc
Cs�d|krtj||||||�|d}tjd|�}	|	sHtj||||||�|	j�\}
}|
j�dkrttj||||||�|s�tj||||||�d|jd}|dkr�t||�||�St||�|||�SdS)Nzwww-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"rEZretry_�_basic_auth)r8r�rP�matchr@rtr�r�)
r�rHrdr�r�rerIrx�stuffrrr%r[rLrLrMrT�s&





zFancyURLopener.http_error_401c
Cs�d|krtj||||||�|d}tjd|�}	|	sHtj||||||�|	j�\}
}|
j�dkrttj||||||�|s�tj||||||�d|jd}|dkr�t||�||�St||�|||�SdS)Nzproxy-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"rEZretry_proxy_r
)r8r�rPrr@rtr�r�)
r�rHrdr�r�rerIrxrrrr%r[rLrLrMrU�s&





zFancyURLopener.http_error_407cCs�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	jd�d}|	|d�}	|j|	||�\}}
|pl|
srdSdt|dd�t|
dd�|	f}	d|	|
|jd<|dkr�|j|�S|j||�SdS)Nzhttp://r��@rRz%s:%s@%srn)r)rrrr��get_user_passwdr	rG)r�rHr%rIrvr�r�r
r�r��
proxyselectorr�rrrLrLrM�retry_proxy_http_basic_auth�s 

z*FancyURLopener.retry_proxy_http_basic_authcCs�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	jd�d}|	|d�}	|j|	||�\}}
|pl|
srdSdt|dd�t|
dd�|	f}	d|	|
|jd<|dkr�|j|�S|j||�SdS)Nzhttps://r�rrRz%s:%s@%srn)r)rrrr�rr	rG)r�rHr%rIrvr�r�r
r�r�rr�rrrLrLrM�retry_proxy_https_basic_auth�s 

z+FancyURLopener.retry_proxy_https_basic_authc
Cs�t|�\}}|jd�d}||d�}|j|||�\}}|p>|sDdSdt|dd�t|dd�|f}d||}	|dkr�|j|	�S|j|	|�SdS)NrrRz%s:%s@%srn)rzhttp://)rr�rr	rG)
r�rHr%rIrvr�r�rrr�rLrLrMrF�s
z$FancyURLopener.retry_http_basic_authc
Cs�t|�\}}|jd�d}||d�}|j|||�\}}|p>|sDdSdt|dd�t|dd�|f}d||}	|dkr�|j|	�S|j|	|�SdS)NrrRz%s:%s@%srn)rzhttps://)rr�rr	rG)
r�rHr%rIrvr�r�rrr�rLrLrM�retry_https_basic_auth	s
z%FancyURLopener.retry_https_basic_authrcCs`|d|j�}||jkr2|r(|j|=n
|j|S|j||�\}}|sJ|rX||f|j|<||fS)Nr)rtr�prompt_user_passwd)r�rvr%r�r�rrrLrLrMr	s


zFancyURLopener.get_user_passwdcCsTddl}y,td||f�}|jd|||f�}||fStk
rNt�dSXdS)NrzEnter username for %s at %s: z#Enter password for %s in %s at %s: )NN)�getpass�input�KeyboardInterrupt�print)r�rvr%rrrrLrLrMr$	sz!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)r�r�r�r�r�r	rr
rrrTrUrrrFrrrrLrLrLrMr9]s"










cCstdkrtjd�atS)Nr�)�
_localhostr�r�rLrLrLrMr�4	s
r�cCsPtdkrLyttjtj��d�aWn(tjk
rJttjd�d�aYnXtS)Nr:r�)�	_thishostr$r�r�r�r�rLrLrLrMr�<	sr�cCstdkrddl}|jatS)Nr)�
_ftperrorsr�r�)r�rLrLrMrG	srcCstdkrtjd�atS)Nrn)�
_noheadersr�r�rLrLrLrM�	noheadersP	s
rc@sFeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)r�NTc	CsX||_||_||_||_||_||_d|_||_y|j�Wn|j	��YnXdS)Nr)
rrrvr.r�rJ�refcount�	keepalive�initr�)r�rrrvr.r�rJr�rLrLrMr�]	szftpwrapper.__init__cCs\ddl}d|_|j�|_|jj|j|j|j�|jj|j	|j
�dj|j�}|jj
|�dS)Nrr�)r��busyZFTPr�Zconnectrvr.rJZloginrrr�r��cwd)r�r�Z_targetrLrLrMr"m	s
zftpwrapper.initc-Cs�ddl}|j�|dkr"d}d}nd|}d}y|jj|�Wn*|jk
rh|j�|jj|�YnXd}|r�|r�yd|}|jj|�\}}WnR|jk
r�}z4t|�dd�d	kr�t	d
|�j
tj�d��WYdd}~XnX|�s�|jjd�|�rn|jj
�}	zJy|jj|�Wn4|jk
�rP}zt	d
|�|�WYdd}~XnXWd|jj|	�Xd|}nd
}|jj|�\}}d|_t|jd�|j�}
|jd7_|j�|
|fS)Nrrwr�zTYPE ArRzTYPE zRETR r=Z550z
ftp error: %rr:zLIST ZLISTr�)rwr�)r��endtransferr�Zvoidcmdr�r"ZntransfercmdZ
error_permr�rr�r�r��pwdr$r#r�makefile�
file_closer r�)r�rNr�r��cmd�isdirr�r�r�r&ZftpobjrLrLrMr�v	sN
 
$
zftpwrapper.retrfilecCs
d|_dS)Nr)r#)r�rLrLrMr%�	szftpwrapper.endtransfercCsd|_|jdkr|j�dS)NFr)r!r �
real_close)r�rLrLrMr��	s
zftpwrapper.closecCs4|j�|jd8_|jdkr0|jr0|j�dS)NrRr)r%r r!r+)r�rLrLrMr(�	szftpwrapper.file_closecCs2|j�y|jj�Wnt�k
r,YnXdS)N)r%r�r�r)r�rLrLrMr+�	s
zftpwrapper.real_close)NT)
r�r�r�r�r"r�r%r�r(r+rLrLrLrMr�Z	s
	-r�cCs�i}xBtjj�D]4\}}|j�}|r|dd�dkr|||dd�<qWdtjkr^|jdd�xXtjj�D]J\}}|dd�dkrj|j�}|r�|||dd�<qj|j|dd	�d�qjW|S)
N��_proxyZREQUEST_METHODr�i����i����i����i����i����)rW�environr{rtr�)rr[r�rLrLrM�getproxies_environment�	s	
r/c
Cs�|dkrt�}y|d}Wntk
r.dSX|dkr<dSt|�\}}dd�|jd�D�}xP|D]H}|rb|jd�}tj|�}d	|}tj||tj�s�tj||tj�rbdSqbWdS)
N�nor�*rRcSsg|]}|j��qSrL)rN)r�r
rLrLrMr#�	sz,proxy_bypass_environment.<locals>.<listcomp>r��.z
(.+\.)?%s$)	r/rqr
rB�lstriprPr�rrR)rvrZno_proxy�hostonlyr.Z
no_proxy_listr[�patternrLrLrM�proxy_bypass_environment�	s&


r6c
Csddlm}t|�\}}dd�}d|kr4|dr4dSd}x�|jdf�D]�}|sPqFtjd	|�}|dk	�r|dkr�ytj|�}||�}Wntk
r�wFYnX||jd
��}	|jd�}
|
dkr�d|jd
�j	d�d
}
nt
|
d
d��}
d
|
}
||
?|	|
?k�rdSqF|||�rFdSqFWdS)Nr)�fnmatchcSsh|jd�}ttt|��}t|�dkr<|ddddgdd�}|dd>|dd>B|dd>B|d	BS)
Nr2r�r�rRrbr:rQr=)rBr�r�r^r`)ZipAddrr-rLrLrM�ip2num
s

z,_proxy_bypass_macosx_sysconf.<locals>.ip2numr2Zexclude_simpleT�
exceptionsz(\d+(?:\.\d+)*)(/\d+)?rRr:rQ� F)r7r
r�rPrr�r�rm�group�countr^)rv�proxy_settingsr7r4r.r9ZhostIPr�r�r1�maskrLrLrM�_proxy_bypass_macosx_sysconf�	s:



r@�darwin)�_get_proxy_settings�_get_proxiescCst�}t||�S)N)rBr@)rvr>rLrLrM�proxy_bypass_macosx_sysconf:
srDcCst�S)N)rCrLrLrLrM�getproxies_macosx_sysconf>
srEcCs t�}|rt||�St|�SdS)N)r/r6rD)rvrrLrLrMrH
s
rcCst�p
t�S)N)r/rErLrLrLrMr5U
scCsi}yddl}Wntk
r$|SXy�|j|jd�}|j|d�d}|r�t|j|d�d�}d|kr�x�|jd�D]4}|jdd�\}}tjd|�s�d	||f}|||<qrWn>|dd
�dkr�||d<n$d
||d<d||d<d||d<|j	�Wnt
ttfk
�rYnX|S)Nrz;Software\Microsoft\Windows\CurrentVersion\Internet Settings�ProxyEnableZProxyServerr�rrRz^([^/:]+)://z%s://%srZzhttp:r�z	http://%sz
https://%sr�zftp://%sr�)
�winreg�ImportError�OpenKey�HKEY_CURRENT_USER�QueryValueExr�rBrPrZClosermrBr�)rrG�internetSettings�proxyEnableZproxyServer�pr�ZaddressrLrLrM�getproxies_registryZ
s8

rOcCst�p
t�S)N)r/rOrLrLrLrMr5�
sc&Cs~yddl}Wntk
r dSXy6|j|jd�}|j|d�d}t|j|d�d�}Wntk
rldSX|sz|r~dSt|�\}}|g}y tj	|�}||kr�|j
|�Wntk
r�YnXy tj|�}||kr�|j
|�Wntk
�r�YnX|jd�}xp|D]h}	|	dk�r*d|k�r*dS|	j
dd	�}	|	j
d
d�}	|	j
dd�}	x$|D]}
tj|	|
tj��rTdS�qTW�qWdS)
Nrz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsrFZ
ProxyOverriderz<local>r2rRz\.r1z.*�?)rGrHrIrJrKr�rmr
r�r�r]ZgetfqdnrBr�rPrrR)rvrGrLrMZ
proxyOverrideZrawHostr.ZaddrZfqdnr2r�rLrLrM�proxy_bypass_registry�
sR







rQcCs t�}|rt||�St|�SdS)N)r/r6rQ)rvrrLrLrMr�
s
)NNN)N)~rr�r�reZhttp.clientr�r�rWr/rPr�rr�rc�collectionsrZrTr?Zurllib.errorrrrZurllib.parserrrrr	r
rrr
rrrrrrrrrZurllib.responserrrDrHrC�__all__�version_infor�rFr�r0r1r\r6r7rQ�ASCIIrrrwrrr2rr/rrrrr r!r"r#r$r%�urandomrdr&r'r(ryr)r�r�rEr]rr.r\r^r*r�r+r,r-r�r[Z
nturl2pathr4r3r�r8r9rr�rr�rrrrr�r/r6r@�platformZ_scproxyrBrCrDrErr5rOrQrLrLrLrM�<module>Ts�P
T
?n$q*@
ov

+3:5!AW

_
#<

-	2