ok

Mini Shell

Direktori : /proc/self/root/opt/alt/python37/lib64/python3.7/urllib/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python37/lib64/python3.7/urllib/__pycache__/request.cpython-37.opt-2.pyc

B

0��c��!@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*yddl+Z+Wne,k
�rdZ-YnXdZ-ddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'g!Z.d(ej/dd)�Z0da1de
j2fddddd*�d+d�Z3d,d�Z4gZ5d}d-d$�Z6d.d%�Z7e	�8d/e	j9�Z:d0d1�Z;Gd2d�d�Z<Gd3d�d�Z=d4d �Z>Gd5d	�d	�Z?Gd6d�de?�Z@Gd7d
�d
e?�ZAGd8d�de?�ZBd9d:�ZCGd;d
�d
e?�ZDGd<d�d�ZEGd=d�deE�ZFGd>d�deF�ZGGd?d�d�ZHGd@d�deHe?�ZIGdAd�deHe?�ZJejKZLGdBd�d�ZMGdCd�de?eM�ZNGdDd�de?eM�ZOGdEdF�dFe?�ZPGdGd�deP�ZQeRejSdH��r&GdIdJ�dJeP�ZTe.�UdJ�GdKd�de?�ZVGdLd�de?�ZWdMdN�ZXdOdP�ZYGdQd�de?�ZZdRdS�Z[GdTd�de?�Z\GdUd�de\�Z]GdVd�de?�Z^dWZ_ej`dXk�r�ddYlambZbmcZcndZd"�Zbd[d!�ZciZdGd\d&�d&�ZeGd]d'�d'ee�Zfdagd^d_�Zhdaid`da�Zjdakdbdc�Zldamddde�ZnGdfdg�dg�Zodhdi�Zpd~djdk�Zqdldm�Zrejsdnk�r�ddoltmuZumvZvdpdq�Zwdrds�Zxdtdu�Zydvd#�Zzn6ej`dXk�r�dwdx�Z{dyd#�Zzdzd{�Z|d|du�ZynepZzeqZydS)�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}|�dtd�|dk	r2td��ts>td��tjtjj||d�}t	|d�}t
|�}	n0|r~t	|d�}t
|�}	ntdkr�t
�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<)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�3/opt/alt/python37/lib64/python3.7/urllib/request.pyr0�s*<




cCs|adS)N)rF)rKrLrLrMr1�sc
Cs2t|�\}}t�t||����}|��}|dkrB|sBtj�|�|fS|rRt|d�}nt	j
dd�}|j}t�
|�|��||f}	d}
d}d}d}
d|kr�t|d	�}|r�||
|
|�xB|�|
�}|s�P|t|�7}|�|�|
d
7}
|r�||
|
|�q�WWdQRXWdQRX|dk�r.||k�r.td||f|	��|	S)N�file�wbF)�deletei ���rzcontent-lengthzContent-Length�z1retrieval 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_typerW�fp�headers�tfp�result�bs�sizer^�blocknum�blockrLrLrMr6�sD


$c	CsHx0tD](}yt�|�Wqtk
r,YqXqWtdd�=trDdadS)N)r[rV�unlink�OSErrorrF)Z	temp_filerLrLrMr7$s


z:\d+$cCs<|j}t|�d}|dkr&|�dd�}t�d|d�}|��S)NrR��Host)�full_urlr�
get_header�_cut_port_re�sub�lower)�requestrH�hostrLrLrM�request_host3srvc@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 |��D]\}}|�||�q.W|dkrVt|�}||_	||_
|rl||_dS)N)rord�unredirected_hdrs�_datarI�_tunnel_host�items�
add_headerrv�origin_req_host�unverifiable�method)	�selfrHrIrdr|r}r~�key�valuerLrLrM�__init__EszRequest.__init__cCs|jrd�|j|j�S|jS)Nz{}#{})�fragment�format�	_full_url)rrLrLrMroWszRequest.full_urlcCs(t|�|_t|j�\|_|_|��dS)N)rr�rr��_parse)rrHrLrLrMro]s
cCsd|_d|_d|_dS)Nrm)r�r��selector)rrLrLrMrodscCs|jS)N)rx)rrLrLrMrIjszRequest.datacCs(||jkr$||_|�d�r$|�d�dS)NzContent-length)rx�
has_header�
remove_header)rrIrLrLrMrIns

cCs
d|_dS)N)rI)rrLrLrMrIxscCsNt|j�\|_}|jdkr(td|j��t|�\|_|_|jrJt|j�|_dS)Nzunknown url type: %r)	rr��typerBrorrur�r
)r�restrLrLrMr�|s
zRequest._parsecCs|jdk	rdnd}t|d|�S)N�POST�GETr~)rI�getattr)rZdefault_methodrLrLrM�
get_method�szRequest.get_methodcCs|jS)N)ro)rrLrLrM�get_full_url�szRequest.get_full_urlcCs2|jdkr|js|j|_n||_|j|_||_dS)N�https)r�ryruror�)rrur�rLrLrM�	set_proxy�s

zRequest.set_proxycCs|j|jkS)N)r�ro)rrLrLrM�	has_proxy�szRequest.has_proxycCs||j|��<dS)N)rd�
capitalize)rr��valrLrLrMr{�szRequest.add_headercCs||j|��<dS)N)rwr�)rr�r�rLrLrM�add_unredirected_header�szRequest.add_unredirected_headercCs||jkp||jkS)N)rdrw)r�header_namerLrLrMr��s
zRequest.has_headercCs|j�||j�||��S)N)rd�getrw)rr��defaultrLrLrMrp�szRequest.get_headercCs |j�|d�|j�|d�dS)N)rd�poprw)rr�rLrLrMr��szRequest.remove_headercCs"|j��}|�|j�t|���S)N)rw�copy�updaterd�listrz)r�hdrsrLrLrM�header_items�s
zRequest.header_items)N)�__name__�
__module__�__qualname__r��propertyro�setter�deleterrIr�r�r�r�r�r{r�r�rpr�r�rLrLrLrMrCs(

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)rZclient_versionrLrLrMr��szOpenerDirector.__init__c	CsZt|d�stdt|���d}�xt|�D�]}|dkr:q*|�d�}|d|�}||dd�}|�d�r�|�d�|d}||dd�}yt|�}Wntk
r�YnX|j�	|i�}	|	|j|<n>|dkr�|}|j
}	n*|d	kr�|}|j}	n|d
kr*|}|j}	nq*|	�
|g�}
|
�r&t�|
|�n
|
�|�d}q*W|�rVt�|j|�|�|�dS)N�
add_parentz%expected BaseHandler instance, got %rF)�redirect_request�do_open�
proxy_open�_rR�errorrG�responsertT)�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)rrLrLrM�close�szOpenerDirector.closec	Gs<|�|d�}x*|D]"}t||�}||�}|dk	r|SqWdS)NrL)r�r�)	r�chainr��	meth_name�argsr�r��funcrfrLrLrM�_call_chain�s

zOpenerDirector._call_chainNc
Cs�t|t�rt||�}n|}|dk	r(||_||_|j}|d}x(|j�|g�D]}t||�}||�}qLW|�	||�}	|d}x*|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|�|jdd|�}|r|S|j}|�|j||d|�}|r>|S|�|jdd|�S)Nr�Zdefault_openr��unknown�unknown_open)r�r�r�)rr�rIrfr�rLrLrMr�s


zOpenerDirector._opencGs~|dkr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|�}|r^|S|rz|dd	f|}|j|�SdS)
N)�httpr�r�r:z
http_error_%srR�_errorrr��http_error_default)r�r�)r�protor��dictr�Zhttp_errZ	orig_argsrfrLrLrMr�&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|�
t�t�}xN|D]F}x@|D]8}t|t�rlt||�r�|�|�qHt||�rH|�|�qHWq>Wx|D]}|�|�q�Wx|D]}|�|��q�Wx&|D]}t|t�r�|�}|�|�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)rr�rLrLrMr�fszBaseHandler.add_parentcCsdS)NrL)rrLrLrMr�iszBaseHandler.closecCst|d�sdS|j|jkS)N�
handler_orderT)r�r�)r�otherrLrLrM�__lt__ms
zBaseHandler.__lt__N)r�r�r�r�r�r�r�rLrLrLrMrcsc@seZdZdZdd�ZeZdS)r/i�cCsH|j|j|��}}}d|kr,dksDn|j�d|||||�}|S)N��i,r�)�code�msgrUr�r�)rrtr�r�r�r�rLrLrM�
http_responsezs
z HTTPErrorProcessor.http_responseN)r�r�r�r�r��https_responserLrLrLrMr/vsc@seZdZdd�ZdS)rcCst|j||||��dS)N)rro)rr�rcr�r�r�rLrLrMr��sz*HTTPDefaultErrorHandler.http_error_defaultN)r�r�r�r�rLrLrLrMr�sc@s4eZdZdZdZdd�Zdd�ZeZZZ	dZ
dS)	r��
c	st|��}|dkr|dks:|dkr(|dks:t|j||||��|�dd�}d��fdd	�|j��D�}t|||jd
d�S)N)i-i.i/i3)r�ZHEAD)i-i.i/r�� z%20)zcontent-lengthzcontent-typecs"i|]\}}|���kr||�qSrL)rs)�.0�k�v)�CONTENT_HEADERSrLrM�
<dictcomp>�sz8HTTPRedirectHandler.redirect_request.<locals>.<dictcomp>T)rdr|r})r�rro�replacerdrzrr|)	rr�rcr�r�rd�newurl�mZ
newheadersrL)r�rMr��s
z$HTTPRedirectHandler.redirect_requestc
CsLd|kr|d}nd|kr$|d}ndSt|�}|jdkrRt||d||f||��|jsn|jrnt|�}d|d<t|�}t|dtj	d�}t
|j|�}|�||||||�}|dkr�dSt
|d	��r|j}	|_|	�|d
�|jks�t|	�|jk�rt|j||j|||��ni}	|_|_|	�|d
�d|	|<|��|��|jj||jd�S)
N�location�uri)r�r��ftprmz+%s - Redirection to url '%s' is not allowed�/r:z
iso-8859-1)�encoding�safe�
redirect_dictrrR)rJ)r�schemerrWZnetlocr�rr	�stringZpunctuationrror�r�r�r��max_repeatsr_�max_redirections�inf_msgr^r�r�rGrJ)
rr�rcr�r�rdr��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�r�r�r�r�http_error_301�http_error_303�http_error_307r�rLrLrLrMr�s&<c	Cs�t|�\}}|�d�s d}|}n:|�d�s6td|��|�dd�}|dkrNd}|d|�}t|�\}}|dk	r|t|�\}}nd}}||||fS)Nr�z//zproxy URL with no authority: %rr:rQ)rr�rBr�rr)	�proxyr�Zr_scheme�	authority�endZuserinfo�hostport�user�passwordrLrLrM�_parse_proxy�s

rc@s"eZdZdZddd�Zdd�ZdS)r�dNcCsL|dkrt�}||_x2|��D]&\}}t|d||||jfdd��qWdS)Nz%s_opencSs||||�S)NrL)�rrr�r�rLrLrM�<lambda>$sz'ProxyHandler.__init__.<locals>.<lambda>)r5�proxiesrz�setattrr�)rrr�rHrLrLrMr�s
zProxyHandler.__init__cCs�|j}t|�\}}}}|dkr"|}|jr6t|j�r6dS|rv|rvdt|�t|�f}	t�|	����d�}
|�	dd|
�t|�}|�
||�||ks�|dkr�dS|jj||j
d�SdS)Nz%s:%s�asciizProxy-authorizationzBasic r�)rJ)r�rru�proxy_bypassr
�base64�	b64encode�encode�decoder{r�r�rGrJ)rr�rr�Z	orig_typeZ
proxy_typer
rr	Z	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)rrLrLrMr�EszHTTPPasswordMgr.__init__cs`t|t�r|g}|�jkr$i�j|<x6dD].�t��fdd�|D��}||f�j||<q*WdS)N)TFc3s|]}��|��VqdS)N)�
reduce_uri)r��u)�default_portrrLrM�	<genexpr>Psz/HTTPPasswordMgr.add_password.<locals>.<genexpr>)r�r�r�tuple)r�realmr�r
r�reduced_urirL)rrrM�add_passwordHs



zHTTPPasswordMgr.add_passwordc	Cs`|j�|i�}xLdD]D}|�||�}x2|��D]&\}}x|D]}|�||�r<|Sq<Wq.WqWdS)N)TF)NN)rr�rrz�	is_suburi)	rr�authuriZdomainsr�reduced_authuriZurisZauthinfor�rLrLrM�find_user_passwordSs

z"HTTPPasswordMgr.find_user_passwordTc
Cs�t|�}|dr.|d}|d}|dp*d}nd}|}d}t|�\}}|r~|dkr~|dk	r~ddd��|�}	|	dk	r~d||	f}||fS)	NrRrr:r��Pi�)r�r�z%s:%d)rr
r�)
rr�r�partsr�rrWru�portZdportrLrLrMr]s zHTTPPasswordMgr.reduce_uricCsN||krdS|d|dkr dS|d}|dd�dkr@|d7}|d�|�S)NTrFrRrQr�)r�)r�base�test�prefixrLrLrMr!tszHTTPPasswordMgr.is_suburiN)T)r�r�r�r�r r$rr!rLrLrLrMr Cs


c@seZdZdd�ZdS)r!cCs0t�|||�\}}|dk	r"||fSt�|d|�S)N)r r$)rrr"r
rrLrLrMr$�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�)rr��kwargs)�	__class__rLrMr��sz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<|�||�|dk	r&t��d|||�t��||||�dS)N)�update_authenticatedr,r )rrr�r
r�is_authenticated)r.rLrMr �sz)HTTPPasswordMgrWithPriorAuth.add_passwordcCsFt|t�r|g}x0dD](}x"|D]}|�||�}||j|<q WqWdS)N)TF)r�r�rr+)rr�r0rrrrLrLrMr/�s


z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDx>dD]6}|�||�}x$|jD]}|�||�r|j|SqWqWdS)N)TF)rr+r!)rr"rr#r�rLrLrMr0�s

z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)r�r�r�r�r r/r0�
__classcell__rLrL)r.rMr"�s

c@sTeZdZe�dej�Zddd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�ZeZ
eZdS)r#z1(?:^|,)[ 	]*([^ 	,]+)[ 	]+realm=(["']?)([^"']*)\2NcCs"|dkrt�}||_|jj|_dS)N)r rr )rZpassword_mgrrLrLrMr��sz!AbstractBasicAuthHandler.__init__ccstd}xFtj�|�D]6}|��\}}}|dkr:t�dtd�||fVd}qW|sp|rb|��d}nd}|dfVdS)NF)�"�'zBasic Auth Realm was unquoted�Trrm)r#�rx�finditer�groupsr?r@�UserWarning�split)r�headerZfound_challenge�mor�r	rrLrLrM�_parse_realm�s
z%AbstractBasicAuthHandler._parse_realmc	Cs~|�|�}|sdSd}xL|D]D}x>|�|�D]0\}}|��dkrF|}q,|dk	r,|�|||�Sq,WqW|dk	rztd|f��dS)N�basiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allr<rs�retry_http_basic_authrB)	r�authreqrur�rdZunsupportedr:r�rrLrLrM�http_error_auth_reqed�s

z.AbstractBasicAuthHandler.http_error_auth_reqedcCs||j�||�\}}|dk	rtd||f}dt�|����d�}|�|jd�|krTdS|�|j|�|j	j
||jd�SdSdS)Nz%s:%szBasic r)rJ)rr$rrrrrp�auth_headerr�r�rGrJ)rrur�rr
�pw�raw�authrLrLrMr>�sz.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jd�r|j�|j�s|S|�d�sp|j�d|j�\}}d�||���}t�	|��
�}|�dd�|����|S)Nr0�
Authorizationz{0}:{1}zBasic {})
r�rr0ror�r$r�rrZstandard_b64encoderr��strip)rr�r
rZcredentialsZauth_strrLrLrM�http_requests
z%AbstractBasicAuthHandler.http_requestcCsLt|jd�rHd|jkr"dkr8nn|j�|jd�n|j�|jd�|S)Nr0r�i,TF)r�rr�r/ro)rr�r�rLrLrMr�s
z&AbstractBasicAuthHandler.http_response)N)r�r�r��re�compile�Ir5r�r<r@r>rGr��
https_requestr�rLrLrLrMr#�s

c@seZdZdZdd�ZdS)r$rEcCs|j}|�d|||�}|S)Nzwww-authenticate)ror@)rr�rcr�r�rdrHr�rLrLrM�http_error_401s
z#HTTPBasicAuthHandler.http_error_401N)r�r�r�rArLrLrLrLrMr$sc@seZdZdZdd�ZdS)r%zProxy-authorizationcCs|j}|�d|||�}|S)Nzproxy-authenticate)rur@)rr�rcr�r�rdrr�rLrLrM�http_error_407*s
z$ProxyBasicAuthHandler.http_error_407N)r�r�r�rArMrLrLrLrMr%&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)rrrLrLrMr�Ds
z"AbstractDigestAuthHandler.__init__cCs
d|_dS)Nr)rN)rrLrLrM�reset_retry_countMsz+AbstractDigestAuthHandler.reset_retry_countcCs||�|d�}|jdkr*t|jdd|d��n|jd7_|rx|��d}|��dkr`|�||�S|��dkrxtd|��dS)	N�i�zdigest auth failedrRrZdigestr=zEAbstractDigestAuthHandler does not support the following scheme: '%s')r�rNrror9rs�retry_http_digest_authrB)rrArur�rdr?r�rLrLrMr@Ps


z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|�dd�\}}ttdt|���}|�||�}|rvd|}|j�|jd�|krRdS|�|j|�|j	j
||jd�}|SdS)Nr�rRz	Digest %s)rJ)r9�parse_keqv_list�filter�parse_http_list�get_authorizationrdr�rAr�r�rGrJ)rr�rD�tokenZ	challenge�chalZauth_valZresprLrLrMrSdsz0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|t��f}|�d�td�}t�|���}|dd�S)Nz	%s:%s:%s:r��)rO�timeZctimer�_randombytes�hashlib�sha1�	hexdigest)r�nonce�s�b�digrLrLrM�
get_cnoncepsz$AbstractDigestAuthHandler.get_cnoncecCs�y6|d}|d}|�d�}|�dd�}|�dd�}Wntk
rJdSX|�|�\}}	|dkrfdS|j�||j�\}
}|
dkr�dS|jdk	r�|�|j|�}nd}d|
||f}
d|��|j	f}|dkr�|	||
�d|||�f�}n~d	|�
d
�k�rZ||jk�r|jd7_nd|_||_d|j}|�
|�}d
|||d	||�f}|	||
�|�}ntd|��d|
|||j	|f}|�r�|d|7}|�r�|d|7}|d|7}|�r�|d||f7}|S)Nrra�qop�	algorithm�MD5�opaquez%s:%s:%sz%s:%srD�,rRz%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$rorI�get_entity_digestr�r�r9rPrOrer)rr�rYrrarfrgri�H�KDr
rBZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitr(rLrLrMrW{sV





z+AbstractDigestAuthHandler.get_authorizationcsD|dkrdd��n|dkr$dd��ntd|���fdd�}�|fS)NrhcSst�|�d����S)Nr)r^Zmd5rr`)�xrLrLrMr��z?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSst�|�d����S)Nr)r^r_rr`)rprLrLrMr�rqz.Unsupported digest authentication algorithm %rcs�d||f�S)Nz%s:%srL)rb�d)rnrLrMr�rq)rB)rrgrorL)rnrMrl�s

z-AbstractDigestAuthHandler.get_algorithm_implscCsdS)NrL)rrIrYrLrLrMrm�sz+AbstractDigestAuthHandler.get_entity_digest)N)r�r�r�r�rQr@rSrerWrlrmrLrLrLrMr&9s
	>
c@seZdZdZdZdd�ZdS)r'rEi�cCs*t|j�d}|�d|||�}|��|S)NrRzwww-authenticate)rror@rQ)rr�rcr�r�rdru�retryrLrLrMrL�s

z$HTTPDigestAuthHandler.http_error_401N)r�r�r�rAr�rLrLrLrLrMr'�sc@seZdZdZdZdd�ZdS)r(zProxy-Authorizationi�cCs"|j}|�d|||�}|��|S)Nzproxy-authenticate)rur@rQ)rr�rcr�r�rdrursrLrLrMrM�s

z%ProxyDigestAuthHandler.http_error_407N)r�r�r�rAr�rMrLrLrLrMr(�sc@s6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�AbstractHTTPHandlerrcCs
||_dS)N)�_debuglevel)r�
debuglevelrLrLrMr��szAbstractHTTPHandler.__init__cCs
||_dS)N)ru)r�levelrLrLrM�set_http_debuglevel�sz'AbstractHTTPHandler.set_http_debuglevelcCstjj�|j|���S)N)r�r��HTTPConnection�_get_content_lengthrIr�)rrtrLrLrMrz�sz'AbstractHTTPHandler._get_content_lengthcCs|j}|std��|jdk	r�|j}t|t�r8d}t|��|�d�sN|�dd�|�d�s�|�d�s�|�|�}|dk	r�|�dt|��n|�dd�|}|�	�r�t
|j�\}}t|�\}}	|�d�s�|�d|�x2|j
jD]&\}
}|
��}
|�|
�s�|�|
|�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-encodingZchunkedrn)rurrIr�r�r�r�r�rzr�rr�rr�r�r�)rrtrurIr�Zcontent_lengthZsel_hostr�ZselZsel_pathrZr�rLrLrM�do_request_�s>







zAbstractHTTPHandler.do_request_c

sT|j}|std��||fd|ji|��}|�|j�t|j�����fdd�|j�	�D��d�d<dd���	�D��|j
r�i}d}|�kr��|||<�|=|j|j
|d	�y`y&|j|�
�|j|j�|�d
�d�Wn,tk
�r}zt|��Wdd}~XYnX|��}	Wn|���YnX|j�r>|j��d|_|��|	_|	j|	_|	S)Nz
no host givenrJcsi|]\}}|�kr||�qSrLrL)r�r�r�)rdrLrMr�*sz/AbstractHTTPHandler.do_open.<locals>.<dictcomp>r��
ConnectioncSsi|]\}}||���qSrL)�title)r�rZr�rLrLrMr�7szProxy-Authorization)rdzTransfer-encoding)Zencode_chunked)rurrJZset_debuglevelrur�rwr�rdrzryZ
set_tunnelrtr�r�rIr�rl�getresponser�Zsockr�rH�reasonr�)
rZ
http_classr�Zhttp_conn_argsrur�Ztunnel_headersZproxy_auth_hdr�errrrL)rdrMr�s@


zAbstractHTTPHandler.do_openN)r)r�r�r�r�rxrzr{r�rLrLrLrMrt�s

&rtc@seZdZdd�ZejZdS)r)cCs|�tjj|�S)N)r�r�r�ry)rr�rLrLrM�	http_openaszHTTPHandler.http_openN)r�r�r�r�rtr{rGrLrLrLrMr)_sr�c@s$eZdZddd�Zdd�ZejZdS)rErNcCst�||�||_||_dS)N)rtr��_context�_check_hostname)rrvr>�check_hostnamerLrLrMr�jszHTTPSHandler.__init__cCs|jtjj||j|jd�S)N)r>r�)r�r�r�r�r�r�)rr�rLrLrM�
https_openoszHTTPSHandler.https_open)rNN)r�r�r�r�r�rtr{rKrLrLrLrMrEhs
rEc@s.eZdZddd�Zdd�Zdd�ZeZeZdS)	rNcCs$ddl}|dkr|j��}||_dS)Nr)Zhttp.cookiejar�	cookiejarZ	CookieJar)rr�r�rLrLrMr�xs
zHTTPCookieProcessor.__init__cCs|j�|�|S)N)r�Zadd_cookie_header)rrtrLrLrMrG~sz HTTPCookieProcessor.http_requestcCs|j�||�|S)N)r�Zextract_cookies)rrtr�rLrLrMr��sz!HTTPCookieProcessor.http_response)N)r�r�r�r�rGr�rKr�rLrLrLrMrws

c@seZdZdd�ZdS)r.cCs|j}td|��dS)Nzunknown url type: %s)r�r)rr�r�rLrLrMr��szUnknownHandler.unknown_openN)r�r�r�r�rLrLrLrMr.�scCsRi}xH|D]@}|�dd�\}}|ddkrB|ddkrB|dd�}|||<q
W|S)N�=rRrr2rQ)r9)�lZparsedZeltr�r�rLrLrMrT�s
rTcCs�g}d}d}}xt|D]l}|r,||7}d}q|rV|dkr@d}qn|dkrLd}||7}q|dkrn|�|�d}q|dkrzd}||7}qW|r�|�|�dd�|D�S)	NrmF�\Tr2rjcSsg|]}|���qSrL)rF)r��partrLrLrM�
<listcomp>�sz#parse_http_list.<locals>.<listcomp>)r\)rbZresr��escaper	ZcurrLrLrMrV�s4	

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

zFileHandler.file_openNcCs`tjdkrZy*tt�d�dt�t���d�t_Wn$tjk
rXt�d�ft_YnXtjS)Nr�r:)r*�namesrr��gethostbyname_ex�gethostname�gaierror�
gethostbyname)rrLrLrMr��s
zFileHandler.get_namesc
Cs�ddl}ddl}|j}|j}t|�}y�t�|�}|j}|jj	|j
dd�}	|�|�d}
|�d|
pbd||	f�}|r~t
|�\}}|r�|s�t|�|��kr�|r�d||}
nd|}
tt|d�||
�SWn*tk
r�}zt|��Wdd}~XYnXtd��dS)	NrT)�usegmtz6Content-type: %s
Content-length: %d
Last-modified: %s
z
text/plainzfile://�rbzfile not on local host)�email.utils�	mimetypesrur�r4rV�stat�st_size�utils�
formatdate�st_mtime�
guess_type�message_from_stringr
�_safe_gethostbynamer�rrGrlr)rr��emailr�ruraZ	localfile�statsrh�modified�mtyperdr'Zorigurl�exprLrLrMr��s0
zFileHandler.open_local_file)r�r�r�r�r�r�r�rLrLrLrMr*�s
cCs&y
t�|�Stjk
r dSXdS)N)r�r�r�)rurLrLrMr��s
r�c@seZdZdd�Zdd�ZdS)r+c
Cs,ddl}ddl}|j}|s"td��t|�\}}|dkr>|j}nt|�}t|�\}}|rdt|�\}}nd}t	|�}|pvd}|p~d}yt
�|�}Wn*tk
r�}zt|��Wdd}~XYnXt
|j�\}	}
|	�d�}ttt	|��}|dd�|d}}|�r|d�s|dd�}y�|�||||||j�}
|�r6d�p8d}x:|
D]2}t|�\}}|��d	k�r@|d
k�r@|��}�q@W|
�||�\}}d}|�|j�d}|�r�|d|7}|dk	�r�|dk�r�|d|7}t�|�}t|||j�S|jk
�r&}z"td
|�}|�t� �d��Wdd}~XYnXdS)Nrzftp error: no host givenrmr�rQrRrJ�Dr�)�a�Ar�rJrrr�zContent-type: %s
zContent-length: %d
z
ftp error: %rr:)!�ftplibr�rurr
�FTP_PORTr]rrr
r�r�rlrr�r9r��map�connect_ftprJrrs�upper�retrfiler�ror�r�r�
all_errors�with_traceback�sys�exc_info)rr�r�r�rur'r
rr�rW�attrs�dirsrN�fwr��attrr�rc�retrlenrdr�r��excrLrLrM�ftp_open�s\



zFTPHandler.ftp_openc	Cst||||||dd�S)NF)�
persistent)�
ftpwrapper)rr
rrur'r�rJrLrLrMr�2szFTPHandler.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�<r[)�cacherJ�soonest�delay�	max_conns)rrLrLrMr�9s
zCacheFTPHandler.__init__cCs
||_dS)N)r�)r�trLrLrM�
setTimeout@szCacheFTPHandler.setTimeoutcCs
||_dS)N)r�)rr�rLrLrM�setMaxConnsCszCacheFTPHandler.setMaxConnscCsr|||d�|�|f}||jkr4t��|j|j|<n,t||||||�|j|<t��|j|j|<|��|j|S)Nr�)�joinr�r\r�rJr��check_cache)rr
rrur'r�rJr�rLrLrMr�Fs

zCacheFTPHandler.connect_ftpcCs�t��}|j|krTx@t|j���D].\}}||kr"|j|��|j|=|j|=q"Wtt|j����|_t	|j�|j
kr�x6t|j���D]$\}}||jkr�|j|=|j|=Pq�Wtt|j����|_dS)N)r\r�r�rJrzr�r��min�valuesr_r�)rr�r�r�rLrLrMr�Qs

zCacheFTPHandler.check_cachecCs4x|j��D]}|��qW|j��|j��dS)N)r�r�r��clearrJ)r�connrLrLrM�clear_cachees
zCacheFTPHandler.clear_cacheN)	r�r�r�r�r�r�r�r�r�rLrLrLrMr,6sc@seZdZdd�ZdS)r-cCs~|j}|�dd�\}}|�dd�\}}t|�}|�d�rNt�|�}|dd�}|sVd}t�d|t|�f�}t	t
�|�||�S)N�:rRrjz;base64i����ztext/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
)ror9r�endswithr�decodebytesr�r�r_r�io�BytesIO)rr�rHr�rIZ	mediatyperdrLrLrM�	data_openls


zDataHandler.data_openN)r�r�r�r�rLrLrLrMr-ksr��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�}||_|�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�classr4)�
stacklevel�key_file�	cert_filez
User-Agent)ZAcceptz*/*)r.r�r?r@rAr5rr�r�r��versionr��_URLopener__tempfilesrVrk�_URLopener__unlink�	tempcache�ftpcache)rrZx509r�rLrLrMr��szURLopener.__init__cCs|��dS)N)r�)rrLrLrM�__del__�szURLopener.__del__cCs|��dS)N)�cleanup)rrLrLrMr��szURLopener.closec	CsZ|jrFx2|jD](}y|�|�Wqtk
r4YqXqW|jdd�=|jrV|j��dS)N)r�r�rlr�r�)rrNrLrLrMr��s
zURLopener.cleanupcGs|j�|�dS)N)r�r\)rr�rLrLrM�	addheader�szURLopener.addheaderc
Csltt|��}t|dd�}|jrL||jkrL|j|\}}t|d�}t|||�St|�\}}|s`d}||jkr�|j|}t|�\}}	t|	�\}
}|
|f}nd}d|}||_	|�
dd�}t||�r�|dkr�|r�|�|||�S|�
||�Sy,|dk�r�t||�|�St||�||�SWnVttfk
�r,�Yn<tk
�rf}
ztd	|
��t��d
��Wdd}
~
XYnXdS)Nz%/:=&?~#+!$,;'@()*[]|)r�r�rNZopen_�-r�r�zsocket errorr:)rrr	r�rGrrrrr�r�r��open_unknown_proxy�open_unknownr�rrrlr�r�r�)rr�rIrardrc�urltyperHr�	proxyhostrur�rZr�rLrLrMrG�s<




zURLopener.opencCst|�\}}tdd|��dS)Nz	url errorzunknown url type)rrl)rr�rIr�rHrLrLrMr�szURLopener.open_unknowncCs t|�\}}tdd||��dS)Nz	url errorzinvalid proxy for %s)rrl)rrr�rIr�rHrLrLrMr�
szURLopener.open_unknown_proxyc
Cstt|��}|jr&||jkr&|j|St|�\}}|dkr�|rF|dkr�y.|�|�}|��}|��tt|�d�|fSt	k
r�}	zWdd}	~	XYnX|�
||�}�z>|��}
|r�t
|d�}nrt|�\}}
t|
p�d�\}}
t|
p�d�\}
}t|
p�d�\}
}t
j�|
�d}t�|�\}}|j�|�t
�|d�}z�||
f}|jdk	�rR||j|<d}d}d}d}d|
k�rxt|
d	�}|�r�||||�xH|�|�}|�s�P|t|�7}|�|�|d7}|�r�||||��q�WWd|��XWd|��X|dk�r||k�rtd
||f|��|S)NrNrRrOrmi rQrzcontent-lengthzContent-Lengthz1retrieval incomplete: got only %i out of %i bytes)rrr�rr�rUr�r4rrlrGrrrVrW�splitextrYZmkstempr�r\�fdopenr]r^r_r`r)rrHrarbrIr�Zurl1rcr�r�rdreZgarbagerW�suffix�fdrfrgrhr^rirjrLrLrM�retrievesj






zURLopener.retrievecCs(d}d}t|t�r<t|�\}}|r6t|�\}}t|�}|}nt|\}}t|�\}}t|�\}	}
|
}d}|	��dkrvd}n:t|
�\}}
|r�t|�\}}|r�d|	||
f}t|�r�|}|s�tdd��|r�t|�}t	�
|����d�}nd}|�rt|�}t	�
|����d�}nd}||�}
i}|�r*d||d<|�r<d||d<|�rJ||d	<d
|d<x|j
D]\}}|||<�qZW|dk	�r�d|d
<|
�d|||�n|
jd||d�y|
��}Wn"tjjk
�r�td��YnXd|jk�r�dk�rnnt||jd||j�S|�||j|j|j|j|�SdS)Nr�z	%s://%s%sz
http errorz
no host givenrzBasic %szProxy-AuthorizationrErnr�r|z!application/x-www-form-urlencodedzContent-Typer�r�)rdz$http protocol error: bad status liner�i,zhttp:)r�r�rrr
rrsrrlrrrrr�rtr~r�r�Z
BadStatusLiner�statusrr��
http_errorrcr)rZconnection_factoryrHrIZuser_passwdZproxy_passwdrur�Zrealhostr�r�Z
proxy_authrDZ	http_connrdr:r�r�rLrLrM�_open_generic_httpQsr



zURLopener._open_generic_httpcCs|�tjj||�S)N)r�r�r�ry)rrHrIrLrLrM�	open_http�szURLopener.open_httpc
Csbd|}t||�rPt||�}|dkr6||||||�}	n|||||||�}	|	rP|	S|�|||||�S)Nz
http_error_%d)r�r�r�)
rrHrc�errcode�errmsgrdrIrZr~rfrLrLrMr��s

zURLopener.http_errorcCs|��t||||d��dS)N)r�r)rrHrcr�r�rdrLrLrMr��szURLopener.http_error_defaultcCstjj||j|jd�S)N)r�r�)r�r�r�r�r�)rrurLrLrM�_https_connection�szURLopener._https_connectioncCs|�|j||�S)N)r�r�)rrHrIrLrLrM�
open_https�szURLopener.open_httpscCs^t|t�std��|dd�dkrP|dd�dkrP|dd���dkrPtd��n
|�|�SdS)	NzEfile error: proxy support for file protocol currently not implementedr:z//r4r��z
localhost/z-file:// scheme is supported only on localhost)r�r�rrsrBr�)rrHrLrLrM�	open_file�s

4
zURLopener.open_filec
Cs\ddl}ddl}t|�\}}t|�}yt�|�}Wn0tk
rb}zt|j|j	��Wdd}~XYnX|j
}	|jj|j
dd�}
|�|�d}|�d|p�d|	|
f�}|s�|}
|dd�dkr�d|}
tt|d	�||
�St|�\}}|�sPt�|�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r4rVr�rlr�strerrorrar�r�r�r�r�r�rrGr
r�r�r��thishostrB)rrHr�r�rurNZ	localnamer��erhr�r�rdZurlfiler'rLrLrMr��s: 
zURLopener.open_local_filec
Cs�t|t�std��ddl}t|�\}}|s2td��t|�\}}t|�\}}|r\t|�\}}nd}t|�}t|ppd�}t|p|d�}t	�
|�}|s�ddl}|j}nt
|�}t|�\}}	t|�}|�d�}
|
dd�|
d}
}|
r�|
ds�|
dd�}
|
�r
|
d�s
d|
d<|||d�|
�f}t|j�tk�rfx8t|j�D]*}
|
|k�r8|j|
}|j|
=|���q8Wy�||jk�r�t|||||
�|j|<|�s�d}nd	}x:|	D]2}t|�\}}|��d
k�r�|dk�r�|��}�q�W|j|�||�\}}|�d|�d}d}|�r|d
|7}|dk	�r4|dk�r4|d|7}t�|�}t||d|�St�k
�r�}ztd|�� t!�"�d��Wdd}~XYnXdS)NzCftp error: proxy support for ftp protocol currently not implementedrzftp error: no host givenrmr�rQrRr�rJr�)r�r�r�rJrrr�zftp:zContent-Type: %s
zContent-Length: %d
zftp error %rr:)#r�r�rr�rr
rrr
r�r�r�r�r]rr9r�r_r��MAXFTPCACHEr�r�r�rrsr�r�r�r�r�r�	ftperrorsr�r�r�)rrHr�rurWr'r
rr�r�r�rNr�r�r�r�r�r�rcr�r�rdr�rLrLrM�open_ftp�sp







zURLopener.open_ftpc	
Cs<t|t�std��y|�dd�\}}Wntk
rDtdd��YnX|sNd}|�d�}|dkr�d	||d�kr�||dd�}|d|�}nd
}g}|�dt�	dt�
t�����|�d
|�|dkr�t�|�
d���d�}nt|�}|�dt|��|�d
�|�|�d�|�}t�|�}t�|�}t|||�S)NzEdata error: proxy support for data protocol currently not implementedrjrRz
data errorzbad data URLztext/plain;charset=US-ASCII�;rr�rmzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srrzlatin-1zContent-Length: %d�
)r�r�rr9rBrl�rfindr\r\ZstrftimeZgmtimerr�rrr
r_r�r�r�r��StringIOr)	rrHrIr�Zsemir�r�rd�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�r�r�rLrLrLrMr8�s,

$


A\


	 :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)rr�r-rLrLrMr�`szFancyURLopener.__init__cCst||d||�S)Nzhttp:)r)rrHrcr�r�rdrLrLrMr�fsz!FancyURLopener.http_error_defaultNc	Csn|jd7_zR|jrJ|j|jkrJt|d�r4|j}n|j}|||dd|�S|�||||||�}|Sd|_XdS)NrR�http_error_500i�z)Internal Server Error: Redirect Recursionr)rrr�rr��redirect_internal)	rrHrcr�r�rdrIr�rfrLrLrMrjs
zFancyURLopener.http_error_302c	Csxd|kr|d}nd|kr$|d}ndS|��t|jd||�}t|�}|jdkrnt|||d|||��|�|�S)Nr�r�r�)r�r�r�rmz( Redirection to url '%s' is not allowed.)r�rr�rr�rrG)	rrHrcr�r�rdrIr�rrLrLrMr|s


z FancyURLopener.redirect_internalcCs|�||||||�S)N)r)rrHrcr�r�rdrIrLrLrMr�szFancyURLopener.http_error_301cCs|�||||||�S)N)r)rrHrcr�r�rdrIrLrLrMr�szFancyURLopener.http_error_303cCs2|dkr|�||||||�S|�|||||�SdS)N)rr�)rrHrcr�r�rdrIrLrLrMr�szFancyURLopener.http_error_307Fc
Cs�d|krt�||||||�|d}t�d|�}	|	sHt�||||||�|	��\}
}|
��dkrtt�||||||�|s�t�||||||�d|jd}|dkr�t||�||�St||�|||�SdS)Nzwww-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r=Zretry_�_basic_auth)r8r�rH�matchr7rsr�r�)
rrHrcr�r�rdrIrs�stuffrr�rrZrLrLrMrL�s&





zFancyURLopener.http_error_401c
Cs�d|krt�||||||�|d}t�d|�}	|	sHt�||||||�|	��\}
}|
��dkrtt�||||||�|s�t�||||||�d|jd}|dkr�t||�||�St||�|||�SdS)Nzproxy-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r=Zretry_proxy_r)r8r�rHrr7rsr�r�)
rrHrcr�r�rdrIrsrrr�rrZrLrLrMrM�s&





zFancyURLopener.http_error_407cCs�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	�d�d}|	|d�}	|�|	||�\}}
|sr|
srdSdt|dd�t|
dd�|	f}	d|	|
|jd<|dkr�|�|�S|�||�SdS)Nzhttp://r��@rRz%s:%s@%srm)r�)rrrr��get_user_passwdr	rG)rrHrrIrur�r�rr�r��
proxyselectorr�r
rrLrLrM�retry_proxy_http_basic_auth�s 

z*FancyURLopener.retry_proxy_http_basic_authcCs�t|�\}}d||}|jd}t|�\}}	t|	�\}	}
|	�d�d}|	|d�}	|�|	||�\}}
|sr|
srdSdt|dd�t|
dd�|	f}	d|	|
|jd<|dkr�|�|�S|�||�SdS)Nzhttps://r�rrRz%s:%s@%srm)r�)rrrr�r	r	rG)rrHrrIrur�r�rr�r�r
r�r
rrLrLrM�retry_proxy_https_basic_auth�s 

z+FancyURLopener.retry_proxy_https_basic_authc
Cs�t|�\}}|�d�d}||d�}|�|||�\}}|sD|sDdSdt|dd�t|dd�|f}d||}	|dkr�|�|	�S|�|	|�SdS)NrrRz%s:%s@%srm)r�zhttp://)rr�r	r	rG)
rrHrrIrur�r�r
rr�rLrLrMr>�s
z$FancyURLopener.retry_http_basic_authc
Cs�t|�\}}|�d�d}||d�}|�|||�\}}|sD|sDdSdt|dd�t|dd�|f}d||}	|dkr�|�|	�S|�|	|�SdS)NrrRz%s:%s@%srm)r�zhttps://)rr�r	r	rG)
rrHrrIrur�r�r
rr�rLrLrM�retry_https_basic_auth	s
z%FancyURLopener.retry_https_basic_authrcCs`|d|��}||jkr2|r(|j|=n
|j|S|�||�\}}|sJ|rX||f|j|<||fS)Nr)rsr�prompt_user_passwd)rrurr�r�r
rrLrLrMr		s


zFancyURLopener.get_user_passwdcCsTddl}y,td||f�}|�d|||f�}||fStk
rNt�dSXdS)NrzEnter username for %s at %s: z#Enter password for %s in %s at %s: )NN)�getpass�input�KeyboardInterrupt�print)rrurrr
rrLrLrMr$	sz!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)r�r�r�r�r�rrrrrrLrMrrr>r
r	rrLrLrLrMr9]s"










cCstdkrt�d�atS)Nr�)�
_localhostr�r�rLrLrLrMr�4	s
r�cCsPtdkrLytt�t���d�aWn(tjk
rJtt�d�d�aYnXtS)Nr:r�)�	_thishostrr�r�r�r�rLrLrLrMr�<	sr�cCstdkrddl}|jatS)Nr)�
_ftperrorsr�r�)r�rLrLrMr�G	sr�cCstdkrt�d�atS)Nrm)�
_noheadersr�r�rLrLrLrM�	noheadersP	s
rc@sFeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dS)r�NTcCsX||_||_||_||_||_||_d|_||_y|��Wn|�	��YnXdS)Nr)
r
rrur'r�rJ�refcount�	keepalive�initr�)rr
rrur'r�rJr�rLrLrMr�]	szftpwrapper.__init__cCs\ddl}d|_|��|_|j�|j|j|j�|j�|j	|j
�d�|j�}|j�
|�dS)Nrr�)r��busyZFTPr�Zconnectrur'rJZloginr
rr�r��cwd)rr�Z_targetrLrLrMrm	s
zftpwrapper.initc
Cs�ddl}|��|dkr"d}d}nd|}d}y|j�|�Wn*|jk
rh|��|j�|�YnXd}|r�|s�yd|}|j�|�\}}WnR|jk
r�}z2t|�dd�dkr�t	d	|��
t��d
��Wdd}~XYnX|�s�|j�d�|�rl|j�
�}	zJy|j�|�Wn4|jk
�rN}zt	d	|�|�Wdd}~XYnXWd|j�|	�Xd|}nd}|j�|�\}}d|_t|�d
�|j�}
|jd7_|��|
|fS)Nr)rrr�zTYPE ArRzTYPE zRETR r4Z550z
ftp error: %rr:zLIST ZLISTr�)r��endtransferr�Zvoidcmdr�rZntransfercmdZ
error_permr�rr�r�r��pwdrrrZmakefile�
file_closerr�)rrNr�r��cmd�isdirr�r�rrZftpobjrLrLrMr�v	sN 
$
zftpwrapper.retrfilecCs
d|_dS)Nr)r)rrLrLrMr�	szftpwrapper.endtransfercCsd|_|jdkr|��dS)NFr)rr�
real_close)rrLrLrMr��	s
zftpwrapper.closecCs2|��|jd8_|jdkr.|js.|��dS)NrRr)rrrr")rrLrLrMr�	szftpwrapper.file_closecCs2|��y|j��Wnt�k
r,YnXdS)N)rr�r�r�)rrLrLrMr"�	s
zftpwrapper.real_close)NT)
r�r�r�r�rr�rr�rr"rLrLrLrMr�Z	s
	-r�cCs�i}xBtj��D]4\}}|��}|r|dd�dkr|||dd�<qWdtjkr^|�dd�xXtj��D]J\}}|dd�dkrj|��}|r�|||dd�<qj|�|dd�d�qjW|S)Ni�����_proxyZREQUEST_METHODr�)rV�environrzrsr�)rrZr�rLrLrM�getproxies_environment�	s	
r%cCs�|dkrt�}y|d}Wntk
r.dSX|dkr<dS|��}t|�\}}xd|�d�D]V}|��}|r\|�d�}|��}||ks�||kr�dSd|}|�|�s�|�|�r\dSq\WdS)N�noF�*Trj�.)r%rkrsr
r9rF�lstripr�)rurZno_proxy�hostonlyr'rZrLrLrM�proxy_bypass_environment�	s*
r+c	Csddlm}t|�\}}dd�}d|kr4|dr4dSd}x�|�dd	�D]�}|sPqFt�d
|�}|dk	�r|dkr�yt�|�}||�}Wntk
r�wFYnX||�d��}	|�d�}
|
dkr�d
|�d��	d�d}
nt
|
dd��}
d|
}
||
?|	|
?k�rdSqF|||�rFdSqFWdS)Nr)�fnmatchcSsh|�d�}ttt|��}t|�dkr<|ddddgdd�}|dd>|dd>B|dd>B|d	BS)
Nr(r�r�rRr[r:rZr4)r9r�r�r]r_)ZipAddrr&rLrLrM�ip2num
s

z,_proxy_bypass_macosx_sysconf.<locals>.ip2numr(Zexclude_simpleT�
exceptionsrLz(\d+(?:\.\d+)*)(/\d+)?rRr:rZ� F)r,r
r�rHrr�r�rl�group�countr])ru�proxy_settingsr,r*r'r.ZhostIPr�r�r(�maskrLrLrM�_proxy_bypass_macosx_sysconf�	s:



r5�darwin)�_get_proxy_settings�_get_proxiescCst�}t||�S)N)r7r5)rur3rLrLrM�proxy_bypass_macosx_sysconf<
sr9cCst�S)N)r8rLrLrLrM�getproxies_macosx_sysconf@
sr:cCs t�}|rt||�St|�SdS)N)r%r+r9)rurrLrLrMrJ
s
rcCst�p
t�S)N)r%r:rLrLrLrMr5W
sc
Csi}yddl}Wntk
r$|SXy�|�|jd�}|�|d�d}|r�t|�|d�d�}d|kr�x�|�d�D]4}|�dd�\}}t�d|�s�d	||f}|||<qrWn>|dd
�dkr�||d<n$d
||d<d||d<d||d<|�	�Wnt
ttfk
�rYnX|S)Nrz;Software\Microsoft\Windows\CurrentVersion\Internet Settings�ProxyEnableZProxyServerr�r�rRz
(?:[^/:]+)://z%s://%srRzhttp:r�z	http://%sz
https://%sr�zftp://%sr�)
�winreg�ImportError�OpenKey�HKEY_CURRENT_USER�QueryValueExr�r9rHrZCloserlrBr�)rr<�internetSettings�proxyEnableZproxyServer�pr�ZaddressrLrLrM�getproxies_registry\
s8

rDcCst�p
t�S)N)r%rDrLrLrLrMr5�
scCsxyddl}Wntk
r dSXy6|�|jd�}|�|d�d}t|�|d�d�}Wntk
rldSX|rv|szdSt|�\}}|g}y t�	|�}||kr�|�
|�Wntk
r�YnXy t�|�}||kr�|�
|�Wntk
r�YnX|�d�}xp|D]h}	|	dk�r$d|k�r$dS|	�
dd	�}	|	�
d
d�}	|	�
dd�}	x$|D]}
t�|	|
tj��rNdS�qNW�qWdS)
Nrz;Software\Microsoft\Windows\CurrentVersion\Internet Settingsr;Z
ProxyOverrider�z<local>r(rRz\.r'z.*�?)r<r=r>r?r@r�rlr
r�r�r\Zgetfqdnr9r�rHrrJ)rur<rArBZ
proxyOverrideZrawHostr'ZaddrZfqdnr)r�rLrLrM�proxy_bypass_registry�
sR







rFcCs t�}|rt||�St|�SdS)N)r%r+rF)rurrLrLrMr�
s
)NNN)N)}rr�r�r^Zhttp.clientr�r�rV�	posixpathrHr�r�r�r\rYrSr?Zurllib.errorrrrZurllib.parserrrrr	r
rrr
rrrrrrrrrZurllib.responserrrDr=rC�__all__�version_infor�rFr�r0r1r[r6r7rI�ASCIIrqrvrrr2rr/rrrrr r!r"r#r$r%�urandomr]r&r'r(rtr)r�r�rEr\rr.rTrVr*r�r+r,r-r�rZZ
nturl2pathr4r3r�r8r9rr�rr�rr�rrr�r%r+r5�platformZ_scproxyr7r8r9r:rr5rDrFrLrLrLrM�<module>Ts�P
T
?n$q*@
ov

+3:5!@W

_
%<

-	2


Zerion Mini Shell 1.0