Your IP : 3.138.114.198


Current Path : /opt/alt/python310/lib64/python3.10/urllib/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/urllib/__pycache__/request.cpython-310.opt-2.pyc

o

6��fn��@s�	ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZmZmZddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*zddl+Z+Wne,y�dZ-YnwdZ-gd�Z.dej/dd	�Z0da1de
j2fddddd
�dd�Z3d
d�Z4gZ5d�dd�Z6dd�Z7e	�8de	j9�Z:dd�Z;Gdd�d�Z<Gdd�d�Z=dd�Z>Gdd�d�Z?Gdd�de?�Z@Gd d!�d!e?�ZAGd"d#�d#e?�ZBd$d%�ZCGd&d'�d'e?�ZDGd(d)�d)�ZEGd*d+�d+eE�ZFGd,d-�d-eF�ZGGd.d/�d/�ZHGd0d1�d1eHe?�ZIGd2d3�d3eHe?�ZJejKZLGd4d5�d5�ZMGd6d7�d7e?eM�ZNGd8d9�d9e?eM�ZOGd:d;�d;e?�ZPGd<d=�d=eP�ZQeRejSd>��rsGd?d@�d@eP�ZTe.�Ud@�GdAdB�dBe?�ZVGdCdD�dDe?�ZWdEdF�ZXdGdH�ZYGdIdJ�dJe?�ZZdKdL�Z[GdMdN�dNe?�Z\GdOdP�dPe\�Z]GdQdR�dRe?�Z^dSZ_ej`dTk�r�ddUlambZbmcZcndVdW�ZbdXdY�ZciZdGdZd[�d[�ZeGd\d]�d]ee�Zfdagd^d_�Zhdaid`da�Zjdakdbdc�Zldamddde�ZnGdfdg�dg�Zodhdi�Zpd�djdk�Zqdldm�Zrdndo�Zsejtdpk�r)ddqlumvZvmwZwdrds�Zxdtdu�Zydvdw�Zzdxdy�Z{dSej`dTk�rAdzd{�Z|d|dy�Z{d}d~�Z}ddw�ZzdSepZ{eqZzdS)��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|r:ddl}|�dtd�|durtd��ts td��tjtjj||d�}|�	dg�t
|d�}t|�}	n|rFt
|d�}t|�}	ntdurPt�a}	nt}	|	�
|||�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<zhttp/1.1)r>)�warnings�warn�DeprecationWarning�
ValueError�	_have_ssl�sslZcreate_default_contextZPurposeZSERVER_AUTHZset_alpn_protocols�HTTPSHandlerr2�_opener�open)
�url�data�timeoutr;r<r=r>r?Z
https_handler�opener�rL�5/opt/alt/python310/lib64/python3.10/urllib/request.pyr0�s42��
�



r0cCs|adS�N)rF)rKrLrLrMr1�sr1c	Csd	t|�\}}t�t||����}|��}|dkr)|s)tj�|�|fWd�S|r1t|d�}nt	j
dd�}|j}t�
|�|�G||f}	d}
d}d}d}
d|vrXt|d	�}|r`||
|
|�	|�|
�}|sin|t|�7}|�|�|
d7}
|r�||
|
|�qaWd�n1s�wYWd�n1s�wY|dkr�||kr�td||f|	��|	S)
N�file�wbF)�delete� ���r�content-length�Content-LengthT��1retrieval incomplete: got only %i out of %i bytes)r�
contextlib�closingr0�info�os�path�normpathrG�tempfileZNamedTemporaryFile�name�_url_tempfiles�append�int�read�len�writer)rH�filename�
reporthookrIZurl_typer\�fp�headers�tfp�result�bs�sizerc�blocknum�blockrLrLrMr6�sX�	


����&��r6c	CsF	tD]}zt�|�WqtyYqwtdd�=tr!dadSdSrN)r`r[�unlink�OSErrorrF)Z	temp_filerLrLrMr7s�
�r7z:\d+$cCs>	|j}t|�d}|dkr|�dd�}t�d|d�}|��S)NrV��Host)�full_urlr�
get_header�_cut_port_re�sub�lower)�requestrH�hostrLrLrM�request_host-sr{c@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|_|��D]
\}}|�||�q|dur)t|�}||_	||_
|r6||_dSdSrN)rtri�unredirected_hdrs�_datarI�_tunnel_host�items�
add_headerr{�origin_req_host�unverifiable�method)	�selfrHrIrir�r�r��key�valuerLrLrM�__init__?s
�zRequest.__init__cCs|jrd�|j|j�S|jS)Nz{}#{})�fragment�format�	_full_url�r�rLrLrMrtQszRequest.full_urlcCs(t|�|_t|j�\|_|_|��dSrN)rr�rr��_parse�r�rHrLrLrMrtWs
cCsd|_d|_d|_dS�Nrr)r�r��selectorr�rLrLrMrt^s
cC�|jSrN)r}r�rLrLrMrIdszRequest.datacCs0||jkr||_|�d�r|�d�dSdSdS)N�Content-length)r}�
has_header�
remove_header)r�rIrLrLrMrIhs

�cCs
d|_dSrN)rIr�rLrLrMrIrs
cCsRt|j�\|_}|jdurtd|j��t|�\|_|_|jr't|j�|_dSdS)Nzunknown url type: %r)	rr��typerBrtrrzr�r
)r��restrLrLrMr�vs
�zRequest._parsecCs 	|jdurdnd}t|d|�S)N�POST�GETr�)rI�getattr)r�Zdefault_methodrLrLrM�
get_method~szRequest.get_methodcCr�rN)rtr�rLrLrM�get_full_url�szRequest.get_full_urlcCs2|jdkr
|js
|j|_n||_|j|_||_dS)N�https)r�r~rzrtr�)r�rzr�rLrLrM�	set_proxy�s


zRequest.set_proxycCs|j|jkSrN)r�rtr�rLrLrM�	has_proxy��zRequest.has_proxycC�||j|��<dSrN)ri�
capitalize�r�r��valrLrLrMr���zRequest.add_headercCr�rN)r|r�r�rLrLrM�add_unredirected_header�r�zRequest.add_unredirected_headercCs||jvp	||jvSrN)rir|�r��header_namerLrLrMr��s
�zRequest.has_headercCs|j�||j�||��SrN)ri�getr|)r�r��defaultrLrLrMru�s�zRequest.get_headercCs |j�|d�|j�|d�dSrN)ri�popr|r�rLrLrMr��szRequest.remove_headercCsi|j�|j�}t|���SrN)r|ri�listr)r��hdrsrLrLrM�header_items�szRequest.header_itemsrN)�__name__�
__module__�__qualname__r��propertyrt�setter�deleterrIr�r�r�r�r�r�r�r�rur�r�rLrLrLrMr=s8
�




	

rc@sNeZdZdd�Zdd�Zdd�Zdd�Zd	ejfd
d�Z	ddd
�Z
dd�Zd	S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)N�Python-urllib/%sz
User-agent)�__version__�
addheaders�handlers�handle_open�handle_error�process_response�process_request)r�Zclient_versionrLrLrMr��s
zOpenerDirector.__init__c	CsPt|d�s
tdt|���d}t|�D]�}|dvrq|�d�}|d|�}||dd�}|�d�r`|�d�|d}||dd�}zt|�}Wn	tyRYnw|j�	|i�}	|	|j|<n|dkrj|}|j
}	n|d	krt|}|j}	n|d
kr~|}|j}	nq|	�
|g�}
|
r�t�|
|�n|
�|�d}q|r�t�|j|�|�|�dSdS)N�
add_parentz%expected BaseHandler instance, got %rF)�redirect_request�do_open�
proxy_open�_rV�errorrG�responseryT)�hasattr�	TypeErrorr��dir�find�
startswithrbrBr�r�r�r�r��
setdefault�bisectZinsortrar�r�)r��handlerZadded�meth�i�protocolZ	condition�j�kind�lookupr�rLrLrM�add_handler�sP
�

�
�zOpenerDirector.add_handlercC�dSrNrLr�rLrLrM�close��zOpenerDirector.closec	Gs<|�|d�}|D]}t||�}||�}|dur|SqdS)NrL)r�r�)	r��chainr��	meth_name�argsr�r��funcrkrLrLrM�_call_chain�s
��zOpenerDirector._call_chainNc
Cs�t|t�rt||�}n	|}|dur||_||_|j}|d}|j�|g�D]}t||�}||�}q%t	�
d|j|j|j|�
��|�||�}	|d}|j�|g�D]}t||�}|||	�}	qP|	S)NZ_requestzurllib.RequestZ	_response)�
isinstance�strrrIrJr�r�r�r��sys�auditrtrir��_openr�)
r��fullurlrIrJ�reqr�r�Z	processorr�r�rLrLrMrG�s$



zOpenerDirector.opencCsP|�|jdd|�}|r
|S|j}|�|j||d|�}|r|S|�|jdd|�S)Nr�Zdefault_openr��unknown�unknown_open)r�r�r�)r�r�rIrkr�rLrLrMr�s 
���
�zOpenerDirector._opencGs~|dvr|jd}|d}d|}d}|}n	|j}|d}d}|||f|}|j|�}|r/|S|r=|dd	f|}|j|�SdS)
N��httpr�r�r:z
http_error_%srVZ_errorrr��http_error_default)r�r�)r��protor��dictr�Zhttp_errZ	orig_argsrkrLrLrMr� s"


�zOpenerDirector.errorrN)r�r�r�r�r�r�r��socket�_GLOBAL_DEFAULT_TIMEOUTrGr�r�rLrLrLrMr�s/
rc	Gs�	t�}ttttttttt	g	}t
tjd�r|�
t�t�}|D]!}|D]}t|t�r5t||�r4|�|�q#t||�r?|�|�q#q|D]}|�|�qC|D]}|�|��qM|D]}t|t�rb|�}|�|�qX|S)N�HTTPSConnection)rrr.r)rrr+r*r/r-r�r��clientrarE�setr�r��
issubclass�add�remover�)r�rKZdefault_classes�skip�klassZcheck�hrLrLrMr29s:�



�

��
r2c@s(eZdZdZdd�Zdd�Zdd�ZdS)	r��cC�
||_dSrN)�parent)r�r�rLrLrMr�`�
zBaseHandler.add_parentcCr�rNrLr�rLrLrMr�cr�zBaseHandler.closecCst|d�sdS|j|jkS)N�
handler_orderT)r�r�)r��otherrLrLrM�__lt__gs
zBaseHandler.__lt__N)r�r�r�r�r�r�r�rLrLrLrMr]s
rc@seZdZ	dZdd�ZeZdS)r/i�cCsH|j|j|��}}}d|krdks"n|j�d|||||�}|S)N���,r�)�code�msgrZr�r�)r�ryr�r�r�r�rLrLrM�
http_responsets�z HTTPErrorProcessor.http_responseN)r�r�r�r�r��https_responserLrLrLrMr/ps
r/c@�eZdZdd�ZdS)rcCst|j||||��rN)rrt)r�r�rhr�r�r�rLrLrMr��sz*HTTPDefaultErrorHandler.http_error_defaultN)r�r�r�r�rLrLrLrMr��rc@s4eZdZdZdZdd�Zdd�ZeZZZ	dZ
dS)	r��
c	sv	|��}|dvr
|dvs|dvr|dkst|j||||��|�dd�}d��fdd	�|j��D�}t|||jd
d�S)N)�-�.�/i3)r�ZHEAD)rrrr�� z%20)rTzcontent-typecs"i|]
\}}|���vr||�qSrL)rx��.0�k�v�ZCONTENT_HEADERSrLrM�
<dictcomp>�s�z8HTTPRedirectHandler.redirect_request.<locals>.<dictcomp>T)rir�r�)r�rrt�replacerirrr�)	r�r�rhr�r�ri�newurl�mZ
newheadersrLrrMr��s	�z$HTTPRedirectHandler.redirect_requestc
CsHd|vr	|d}nd|vr|d}ndSt|�}|jdvr)t||d||f||��|js7|jr7t|�}d|d<t|�}t|dtj	d�}t
|j|�}|�||||||�}|durYdSt
|d	�r�|j}	|_|	�|d
�|jkstt|	�|jkr�t|j||j|||��ni}	|_|_|	�|d
�d|	|<|��|��|jj||jd�S)
N�location�uri�r�r��ftprrz+%s - Redirection to url '%s' is not allowed�/r:z
iso-8859-1)�encoding�safe�
redirect_dictrrV�rJ)r�schemerr\Znetlocr�rr	�stringZpunctuationrrtr�r�rr��max_repeatsrd�max_redirections�inf_msgrcr�r�rGrJ)
r�r�rhr�r�rir�urlparts�newZvisitedrLrLrM�http_error_302�sH



��
��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&<rc
Cs�	t|�\}}|�d�sd}|}n-|�d�std|��d|vr,|�d�}|�d|�}n|�dd�}|dkr8d}|d|�}t|�\}}|durOt|�\}}	nd}}	|||	|fS)Nr�//zproxy URL with no authority: %r�@r:rS)rr�rBr�rr)
�proxyrZr_scheme�	authorityZhost_separator�endZuserinfo�hostport�user�passwordrLrLrM�_parse_proxy�s&


r,c@s"eZdZdZddd�Zdd�ZdS)r�dNcCsP|durt�}||_|��D]\}}|��}t|d||||jfdd��qdS)Nz%s_opencSs||||�SrNrL)�rr&r�r�rLrLrM�<lambda>#r�z'ProxyHandler.__init__.<locals>.<lambda>)r5�proxiesrrx�setattrr�)r�r0r�rHrLrLrMr�s
��zProxyHandler.__init__cCs�|j}t|�\}}}}|dur|}|jrt|j�rdS|r;|r;dt|�t|�f}	t�|	����d�}
|�	dd|
�t|�}|�
||�||ksM|dkrOdS|jj||j
d�S)N�%s:%s�ascii�Proxy-authorization�Basic r�r)r�r,rz�proxy_bypassr
�base64�	b64encode�encode�decoder�r�r�rGrJ)r�r�r&r�Z	orig_typeZ
proxy_typer*r+r)Z	user_passZcredsrLrLrMr�&s"�zProxyHandler.proxy_openrN)r�r�r�r�r�r�rLrLrLrMrs
rc@s6eZdZdd�Zdd�Zdd�Zd
dd	�Zd
d�ZdS)r cCs
i|_dSrN)�passwdr�rLrLrMr�Dr�zHTTPPasswordMgr.__init__cs\t|t�r|g}|�jvri�j|<dD]�t��fdd�|D��}||f�j||<qdS)N�TFc3s�|]	}��|��VqdSrN)�
reduce_uri)r�u��default_portr�rLrM�	<genexpr>Ns�
�z/HTTPPasswordMgr.add_password.<locals>.<genexpr>)r�r�r;�tuple)r��realmrr*r;�reduced_urirLr?rM�add_passwordGs


��zHTTPPasswordMgr.add_passwordc	Cs`|j�|i�}dD]$}|�||�}|��D]\}}|D]}|�||�r+|Sqqq	dS)Nr<�NN)r;r�r=r�	is_suburi)	r�rC�authuriZdomainsr@�reduced_authuriZurisZauthinforrLrLrM�find_user_passwordRs���z"HTTPPasswordMgr.find_user_passwordTc
Cs�	t|�}|dr|d}|d}|dpd}nd}|}d}t|�\}}|r@|dur@|dur@ddd��|�}	|	dur@d||	f}||fS)	NrVrr:r�Pi�r�z%s:%d)rr
r�)
r�rr@�partsrr'r\rz�portZdportrLrLrMr=\s&��zHTTPPasswordMgr.reduce_uricCsP	||krdS|d|dkrdS|d}|dd�dkr!|d7}|d�|�S)NTrFrVrSr)r�)r��base�test�prefixrLrLrMrGsszHTTPPasswordMgr.is_suburiN)T)r�r�r�r�rErJr=rGrLrLrLrMr Bs

r c@r�)r!cCs0t�|||�\}}|dur||fSt�|d|�SrN)r rJ)r�rCrHr*r+rLrLrMrJ�s�z2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)r�r�r�rJrLrLrLrMr!�sr!cs<eZdZ�fdd�Zd
�fdd�	Zd
dd�Zdd	�Z�ZS)r"csi|_t�j|i|��dSrN)�
authenticated�superr��r�r��kwargs��	__class__rLrMr��sz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<|�||�|durt��d|||�t��||||�dSrN)�update_authenticatedrRrE)r�rCrr*r;�is_authenticatedrUrLrMrE�sz)HTTPPasswordMgrWithPriorAuth.add_passwordcCs>t|t�r|g}dD]}|D]
}|�||�}||j|<qq
dS�Nr<)r�r�r=rQ)r�rrXr@r>rDrLrLrMrW�s
��z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDdD]}|�||�}|jD]}|�||�r|j|Sq
qdSrY)r=rQrG)r�rHr@rIrrLrLrMrX�s
���z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)r�r�r�r�rErWrX�
__classcell__rLrLrUrMr"�s


r"c@sTeZdZe�dej�Zddd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZeZ
eZdS)r#z1(?:^|,)[ 	]*([^ 	,]+)[ 	]+realm=(["']?)([^"']*)\2NcCs"|durt�}||_|jj|_dSrN)r r;rE)r�Zpassword_mgrrLrLrMr��sz!AbstractBasicAuthHandler.__init__ccsv�d}tj�|�D]}|��\}}}|dvrt�dtd�||fVd}q	|s9|r0|��d}nd}|dfVdSdS)NF)�"�'zBasic Auth Realm was unquoted�Trrr)r#�rx�finditer�groupsr?r@�UserWarning�split)r��headerZfound_challengeZmorr	rCrLrLrM�_parse_realm�s ��
�z%AbstractBasicAuthHandler._parse_realmc	Cs~|�|�}|s	dSd}|D]$}|�|�D]\}}|��dkr!|}q|dur0|�|||�Sqq
|dur=td|f��dS)N�basiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allrdrx�retry_http_basic_authrB)	r��authreqrzr�riZunsupportedrcrrCrLrLrM�http_error_auth_reqed�s$
����z.AbstractBasicAuthHandler.http_error_auth_reqedcCsx|j�||�\}}|dur:d||f}dt�|����d�}|�|jd�|kr*dS|�|j|�|j	j
||jd�SdS)Nr2r5r3r)r;rJr7r8r9r:ru�auth_headerr�r�rGrJ)r�rzr�rCr*�pw�raw�authrLrLrMrf�sz.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jd�r
|j�|j�s|S|�d�s8|j�d|j�\}}d�||���}t�	|��
�}|�dd�|����|S)NrX�
Authorizationz{0}:{1}zBasic {})
r�r;rXrtr�rJr�r9r7Zstandard_b64encoder:r��strip)r�r�r*r;ZcredentialsZauth_strrLrLrM�http_requests�
�z%AbstractBasicAuthHandler.http_requestcCsNt|jd�r%d|jkrdkrnn
|j�|jd�|S|j�|jd�|S)NrXr�r�TF)r�r;r�rWrt)r�r�r�rLrLrMr�
s�z&AbstractBasicAuthHandler.http_responserN)r�r�r��re�compile�Ir^r�rdrhrfror��
https_requestr�rLrLrLrMr#�s�

r#c@�eZdZdZdd�ZdS)r$rmcC�|j}|�d|||�}|S)N�www-authenticate)rtrh)r�r�rhr�r�rirHr�rLrLrM�http_error_401s
�z#HTTPBasicAuthHandler.http_error_401N)r�r�r�rirwrLrLrLrMr$�r$c@rt)r%r4cCru�N�proxy-authenticate)rzrh)r�r�rhr�r�rir'r�rLrLrM�http_error_407)s
�z$ProxyBasicAuthHandler.http_error_407N)r�r�r�rir{rLrLrLrMr%%rxr%c@sNeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)r&NcCs4|durt�}||_|jj|_d|_d|_d|_dS�Nr)r r;rE�retried�nonce_count�
last_nonce)r�r;rLrLrMr�Cs

z"AbstractDigestAuthHandler.__init__cC�
d|_dSr|)r}r�rLrLrM�reset_retry_countLr�z+AbstractDigestAuthHandler.reset_retry_countcCs~|�|d�}|jdkrt|jdd|d��|jd7_|r;|��d}|��dkr/|�||�S|��dkr=td|��dSdS)	N�i�zdigest auth failedrVrZdigestrezEAbstractDigestAuthHandler does not support the following scheme: '%s')r�r}rrtrbrx�retry_http_digest_authrB)r�rirzr�rirgrrLrLrMrhOs 

���z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|�dd�\}}ttdt|���}|�||�}|r;d|}|j�|jd�|kr)dS|�|j|�|j	j
||jd�}|SdS)NrrVz	Digest %sr)rb�parse_keqv_list�filter�parse_http_list�get_authorizationrir�rir�r�rGrJ)r�r�rl�tokenZ	challenge�chalZauth_valZresprLrLrMr�cs�z0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|t��f}|�d�td�}t�|���}|dd�S)Nz	%s:%s:%s:r3��)r~�time�ctimer9�_randombytes�hashlib�sha1�	hexdigest)r��nonce�s�b�digrLrLrM�
get_cnonceosz$AbstractDigestAuthHandler.get_cnoncecCs�z|d}|d}|�d�}|�dd�}|�dd�}Wn
ty%YdSw|�|�\}}	|dur3dS|j�||j�\}
}|
durCdS|jdurP|�|j|�}nd}d|
||f}
d|��|j	f}|durt|	||
�d|||�f�}n=d	|�
d
�vr�||jkr�|jd7_nd|_||_d|j}|�
|�}d
|||d	||�f}|	||
�|�}ntd|��d|
|||j	|f}|r�|d|7}|r�|d|7}|d|7}|r�|d||f7}|S)NrCr��qop�	algorithm�MD5�opaquez%s:%s:%sr2rl�,rVz%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_implsr;rJrtrI�get_entity_digestr�r�rbrr~r�r)r�r�r�rCr�r�r�r��H�KDr*rjZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitrNrLrLrMr�zs^
�
�



��z+AbstractDigestAuthHandler.get_authorizationcsD|dkr	dd��n|dkrdd��ntd|���fdd�}�|fS)Nr�cS�t�|�d����S�Nr3)r�Zmd5r9r���xrLrLrMr/��z?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSr�r�)r�r�r9r�r�rLrLrMr/�r�z.Unsupported digest authentication algorithm %rcs�d||f�S)Nr2rL)r��d�r�rLrMr/�s)rB)r�r�r�rLr�rMr��s

�z-AbstractDigestAuthHandler.get_algorithm_implscCr�rNrL)r�rIr�rLrLrMr��r�z+AbstractDigestAuthHandler.get_entity_digestrN)r�r�r�r�r�rhr�r�r�r�r�rLrLrLrMr&8s
	>
r&c@seZdZ	dZdZdd�ZdS)r'rm��cCs*t|j�d}|�d|||�}|��|S)NrVrv)rrtrhr��r�r�rhr�r�rirz�retryrLrLrMrw�s�z$HTTPDigestAuthHandler.http_error_401N)r�r�r�rir�rwrLrLrLrMr'�s
r'c@seZdZdZdZdd�ZdS)r(�Proxy-Authorizationr�cCs"|j}|�d|||�}|��|Sry)rzrhr�r�rLrLrMr{�s�z%ProxyDigestAuthHandler.http_error_407N)r�r�r�rir�r{rLrLrLrMr(�sr(c@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�AbstractHTTPHandlerrcCr�rN��_debuglevel)r��
debuglevelrLrLrMr��r�zAbstractHTTPHandler.__init__cCr�rNr�)r��levelrLrLrM�set_http_debuglevel�r�z'AbstractHTTPHandler.set_http_debuglevelcCstjj�|j|���SrN)r�r��HTTPConnection�_get_content_lengthrIr��r�ryrLrLrMr��s�z'AbstractHTTPHandler._get_content_lengthcCs|j}|s	td��|jdurI|j}t|t�rd}t|��|�d�s'|�dd�|�d�sI|�d�sI|�|�}|durC|�dt|��n|�dd�|}|�	�r\t
|j�\}}t|�\}}	|�d�sg|�d|�|j
jD]\}
}|
��}
|�|
�s~|�|
|�qk|S)	N�
no host givenz\POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.zContent-type�!application/x-www-form-urlencodedr��Transfer-encodingZchunkedrs)rzrrIr�r�r�r�r�r�r�rr�rr�r�r�)r�ryrzrIr�Zcontent_lengthZsel_hostrZselZsel_pathr_r�rLrLrM�do_request_�sH


�
�
��

�zAbstractHTTPHandler.do_request_c

sB	|j}|s
td��||fd|ji|��}|�|j�t|j�����fdd�|j�	�D��d�d<dd���	�D��|j
rXi}d}|�vrP�|||<�|=|j|j
|d	�z*z|j|�
�|j|j�|�d
�d�Wnty|}zt|��d}~ww|��}	Wn|���|jr�|j��d|_|��|	_|	j|	_|	S)Nr�rJcsi|]\}}|�vr||�qSrLrLr�rirLrMr)s�z/AbstractHTTPHandler.do_open.<locals>.<dictcomp>r��
ConnectioncSsi|]	\}}|��|�qSrL)�title)rr_r�rLrLrMr6sr�r�r�)Zencode_chunked)rzrrJZset_debuglevelr�r�r|�updaterirr~Z
set_tunnelryr�r�rIr�rq�getresponser�Zsockr�rH�reasonr�)
r�Z
http_classr�Zhttp_conn_argsrzr�Ztunnel_headersZproxy_auth_hdr�errr.rLr�rMr�sH

���

zAbstractHTTPHandler.do_openN�r)r�r�r�r�r�r�r�r�rLrLrLrMr��s
&r�c@seZdZdd�ZejZdS)r)cCs|�tjj|�SrN)r�r�r�r��r�r�rLrLrM�	http_open`szHTTPHandler.http_openN)r�r�r�r�r�r�rorLrLrLrMr)^s
r)r�c@s$eZdZddd�Zdd�ZejZdS)rErNcCst�||�||_||_dSrN)r�r��_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�rLrLrM�
https_openns�zHTTPSHandler.https_open)rNN)r�r�r�r�r�r�r�rsrLrLrLrMrEgs

rEc@s.eZdZddd�Zdd�Zdd�ZeZeZdS)	rNcCs$ddl}|dur
|j��}||_dSr|)Zhttp.cookiejar�	cookiejarZ	CookieJar)r�r�r�rLrLrMr�ws

zHTTPCookieProcessor.__init__cCs|j�|�|SrN)r�Zadd_cookie_headerr�rLrLrMro}sz HTTPCookieProcessor.http_requestcCs|j�||�|SrN)r�Zextract_cookies)r�ryr�rLrLrMr��sz!HTTPCookieProcessor.http_responserN)r�r�r�r�ror�rsr�rLrLrLrMrvs
rc@r�)r.cCs|j}td|��)Nzunknown url type: %s)r�r)r�r�r�rLrLrMr��szUnknownHandler.unknown_openN)r�r�r�r�rLrLrLrMr.�rr.cCsP	i}|D] }|�dd�\}}|ddkr!|ddkr!|dd�}|||<q|S)N�=rVrr[rS)rb)�lZparsed�eltr	r
rLrLrMr��s
r�cCs�	g}d}d}}|D]5}|r||7}d}q|r*|dkrd}q|dkr%d}||7}q|dkr6|�|�d}q|dkr<d}||7}q|rH|�|�dd�|D�S)	NrrF�\Tr[r�cSsg|]}|���qSrL)rn)r�partrLrLrM�
<listcomp>�r�z#parse_http_list.<locals>.<listcomp>)ra)r��resr��escaper	ZcurrLrLrMr��s6


r�c@s(eZdZdd�ZdZdd�Zdd�ZdS)r*cCsZ|j}|dd�dkr(|dd�dkr(|jr(|jdkr(|j|��vr&td��dS|�|�S)Nr:r$r]r�	localhost�-file:// scheme is supported only on localhost)r�rz�	get_namesr�open_local_file)r�r�rHrLrLrM�	file_open�s&
�
zFileHandler.file_openNcCsftjdur0ztt�d�dt�t���d�t_WtjStjy/t�d�ft_YtjSwtjS)Nr�r:)r*�namesrBr��gethostbyname_ex�gethostname�gaierror�
gethostbynamer�rLrLrMr��s
����zFileHandler.get_namesc
Cs�ddl}ddl}|j}|j}t|�}zYt�|�}|j}|jj	|j
dd�}	|�|�d}
|�d|
p1d||	f�}|r?t
|�\}}|rK|sbt|�|��vrg|rTd||}
nd|}
tt|d�||
�WSWtd��Wtd��ty{}zt|��d}~ww)	NrT�Zusegmtz6Content-type: %s
Content-length: %d
Last-modified: %s
�
text/plain�file://�rbzfile not on local host)�email.utils�	mimetypesrzr�r4r[�stat�st_size�utils�
formatdate�st_mtime�
guess_type�message_from_stringr
�_safe_gethostbynamer�rrGrqr)r�r��emailr�rzrfZ	localfile�statsrm�modified�mtyperirMZorigurl�exprLrLrMr��sB
����	����zFileHandler.open_local_file)r�r�r�r�r�r�r�rLrLrLrMr*�s

r*cCs$zt�|�WStjyYdSwrN)r�r�r�)rzrLrLrMr��s
�r�c@seZdZdd�Zdd�ZdS)r+c
Cs�ddl}ddl}|j}|std��t|�\}}|dur|j}nt|�}t|�\}}|r2t|�\}}nd}t	|�}|p;d}|p?d}zt
�|�}WntyW}zt|��d}~wwt
|j�\}	}
|	�d�}ttt	|��}|dd�|d}}|r�|ds�|dd�}z_|�||||||j�}
|r�dp�d}|
D]}t|�\}}|��d	kr�|d
vr�|��}q�|
�||�\}}d}|�|j�d}|r�|d|7}|dur�|dkr�|d|7}t�|�}t|||j�WS|jy�}zt|�|�d}~ww)
Nr�ftp error: no host givenrrrrSrVrr�Dr���a�Ar�rrr�r�zContent-type: %s
zContent-length: %d
)�ftplibr�rzrr
�FTP_PORTrbrrr
r�r�rqrr�rbr��map�connect_ftprJrrx�upper�retrfiler�rtr�r�r�
all_errors)r�r�r�r�rzrMr*r;r�r\�attrs�dirsrO�fwr��attrr�rh�retrlenrir�r�rLrLrM�ftp_open�sd��
�

��zFTPHandler.ftp_openc	Cst||||||dd�S)NF)�
persistent)�
ftpwrapper)r�r*r;rzrMr�rJrLrLrMr�0s�zFTPHandler.connect_ftpN)r�r�r�r�r�rLrLrLrMr+�s4r+c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)r,cCs"i|_i|_d|_d|_d|_dS)Nr�<r�)�cacherJ�soonest�delay�	max_connsr�rLrLrMr�7s

zCacheFTPHandler.__init__cCr�rN)r)r��trLrLrM�
setTimeout>r�zCacheFTPHandler.setTimeoutcCr�rN)r)r�rrLrLrM�setMaxConnsAr�zCacheFTPHandler.setMaxConnscCsr|||d�|�|f}||jvrt��|j|j|<nt||||||�|j|<t��|j|j|<|��|j|S)Nr)�joinrr�rrJr�check_cache)r�r*r;rzrMr�rJr�rLrLrMr�Ds


�
zCacheFTPHandler.connect_ftpcCs�t��}|j|kr(t|j���D]\}}||kr'|j|��|j|=|j|=qtt|j����|_t	|j�|j
krat|j���D]\}}||jkrT|j|=|j|=nqAtt|j����|_dSdSrN)r�rr�rJrrr��min�valuesrdr)r�rr	r
rLrLrMr
Os$
�
��zCacheFTPHandler.check_cachecCs0|j��D]}|��q|j��|j��dSrN)rrr��clearrJ)r��connrLrLrM�clear_cachecs

zCacheFTPHandler.clear_cacheN)	r�r�r�r�rrr�r
rrLrLrLrMr,4sr,c@r�)r-cCs~|j}|�dd�\}}|�dd�\}}t|�}|�d�r't�|�}|dd�}|s+d}t�d|t|�f�}t	t
�|�||�S)N�:rVr�z;base64i�����text/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
)rtrbr�endswithr7�decodebytesr�r�rdr�io�BytesIO)r�r�rHrrIZ	mediatyperirLrLrM�	data_openjs



�zDataHandler.data_openN)r�r�r�rrLrLrLrMr-irr-r�nt)r4r3cC�
	t|�SrN)r
��pathnamerLrLrMr4��r4cCrrN)r	rrLrLrMr3�rr3c@s�eZdZ	dZdeZd)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�ZerQdd�Zd)dd �Zd!d"�Zd#d$�Zd%d&�Zd)d'd(�ZdS)+r8Nr�cKszdd|jji}tj|tdd�|durt�}||_|�d�|_|�d�|_	d|j
fdg|_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)ZAcceptz*/*)rVr�r?r@rAr5r0r�rr�versionr��_URLopener__tempfilesr[rp�_URLopener__unlink�	tempcache�ftpcache)r�r0Zx509r�rLrLrMr��s
�
zURLopener.__init__cC�|��dSrN)r�r�rLrLrM�__del__�r�zURLopener.__del__cCr%rN)�cleanupr�rLrLrMr��r�zURLopener.closec	CsV|jr|jD]}z|�|�WqtyYqw|jdd�=|jr)|j��dSdSrN)r!r"rqr#r
)r�rOrLrLrMr'�s
��zURLopener.cleanupcGs	|j�|�dSrN)r�ra)r�r�rLrLrM�	addheader�szURLopener.addheaderc
CsT	tt|��}t|dd�}|jr'||jvr'|j|\}}t|d�}t|||�St|�\}}|s1d}||jvrL|j|}t|�\}}	t|	�\}
}|
|f}nd}d|}||_	|�
dd�}t||�rd|dkrs|rm|�|||�S|�
||�Sz|dur�t||�|�WSt||�||�WSttfy��ty�}
ztd	|
��t��d
��d}
~
ww)Nz%/:=&?~#+!$,;'@()*[]|�rr�rOZopen_�-r�r�zsocket errorr:)rrr	r#rGrrr0rr�r
r��open_unknown_proxy�open_unknownr�rrrq�with_tracebackr��exc_info)r�r�rIrfrirh�urltyperHr&�	proxyhostrzr�r_r�rLrLrMrG�sB



��zURLopener.opencCs	t|�\}}tdd|��)N�	url errorzunknown url type�rrq)r�r�rIr�rHrLrLrMr,szURLopener.open_unknowncCs	t|�\}}tdd||��)Nr1zinvalid proxy for %sr2)r�r&r�rIr�rHrLrLrMr+szURLopener.open_unknown_proxycCs	tt|��}|jr||jvr|j|St|�\}}|durF|r$|dkrFz|�|�}|��}|��tt|�d�|fWSt	yEYnw|�
||�}z�|��}	|rYt
|d�}
n9t|�\}}t|pcd�\}}t|pkd�\}}t|psd�\}}t
j�|�d}
t�|
�\}}|j�|�t
�|d�}
zO||	f}|jdur�||j|<d}d}d}d}d|	vr�t|	d	�}|r�||||�	|�|�}|s�n|t|�7}|
�|�|d7}|r�||||�q�W|
��n|
��wW|��n|��w|dk�r||k�rtd
||f|��|S)NrOrVrPrrrRrSrrTrUrW)rrr#rr�rZr�r4rrqrGrrr[r\�splitextr^Zmkstempr!ra�fdopenrbrcrdrer)r�rHrfrgrIr�Zurl1rhr�rirjZgarbager\�suffix�fdrkrlrmrcrnrorLrLrM�retrievesx

�



���zURLopener.retrievecCs
	d}d}t|t�rt|�\}}|rt|�\}}t|�}|}n:|\}}t|�\}}t|�\}	}
|
}d}|	��dkr<d}nt|
�\}}
|rJt|�\}}|rSd|	||
f}t|�rY|}|s`tdd��|rqt|�}t	�
|����d�}nd}|r�t|�}t	�
|����d�}nd}||�}
i}|r�d||d<|r�d||d<|r�||d	<d
|d<|j
D]\}}|||<q�|dur�d|d
<|
�d|||�n|
jd||d�z|
��}Wn
tjjy�td��wd|jkr�dkr�nnt||jd||j�S|�||j|j|j|j|�S)Nr�z	%s://%s%sz
http errorr�r3zBasic %sr�rmrsr�r�r�zContent-Typer�r�r�z$http protocol error: bad status liner�r��http:)r�r�rrr
rrxr6rqr7r8r9r:r�ryr�r�r�Z
BadStatusLinerZstatusrr��
http_errorrhr�)r�Zconnection_factoryrHrIZuser_passwdZproxy_passwdrzr�Zrealhostr/r�Z
proxy_authrlZ	http_connrircr�r�rLrLrM�_open_generic_httpOsx

���zURLopener._open_generic_httpcCs	|�tjj||�SrN)r:r�r�r��r�rHrIrLrLrM�	open_http��zURLopener.open_httpc
Csd	d|}t||�r)t||�}|dur||||||�}	n	|||||||�}	|	r)|	S|�|||||�S)Nz
http_error_%d)r�r�r�)
r�rHrh�errcode�errmsgrirIr_r�rkrLrLrMr9�s

zURLopener.http_errorcCs	|��t||||d��rN)r�r�r�rHrhr>r?rirLrLrMr��szURLopener.http_error_defaultcCstjj||j|jd�S)N)rr)r�r�r�rr)r�rzrLrLrM�_https_connection�s�zURLopener._https_connectioncCs	|�|j||�SrN)r:rAr;rLrLrM�
open_https�szURLopener.open_httpscCsZ	t|t�s
td��|dd�dkr(|dd�dkr(|dd���dkr(td��|�|�S)	NzEfile error: proxy support for file protocol currently not implementedr:r$r]r�z
localhost/r�)r�r�rrxrBr�r�rLrLrM�	open_file�s
4
zURLopener.open_filec
CsH	ddl}ddl}t|�\}}t|�}zt�|�}Wnty-}zt|j|j	��d}~ww|j
}	|jj|j
dd�}
|�|�d}|�d|pGd|	|
f�}|sf|}
|dd�dkr]d|}
tt|d	�||
�St|�\}}|s�t�|�t�ft�vr�|}
|dd�dkr�d|}
n|dd
�dkr�td|��tt|d	�||
�Std
��)NrTr�z6Content-Type: %s
Content-Length: %d
Last-modified: %s
r�rVrr�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r4r[r�rqr�strerrorrfr�r�r�r�r�r�rrGr
r�r�r��thishostrB)r�rHr�r�rzrOZ	localnamer��ermr�r�riZurlfilerMrLrLrMr��sD����
zURLopener.open_local_filec
Csj	t|t�s
td��ddl}t|�\}}|std��t|�\}}t|�\}}|r/t|�\}}nd}t|�}t|p9d�}t|p?d�}t	�
|�}|sPddl}|j}nt
|�}t|�\}}	t|�}|�d�}
|
dd�|
d}
}|
rz|
dsz|
dd�}
|
r�|
ds�d|
d<|||d�|
�f}t|j�tkr�t|j�D]}
|
|kr�|j|
}|j|
=|��q�zl||jvr�t|||||
�|j|<|s�d}nd	}|	D]}t|�\}}|��d
kr�|dvr�|��}q�|j|�||�\}}|�d|�d}d}|r�|d
|7}|du�r|dk�r|d|7}t�|�}t||d|�WSt��y4}z
td|�� t!�"�d��d}~ww)NzCftp error: proxy support for ftp protocol currently not implementedrr�rrrrSrVr�rrr�r�zftp:zContent-Type: %s
zContent-Length: %d
zftp error %rr:)#r�r�rr�rr
rrr
r�r�r�r�rbrrbr	rdr$�MAXFTPCACHEr�r�rrrxr�r�r�r�r�r�	ftperrorsr-r�r.)r�rHr�rzr\rMr*r;r�r�r�rOr�r	r
r�r�r�rhr�r�rir�rLrLrM�open_ftp�sr



�
�
�
��zURLopener.open_ftpc	
Cs8	t|t�s
td��z
|�dd�\}}Wnty tdd��w|s%d}|�d�}|dkrEd	||d�vrE||dd�}|d|�}nd
}g}|�dt�	dt�
t�����|�d
|�|dkrpt�|�
d���d�}nt|�}|�dt|��|�d
�|�|�d�|�}t�|�}t�|�}t|||�S)NzEdata error: proxy support for data protocol currently not implementedr�rVz
data errorzbad data URLr�;rr�rrzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr7r3zlatin-1zContent-Length: %d�
)r�r�rrbrBrq�rfindrar��strftime�gmtimer7rr9r:r
rdr	r�r�r�StringIOr)	r�rHrIr�Zsemirr�ri�frLrLrM�	open_data1s<

�
�




zURLopener.open_datarN�NNN)r�r�r�r!r�r r�r&r�r'r(rGr,r+r7r:r<r9r�rCrArBrDr�rJrRrLrLrLrMr8�s0


$

A
\

	 :r8c@s�eZdZ	dd�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|g|�Ri|��i|_d|_d|_dS)Nrr)r8r��
auth_cache�tries�maxtriesrSrLrLrMr�^s
zFancyURLopener.__init__cCs	t||d||�S)Nr8)rr@rLrLrMr�dr=z!FancyURLopener.http_error_defaultNc	Cs|	|jd7_z1|jr*|j|jkr*t|d�r|j}n|j}|||dd|�Wd|_S|�||||||�}|Wd|_Sd|_w)NrV�http_error_500r�z)Internal Server Error: Redirect Recursionr)rUrVr�rWr��redirect_internal)	r�rHrhr>r?rirIr�rkrLrLrMr hs"
���zFancyURLopener.http_error_302c	Csxd|vr	|d}nd|vr|d}ndS|��t|jd||�}t|�}|jdvr7t|||d|||��|�|�S)Nrrrrz( Redirection to url '%s' is not allowed.)r�rr�rrrrG)	r�rHrhr>r?rirIrrrLrLrMrXzs 


��
z FancyURLopener.redirect_internalcC�	|�||||||�SrN�r �r�rHrhr>r?rirIrLrLrMr!��zFancyURLopener.http_error_301cCrYrNrZr[rLrLrMr"�r\zFancyURLopener.http_error_303cCs0	|dur|�||||||�S|�|||||�SrN)r r�r[rLrLrMr#�szFancyURLopener.http_error_307Fc
C��	d|vrt�||||||�|d}t�d|�}	|	s%t�||||||�|	��\}
}|
��dkr;t�||||||�|sGt�||||||�d|jd}|durZt||�||�St||�|||�S)Nrv�![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"reZretry_�_basic_auth�r8r�rp�matchr`rxr�r��
r�rHrhr>r?rirIr�ZstuffrarrCr_rLrLrMrw��0
�
�
��zFancyURLopener.http_error_401c
Cr])Nrzr^reZretry_proxy_r_r`rbrLrLrMr{�rczFancyURLopener.http_error_407cC�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	�d�d}|	|d�}	|�|	||�\}}
|s9|
s9dSdt|dd�t|
dd�|	f}	d|	|
|jd<|durZ|�|�S|�||�S)N�http://r�r%rV�%s:%s@%srrr)�rr0rr��get_user_passwdr	rG�r�rHrCrIrzr�rr&r/r0Z
proxyselectorr�r*r;rLrLrM�retry_proxy_http_basic_auth�� 
�
z*FancyURLopener.retry_proxy_http_basic_authcCrd)N�https://r�r%rVrfrrr)rgrirLrLrM�retry_proxy_https_basic_auth�rkz+FancyURLopener.retry_proxy_https_basic_authc
C�t|�\}}|�d�d}||d�}|�|||�\}}|s"|s"dSdt|dd�t|dd�|f}d||}	|dur@|�|	�S|�|	|�S)Nr%rVrfrrr)re�rr�rhr	rG�
r�rHrCrIrzr�r�r*r;rrLrLrMrf���
z$FancyURLopener.retry_http_basic_authc
Crn)Nr%rVrfrrr)rlrorprLrLrM�retry_https_basic_auth		rqz%FancyURLopener.retry_https_basic_authrcCs`|d|��}||jvr|r|j|=n|j|S|�||�\}}|s%|r,||f|j|<||fS)Nr%)rxrT�prompt_user_passwd)r�rzrCrr�r*r;rLrLrMrh	s


zFancyURLopener.get_user_passwdcCsT	ddl}ztd||f�}|�d|||f�}||fWSty)t�YdSw)NrzEnter username for %s at %s: z#Enter password for %s in %s at %s: rF)�getpass�input�KeyboardInterrupt�print)r�rzrCrtr*r;rLrLrMrs"	s�
�z!FancyURLopener.prompt_user_passwdrN)NFr�)r�r�r�r�r�r rXr!r"r#rwr{rjrmrfrrrhrsrLrLrLrMr9[s*




�
�




r9cC�	tdur
t�d�atS)Nr�)�
_localhostr�r�rLrLrLrMr�2	�
r�cCsT	tdur(ztt�t���d�aWtStjy'tt�d�d�aYtSwtS)Nr:r�)�	_thishostrBr�r�r�r�rLrLrLrMrF:	s��rFcCs	tdurddl}|jatSr|)�
_ftperrorsr�r�)r�rLrLrMrIE	s
rIcCrxr�)�
_noheadersr�r�rLrLrLrM�	noheadersN	rzr~c@sLeZdZ			ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)rNTcCsP||_||_||_||_||_||_d|_||_z|��WdS|�	��r|)
r*r;rzrMr�rJ�refcount�	keepalive�initr�)r�r*r;rzrMr�rJr�rLrLrMr�[	szftpwrapper.__init__cCs\ddl}d|_|��|_|j�|j|j|j�|j�|j	|j
�d�|j�}|j�
|�dS)Nrr)r��busyZFTPrZconnectrzrMrJZloginr*r;r	r��cwd)r�r�Z_targetrLrLrMr�k	s
zftpwrapper.initc
Cs�ddl}|��|dvrd}d}nd|}d}z|j�|�Wn|jy3|��|j�|�Ynwd}|rs|sszd|}|j�|�\}}Wn*|jyr}zt|�dd�dkrht	d	|��
t��d
��WYd}~nd}~ww|s�|j�d�|r�|j�
�}	z%z|j�|�Wn|jy�}zt	d	|�|�d}~wwW|j�|	�n|j�|	�wd|}nd}|j�|�\}}d|_t|�d
�|j�}
|jd7_|��|
|fS)Nr)r�r�zTYPE ArVzTYPE zRETR r]Z550z
ftp error: %rr:zLIST ZLISTr�)r��endtransferrZvoidcmdr�r�ZntransfercmdZ
error_permr�rr-r�r.�pwdr�r�rZmakefile�
file_closerr�)r�rOr�r��cmd�isdirrr�r�r�ZftpobjrLrLrMr�t	sX�
����
���
zftpwrapper.retrfilecCr�r|)r�r�rLrLrMr��	r�zftpwrapper.endtransfercCs d|_|jdkr|��dSdS)NFr)r�r�
real_closer�rLrLrMr��	s
�zftpwrapper.closecCs:|��|jd8_|jdkr|js|��dSdSdS)NrVr)r�rr�r�r�rLrLrMr��	s
�zftpwrapper.file_closecCs0|��z|j��WdSt�yYdSwrN)r�rr�rIr�rLrLrMr��	s�zftpwrapper.real_close)NT)
r�r�r�r�r�r�r�r�r�r�rLrLrLrMrX	s
�	-rcCs�	i}g}tj��D]3}t|�dkr=|ddkr=|dd���dkr=tj|}|dd���}|�|||f�|r=|||<q
dtjvrI|�dd�|D]\}}}|dd�dkre|r_|||<qK|�|d�qK|S)	Nr�i����r����r&ZREQUEST_METHODr��_proxy)r[�environ�keysrdrxrar�)r0Zenvironmentr_r�Z
proxy_namerLrLrM�getproxies_environment�	s(,
�

�r�cCs�	|durt�}z|d}Wn
tyYdSw|dkrdS|��}t|�\}}|�d�D]-}|��}|r[|�d�}|��}||ksG||krJdSd|}|�|�sX|�|�r[dSq.dS)NZnoF�*Tr��.)r�r�rxr
rbrn�lstripr)rzr0Zno_proxy�hostonlyrMr_rLrLrM�proxy_bypass_environment�	s0�
�r�c
Cs2	ddlm}ddlm}m}t|�\}}dd�}d|vr#|dr#dSd}zt||��}Wn	|y6Ynw|�d	d
�D]Y}	|	sBq=t�d|	�}
|
dur�|dur�||
�	d��}|
�	d
�}|durmd|
�	d��
d�d}nt|dd��}|dks}|dkr~q=d|}||?||?kr�dSq=|||	�r�dSq=dS)Nr��fnmatch)�AddressValueError�IPv4AddresscSsd|�d�}ttt|��}t|�dkr|gd�dd�}|dd>|dd>B|dd	>B|d
BS)Nr�r)rrrrr�rVr�r:r�r])rbr�r�rbrd)ZipAddrrLrLrLrM�ip2num
s

,z,_proxy_bypass_macosx_sysconf.<locals>.ip2numr�Zexclude_simpleT�
exceptionsrLz(\d+(?:\.\d+)*)(/\d+)?rVr:r�� F)r�Z	ipaddressr�r�r
rbr�rpra�group�count)
rz�proxy_settingsr�r�r�r�rMr�ZhostIPr�rrN�maskrLrLrM�_proxy_bypass_macosx_sysconf
sB�
�
�r�cCsb	ddlm}t|�\}}|�d�}|D]}|��}|dkr&d|vr%dSq|||�r.dSqdS)Nrr�rKz<local>r�TF)r�r
rbrn)rz�overrider�r�Zproxy_overriderOrLrLrM�_proxy_bypass_winreg_overrideA
s
�
�r��darwin)�_get_proxy_settings�_get_proxiescCst�}t||�SrN)r�r�)rzr�rLrLrM�proxy_bypass_macosx_sysconf\
s
r�cCs	t�SrN)r�rLrLrLrM�getproxies_macosx_sysconf`
sr�cC�	t�}|rt||�St|�SrN)r�r�r��rzr0rLrLrMr6j
�

r6cCst�pt�SrN)r�r�rLrLrLrMr5w
r�r5c
Cs:	i}zddl}Wnty|YSwzz|�|jd�}|�|d�d}|r�t|�|d�d�}d|vr>d|vr>d�|�}|�d�D]%}|�dd�\}}t�	d	|�sd|d
vr\d|}n|dkrdd
|}|||<qC|�
d�r�t�dd|d�}|�
d�p}||d<|�
d�p�||d<|��W|St
ttfy�Y|Sw)Nr�;Software\Microsoft\Windows\CurrentVersion\Internet Settings�ProxyEnableZProxyServerr�rKzhttp={0};https={0};ftp={0}rVz
(?:[^/:]+)://)r�r�rreZsockszsocks://z	^socks://z	socks4://r�r�)�winreg�ImportError�OpenKey�HKEY_CURRENT_USER�QueryValueExr�r�rbrprar�rwZCloserqrBr�)r0r��internetSettings�proxyEnableZproxyServer�pr�ZaddressrLrLrM�getproxies_registry|
sT������




��r�cCs	t�pt�SrN)r�r�rLrLrLrMr5�
scCs�zddl}Wn
tyYdSwz|�|jd�}|�|d�d}t|�|d�d�}Wn
ty6YdSw|r;|s=dSt||�S)NrFr�r�Z
ProxyOverride)r�r�r�r�r�r�rqr�)rzr�r�r�Z
proxyOverriderLrLrM�proxy_bypass_registry�
s2�����
��
r�cCr�rN)r�r�r�r�rLrLrMr6�
r�rSrN)~r7r�r�r�Zhttp.clientr�rr[�	posixpathrpr�rr�r�r^rXr?Zurllib.errorrrrZurllib.parserrrrr	r
rrr
rrrrrrrrrZurllib.responserrrDr�rC�__all__�version_infor�rFr�r0r1r`r6r7rq�ASCIIrvr{rrr2rr/rrr,rr r!r"r#r$r%�urandomr�r&r'r(r�r)r�r�rErarr.r�r�r*r�r+r,r-rHr_Z
nturl2pathr4r3r$r8r9ryr�r{rFr|rIr}r~rr�r�r�r��platformZ_scproxyr�r�r�r�r6r5r�r�rLrLrLrM�<module>s�SP��O
?m$q!+@
ov


+395!@W

_
%%@

1	

?>