File "request.cpython-34.pyc"

Full Path: /home/attunedd/public_html/byp/izo/con7ext_sym404/rintoar.txt/opt/alt/python34/lib64/python3.4/urllib/__pycache__/request.cpython-34.pyc
File size: 72.41 KB
MIME-type: text/x-bytecode.python
Charset: 8 bit


e fl(@sdZddlZddlZddlZddlZddlZddlZddlZddl	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+yddl,Z,Wne-k
rdZ.YnXdZ.dd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'g Z/ej0dd(Z1da2dej3d)dd*dd+dd,dd-dZ4d.dZ5gZ6dddd/d$Z7d0d%Z8e
j9d1e
j:Z;d2d3Z<Gd4ddZ=Gd5d	d	Z>d6d Z?Gd7d
d
Z@Gd8dde@ZAGd9dde@ZBGd:dde@ZCd;d<ZDGd=dde@ZEGd>ddZFGd?ddeFZGGd@ddZHGdAddeHe@ZIGdBddeHe@ZJejKZLGdCddZMGdDdde@eMZNGdEdde@eMZOGdFdGdGe@ZPGdHddePZQeRejSdIrhGdJdKdKePZTe/jUdKnGdLd
d
e@ZVGdMdde@ZWdNdOZXdPdQZYGdRdde@ZZdSdTZ[GdUdde@Z\GdVdde\Z]GdWdde@Z^dXZ_ej`dYkr>ddZlambZbmcZcnd[d"Zbd\d!ZciZdGd]d&d&ZeGd^d'd'eeZfdagd_d`ZhdaidadbZjdakdcddZldamdedfZnGdgdhdhZodidjZpdkdlZqdmdnZrejsdokr\ddpltmuZumvZvdqdrZwdsdtZxdudvZydwd#ZznNej`dYkrdxdyZ{dzd#Zzd{d|Z|d}dvZynepZzeqZydS)~a
An extensible library for opening URLs using a variety of protocols

The simplest way to use this module is to call the urlopen function,
which accepts a string containing a URL or a Request object (described
below).  It opens the URL and returns the results as file-like
object; the returned object has some extra methods described below.

The OpenerDirector manages a collection of Handler objects that do
all the actual work.  Each Handler implements a particular protocol or
option.  The OpenerDirector is a composite object that invokes the
Handlers needed to open the requested URL.  For example, the
HTTPHandler performs HTTP GET and POST requests and deals with
non-error returns.  The HTTPRedirectHandler automatically deals with
HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler
deals with digest authentication.

urlopen(url, data=None) -- Basic usage is the same as original
urllib.  pass the url and optionally data to post to an HTTP URL, and
get a file-like object back.  One difference is that you can also pass
a Request instance instead of URL.  Raises a URLError (subclass of
OSError); for HTTP errors, raises an HTTPError, which can also be
treated as a valid response.

build_opener -- Function that creates a new OpenerDirector instance.
Will install the default handlers.  Accepts one or more Handlers as
arguments, either instances or Handler classes that it will
instantiate.  If one of the argument is a subclass of the default
handler, the argument will be installed instead of the default.

install_opener -- Installs a new opener as the default opener.

objects of interest:

OpenerDirector -- Sets up the User Agent as the Python-urllib client and manages
the Handler classes, while dealing with requests and responses.

Request -- An object that encapsulates the state of a request.  The
state can be as simple as the URL.  It can also include extra HTTP
headers, e.g. a User-Agent.

BaseHandler --

internals:
BaseHandler and parent
_call_chain conventions

Example usage:

import urllib.request

# set up authentication info
authinfo = urllib.request.HTTPBasicAuthHandler()
authinfo.add_password(realm='PDQ Application',
                      uri='https://mahler:8092/site-updates.py',
                      user='klem',
                      passwd='geheim$parole')

proxy_support = urllib.request.ProxyHandler({"http" : "http://ahad-haam:3128"})

# build a new opener that adds authentication and caching FTP handlers
opener = urllib.request.build_opener(proxy_support, authinfo,
                                     urllib.request.CacheFTPHandler)

# install it
urllib.request.install_opener(opener)

f = urllib.request.urlopen('http://www.python.org/')
N)URLError	HTTPErrorContentTooShortError)urlparseurlspliturljoinunwrapquoteunquote	splittype	splithost	splitport	splitusersplitpasswd	splitattr
splitquery
splitvaluesplittagto_bytesunquote_to_bytes
urlunparse)
addinfourladdclosehookFTRequestOpenerDirectorBaseHandlerHTTPDefaultErrorHandlerHTTPRedirectHandlerHTTPCookieProcessorProxyHandlerHTTPPasswordMgrHTTPPasswordMgrWithDefaultRealmAbstractBasicAuthHandlerHTTPBasicAuthHandlerProxyBasicAuthHandlerAbstractDigestAuthHandlerHTTPDigestAuthHandlerProxyDigestAuthHandlerHTTPHandlerFileHandler
FTPHandlerCacheFTPHandlerDataHandlerUnknownHandlerHTTPErrorProcessorurlopeninstall_openerbuild_openerpathname2urlurl2pathname
getproxiesurlretrieve
urlcleanup	URLopenerFancyURLopenercafilecapath	cadefaultcontextc	Cs|s|s|r|dk	r-tdntsBtdntjtjjd|d|}td|}t|}nF|rtd|}t|}n"tdkrta}nt}|j	|||S)NzDYou can't pass both context and any of cafile, capath, and cadefaultzSSL support not availabler:r;r=)

ValueError	_have_sslsslZcreate_default_contextZPurposeZSERVER_AUTHHTTPSHandlerr1_openeropen)	urldatatimeoutr:r;r<r=Z
https_handleropenerrH3/opt/alt/python34/lib64/python3.4/urllib/request.pyr/s$	cCs
|adS)N)rB)rGrHrHrIr0scCst|\}}tjt||E}|j}|dkrb|rbtjj||fS|rzt|d}n(t	j
dd}|j}tj
||||f}	d
}
d}d}d}
d	|krt|d
}n|r||
|
|nx]|j|
}|s!Pn|t|7}|j||
d7}
|r||
|
|qqWWdQXWdQX|dkr||krtd||f|	n|	S)aW
    Retrieve a URL into a temporary location on disk.

    Requires a URL argument. If a filename is passed, it is used as
    the temporary file location. The reporthook argument should be
    a callable that accepts a block number, a read size, and the
    total file size of the URL target. The data argument should be
    valid URL encoded data.

    If a filename is passed and the URL points to a local resource,
    the result is a copy from local file to new file.

    Returns a tuple containing the path to the newly created
    data file as well as the resulting HTTPMessage object.
    filewbZdeleteFirzcontent-lengthzContent-LengthNz1retrieval incomplete: got only %i out of %i bytesi )r
contextlibclosingr/infoospathnormpathrCtempfileZNamedTemporaryFilename_url_tempfilesappendintreadlenwriter)rDfilename
reporthookrEZurl_typerSfpheaderstfpresultbssizerZblocknumblockrHrHrIr5sD	


#cCsWx4tD],}ytj|Wqtk
r2YqXqWtdd=trSdandS)z0Clean up temporary files from urlretrieve calls.N)rWrRunlinkOSErrorrB)Z	temp_filerHrHrIr6s

	
z:\d+$cCsY|j}t|d}|dkr:|jdd}ntjd|d}|jS)zReturn request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    rMHost)full_urlr
get_header_cut_port_resublower)requestrDhostrHrHrIrequest_hosts	rrc@s*eZdZdidddddZeddZejddZejddZed	d
Zejdd
Zejdd
Zd
dZ	ddZ
ddZddZddZ
ddZddZddZdddZdd Zd!d"ZdS)#rNFc	Cs||_i|_i|_d|_||_d|_x*|jD]\}}|j||qCW|dkr~t|}n||_	||_
|r||_ndS)N)rkr`unredirected_hdrs_datarE_tunnel_hostitems
add_headerrrorigin_req_hostunverifiablemethod)	selfrDrEr`rxryrzkeyvaluerHrHrI__init__s								zRequest.__init__cCs&|jrdj|j|jS|jS)Nz{}#{})fragmentformat	_full_url)r{rHrHrIrks	zRequest.full_urlcCs8t||_t|j\|_|_|jdS)N)rrrr_parse)r{rDrHrHrIrk scCsd|_d|_d|_dS)Nri)rrselector)r{rHrHrIrk's		cCs|jS)N)rt)r{rHrHrIrE-szRequest.datacCs>||jkr:||_|jdr:|jdq:ndS)NzContent-length)rt
has_header
remove_header)r{rErHrHrIrE1s	cCs
d|_dS)N)rE)r{rHrHrIrE;scCswt|j\|_}|jdkr=td|jnt|\|_|_|jrst|j|_ndS)Nzunknown url type: %r)	rrtyper>rkrrqrr
)r{restrHrHrIr?s	zRequest._parsecCs+|jdk	rdnd}t|d|S)z3Return a string indicating the HTTP request method.NPOSTGETrz)rEgetattr)r{Zdefault_methodrHrHrI
get_methodGszRequest.get_methodcCs|jS)N)rk)r{rHrHrIget_full_urlLszRequest.get_full_urlcCsJ|jdkr(|jr(|j|_n||_|j|_||_dS)Nhttps)rrurqrkr)r{rqrrHrHrI	set_proxyOs
	zRequest.set_proxycCs|j|jkS)N)rrk)r{rHrHrI	has_proxyWszRequest.has_proxycCs||j|j<dS)N)r`
capitalize)r{r|valrHrHrIrwZszRequest.add_headercCs||j|j<dS)N)rsr)r{r|rrHrHrIadd_unredirected_header^szRequest.add_unredirected_headercCs||jkp||jkS)N)r`rs)r{header_namerHrHrIrbszRequest.has_headercCs"|jj||jj||S)N)r`getrs)r{rdefaultrHrHrIrlfs	zRequest.get_headercCs*|jj|d|jj|ddS)N)r`poprs)r{rrHrHrIrkszRequest.remove_headercCs/|jj}|j|jt|jS)N)rscopyupdater`listrv)r{hdrsrHrHrIheader_itemsoszRequest.header_items)__name__
__module____qualname__r~propertyrksetterdeleterrErrrrrrwrrrlrrrHrHrHrIrs(
c@speZdZddZddZddZddZd	ejd
dZ	d	dd
Z
ddZd	S)rcCsMdt}d|fg|_g|_i|_i|_i|_i|_dS)NzPython-urllib/%sz
User-agent)__version__
addheadershandlershandle_openhandle_errorprocess_responseprocess_request)r{Zclient_versionrHrHrIr~us
				zOpenerDirector.__init__cCst|ds(tdt|nd}xxt|D]j}|dkrSq;n|jd}|d|}||dd}|jd	r
|jd|d}||dd}yt|}Wntk
rYnX|jj	|i}	|	|j|<n]|d
kr(|}|j
}	n?|dkrF|}|j}	n!|dkr;|}|j}	nq;|	j
|g}
|
rtj|
|n
|
j|d
}q;W|rtj|j||j|ndS)N
add_parentz%expected BaseHandler instance, got %rFredirect_requestdo_open
proxy_open_rMerrorrCresponserpT)zredirect_requestzdo_openz
proxy_open)hasattr	TypeErrorrdirfind
startswithrYr>rrrrr
setdefaultbisectZinsortrXrr)r{handlerZaddedmethiprotocolZ	conditionjkindlookuprrHrHrIadd_handlersJ


zOpenerDirector.add_handlercCsdS)NrH)r{rHrHrIcloseszOpenerDirector.closec	GsR|j|f}x9|D]1}t||}||}|dk	r|SqWdS)N)rr)	r{chainr	meth_nameargsrrfuncrbrHrHrI_call_chains
zOpenerDirector._call_chainNc
Cst|tr!t||}n|}|dk	r?||_n||_|j}|d}x8|jj|gD]!}t||}||}qqW|j	||}	|d}x;|j
j|gD]$}t||}|||	}	qW|	S)NZ_requestZ	_response)
isinstancestrrrErFrrrr_openr)
r{fullurlrErFreqrrZ	processorrrrHrHrIrCs"		

zOpenerDirector.opencCsp|j|jdd|}|r%|S|j}|j|j||d|}|rW|S|j|jdd|S)NrZdefault_openrunknownunknown_open)rrr)r{rrErbrrHrHrIrs	
zOpenerDirector._opencGs|d
kr<|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|}|r|S|r|dd	f|}|j|SdS)Nhttprz
http_error_%srMZ_errorrrhttp_error_default)zhttpzhttps)rr)r{protordictrZhttp_errZ	orig_argsrbrHrHrIrs 


		
zOpenerDirector.error)rrrr~rrrsocket_GLOBAL_DEFAULT_TIMEOUTrCrrrHrHrHrIrts/c	GsCt}ttttttttt	g	}t
tjdrL|j
tnt}xo|D]g}x^|D]V}t|trt||r|j|qqit||ri|j|qiqiWq\Wx|D]}|j|qWx|D]}|j|qWx6|D].}t|tr.|}n|j|q
W|S)a*Create an opener object from a list of handlers.

    The opener will use several default handlers, including support
    for HTTP, FTP and when applicable HTTPS.

    If any of the handlers passed as arguments are subclasses of the
    default handlers, the default handlers will not be used.
    HTTPSConnection)rrr-r(rrr*r)r.r,rrclientrXrAsetrr
issubclassaddremover)rrGZdefault_classesskipklassZcheckhrHrHrIr1s0						




c@s:eZdZdZddZddZddZdS)	ricCs
||_dS)N)parent)r{rrHrHrIr)szBaseHandler.add_parentcCsdS)NrH)r{rHrHrIr,szBaseHandler.closecCs#t|dsdS|j|jkS)N
handler_orderT)rr)r{otherrHrHrI__lt__0szBaseHandler.__lt__N)rrrrrrrrHrHrHrIr&sc@s.eZdZdZdZddZeZdS)r.zProcess HTTP error responses.icCsd|j|j|j}}}d|ko7dkns`|jjd|||||}n|S)Ni,r)codemsgrQrr)r{rprrrrrHrHrI
http_response=s
 	z HTTPErrorProcessor.http_responseN)rrr__doc__rrhttps_responserHrHrHrIr.9sc@seZdZddZdS)rcCst|j||||dS)N)rrk)r{rr_rrrrHrHrIrKsz*HTTPDefaultErrorHandler.http_error_defaultN)rrrrrHrHrHrIrJsc@sHeZdZdZdZddZddZeZZZ	dZ
dS)	r
c	s|j}|dkr$|dkp9|dko9|dksZt|j||||n|jdd	}dtfdd
|jjD}t|d|d|jddS)aReturn a Request or None in response to a redirect.

        This is called by the http_error_30x methods when a
        redirection response is received.  If a redirection should
        take place, return a new Request to allow http_error_30x to
        perform the redirect.  Otherwise, raise HTTPError if no-one
        else should try to handle this url.  Return None if you can't
        but another Handler might.
        -./3rHEADr z%20content-lengthcontent-typec3s3|])\}}|jkr||fVqdS)N)ro).0kv)CONTENT_HEADERSrHrI	<genexpr>ms	z7HTTPRedirectHandler.redirect_request.<locals>.<genexpr>r`rxryT)rrrr)zGETr)rrr)rr)	rrrkreplacerr`rvrrx)	r{rr_rrr`newurlmZ
newheadersrH)rrIrVs
(		z$HTTPRedirectHandler.redirect_requestc
Csd|kr|d}nd|kr2|d}ndSt|}|jdkrvt||d||f||n|jst|}d|d	<nt|}t|j|}|j||||||}|dkrdSt	|d
r[|j
}	|_
|	j|d|jks3t
|	|jkrot|j||j|||qoni}	|_
|_
|	j|dd|	|<|j|j|jj|d
|jS)Nlocationurirrftpriz+%s - Redirection to url '%s' is not allowed/r
redirect_dictrrMrF)zhttpzhttpszftpri)rschemerrSrrrrkrrrrmax_repeatsr[max_redirectionsinf_msgrZrrrCrF)
r{rr_rrr`rurlpartsnewZvisitedrHrHrIhttp_error_302xs<


	


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)rrrrrrrhttp_error_301http_error_303http_error_307rrHrHrHrIrNs"7c	Cst|\}}|jds0d}|}nY|jdsRtd|n|jdd}|dkryd}n|d|}t|\}}|dk	rt|\}}n
d}}||||fS)aReturn (scheme, user, password, host/port) given a URL or an authority.

    If a URL is supplied, it must have an authority (host:port) component.
    According to RFC 3986, having an authority component means the URL must
    have two slashes after the scheme.
    rNz//zproxy URL with no authority: %rrrMrN)rrr>rrr)	proxyrZr_scheme	authorityendZuserinfohostportuserpasswordrHrHrI_parse_proxys		
r
c@s1eZdZdZdddZddZdS)rdNc	Cs|dkrt}nt|ds3td||_x@|jD]2\}}t|d||||jddqIWdS)Nkeyszproxies must be a mappingz%s_opencSs||||S)NrH)rrrrrHrHrI<lambda>sz'ProxyHandler.__init__.<locals>.<lambda>)r4rAssertionErrorproxiesrvsetattrr)r{rrrDrHrHrIr~s	
zProxyHandler.__init__cCs|j}t|\}}}}|dkr6|}n|jrRt|jrRdS|r|rdt|t|f}	tj|	jjd}
|j	dd|
nt|}|j
||||ks|dkrdS|jj|d|j
SdS)Nz%s:%sasciizProxy-authorizationzBasic rrF)rr
rqproxy_bypassr
base64	b64encodeencodedecoderwrrrCrF)r{rrrZ	orig_typeZ
proxy_typerrr
Z	user_passZcredsrHrHrIrs 		zProxyHandler.proxy_open)rrrrr~rrHrHrHrIrs
c@sOeZdZddZddZddZddd	Zd
dZdS)
r cCs
i|_dS)N)passwd)r{rHrHrIr~szHTTPPasswordMgr.__init__cst|tr|g}n|jkr:ij|<nxGdD]?tfdd|D}||fj||<qAWdS)NTFcs"g|]}j|qSrH)
reduce_uri)ru)default_portr{rHrI
<listcomp>
s	z0HTTPPasswordMgr.add_password.<locals>.<listcomp>)TF)rrrtuple)r{realmrrrZreduced_urirH)rr{rIadd_passwords
zHTTPPasswordMgr.add_passwordc	Cs|jj|i}xddD]\}|j||}xA|jD]3\}}x$|D]}|j||rT|SqTWqAWqWdS)NTF)TF)NN)rrrrv	is_suburi)	r{r!authuriZdomainsrZreduced_authuriZurisZauthinforrHrHrIfind_user_password
s

z"HTTPPasswordMgr.find_user_passwordTc
Cst|}|dr=|d}|d}|dp7d}nd}|}d}t|\}}|r|dkr|dk	ridd6dd	6j|}	|	dk	rd
||	f}qn||fS)z@Accept authority or URI and extract only the authority and path.rMrrrNPrirz%s:%d)rr
r)
r{rrpartsrrrSrqportZdportrHrHrIrs 




	zHTTPPasswordMgr.reduce_uricCsi||krdS|d|dkr(dStj|d|df}t|t|dkredSdS)zcCheck if test is below base in a URI tree

        Both args must be URIs in reduced form.
        TrFrM)	posixpathcommonprefixr[)r{basetestZcommonrHrHrIr#.szHTTPPasswordMgr.is_suburiN)rrrr~r"r%rr#rHrHrHrIr s

c@seZdZddZdS)r!cCsDtj|||\}}|dk	r1||fStj|d|S)N)r r%)r{r!r$rrrHrHrIr%?s

z2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)rrrr%rHrHrHrIr!=sc@sLeZdZejdejZdddZddZddZ	dS)	r"z1(?:.*,)*[ 	]*([^ 	]+)[ 	]+realm=(["']?)([^"']*)\2NcCs4|dkrt}n||_|jj|_dS)N)r rr")r{Zpassword_mgrrHrHrIr~Us	z!AbstractBasicAuthHandler.__init__c	Cs|j|d}|r|jd}|jdkrMtd|qtjj|}|r|j\}}}|dkrtj	dt
dn|jdkr|j|||SqndS)	NrbasiczDAbstractBasicAuthHandler does not support the following scheme: '%s'"'zBasic Auth Realm was unquotedr)r.r/)rsplitror>r"rxsearchgroupswarningswarnUserWarningretry_http_basic_auth)	r{authreqrqrr`rZmor	r!rHrHrIhttp_error_auth_reqed[s
	
z.AbstractBasicAuthHandler.http_error_auth_reqedcCs|jj||\}}|dk	rd||f}dtj|jjd}|j|jd|krxdS|j|j||j	j
|d|jSdSdS)Nz%s:%szBasic rrF)rr%rrrrrlauth_headerrrrCrF)r{rqrr!rpwrawauthrHrHrIr7qs"z.AbstractBasicAuthHandler.retry_http_basic_auth)
rrrrecompileIr1r~r9r7rHrHrHrIr"Gs
	c@s"eZdZdZddZdS)r#
AuthorizationcCs%|j}|jd|||}|S)Nzwww-authenticate)rkr9)r{rr_rrr`rDrrHrHrIhttp_error_401s		z#HTTPBasicAuthHandler.http_error_401N)rrrr:rBrHrHrHrIr#~sc@s"eZdZdZddZdS)r$zProxy-authorizationcCs%|j}|jd|||}|S)Nzproxy-authenticate)rqr9)r{rr_rrr`rrrHrHrIhttp_error_407s		z$ProxyBasicAuthHandler.http_error_407N)rrrr:rCrHrHrHrIr$sc@sseZdZdddZddZddZdd	Zd
dZdd
ZddZ	ddZ
dS)r%NcCsO|dkrt}n||_|jj|_d|_d|_d|_dS)Nr)r rr"retriednonce_count
last_nonce)r{rrHrHrIr~s			z"AbstractDigestAuthHandler.__init__cCs
d|_dS)Nr)rD)r{rHrHrIreset_retry_countsz+AbstractDigestAuthHandler.reset_retry_countcCs|j|d}|jdkr?t|jdd|dn|jd7_|r|jd}|jdkr|j||S|jdkrtd|qndS)	Nizdigest auth failedrMrZdigestr-zEAbstractDigestAuthHandler does not support the following scheme: '%s')rrDrrkr0roretry_http_digest_authr>)r{r:rqrr`r8rrHrHrIr9sz/AbstractDigestAuthHandler.http_error_auth_reqedcCs|jdd\}}ttdt|}|j||}|rd|}|jj|jd|krwdS|j|j||j	j
|d|j}|SdS)NrrMz	Digest %srF)r0parse_keqv_listfilterparse_http_listget_authorizationr`rr:rrrCrF)r{rr=tokenZ	challengechalZauth_valZresprHrHrIrIs
z0AbstractDigestAuthHandler.retry_http_digest_authcCsXd|j|tjf}|jdtd}tj|j}|ddS)Nz	%s:%s:%s:rrL)rEtimeZctimer_randombyteshashlibsha1	hexdigest)r{noncesbdigrHrHrI
get_cnoncesz$AbstractDigestAuthHandler.get_cnoncecCs_yK|d}|d}|jd}|jdd}|jdd}Wntk
rcdSYnX|j|\}}	|dkrdS|jj||j\}
}|
dkrdS|jdk	r|j|j|}nd}d|
||f}
d|j|j	f}|d	kr||j
kr=|jd
7_nd
|_||_
d|j}|j|}d||||||f}|	||
|}nD|dkr|	||
d|||f}nt
d
|d|
|||j	|f}|r|d|7}n|r0|d|7}n|d|7}|r[|d||f7}n|S)Nr!rVqop	algorithmMD5opaquez%s:%s:%sz%s:%sr=rMz%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")rKeyErrorget_algorithm_implsrr%rkrEget_entity_digestrrrFrErZr)r{rrOr!rVr[r\r^HKDrr;ZentdigZA1ZA2ZncvalueZcnonceZnoncebitZrespdigr+rHrHrIrMsV


	
		
(
z+AbstractDigestAuthHandler.get_authorizationcsR|dkrddn|dkr6ddnfdd}|fS)Nr]cSstj|jdjS)Nr)rSZmd5rrU)xrHrHrIrsz?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSstj|jdjS)Nr)rSrTrrU)rdrHrHrIrscsd||fS)Nz%s:%srH)rWd)rbrHrIr!srH)r{r\rcrH)rbrIr`sz-AbstractDigestAuthHandler.get_algorithm_implscCsdS)NrH)r{rErOrHrHrIra$sz+AbstractDigestAuthHandler.get_entity_digest)rrrr~rGr9rIrZrMr`rarHrHrHrIr%s	<
c@s.eZdZdZdZdZddZdS)r&zAn authentication protocol defined by RFC 2069

    Digest authentication improves on basic authentication because it
    does not transmit passwords in the clear.
    rAicCs9t|jd}|jd|||}|j|S)NrMzwww-authenticate)rrkr9rG)r{rr_rrr`rqretryrHrHrIrB3s
	
z$HTTPDigestAuthHandler.http_error_401N)rrrrr:rrBrHrHrHrIr&)sc@s(eZdZdZdZddZdS)r'zProxy-AuthorizationicCs/|j}|jd|||}|j|S)Nzproxy-authenticate)rqr9rG)r{rr_rrr`rqrfrHrHrIrC@s
		
z%ProxyDigestAuthHandler.http_error_407N)rrrr:rrCrHrHrHrIr';sc@sCeZdZdddZddZddZdd	Zd
S)AbstractHTTPHandlerrcCs
||_dS)N)_debuglevel)r{
debuglevelrHrHrIr~IszAbstractHTTPHandler.__init__cCs
||_dS)N)rh)r{levelrHrHrIset_http_debuglevelLsz'AbstractHTTPHandler.set_http_debuglevelc
Cs|j}|stdn|jdk	r|j}t|trZd}t|n|jds||jddn|jdsyt|}WnCtk
rt|t	j
rtdt||fnYqX|jddt
||jqn|}|jrDt|j\}}t|\}}	n|jdsf|jd|nxH|jjD]:\}
}|
j}
|j|
ss|j|
|qsqsW|S)	Nz
no host givenzLPOST data should be bytes or an iterable of bytes. It cannot be of type str.zContent-typez!application/x-www-form-urlencodedzContent-lengthzBContent-Length should be specified for iterable data of type %r %rz%drj)rqrrErrrrr
memoryviewcollectionsIterabler>rr[itemsizerrrrrrr)r{rprqrErZmvZsel_hostrZselZsel_pathrVr}rHrHrIdo_request_OsB		

	!zAbstractHTTPHandler.do_request_c
s|j}|stdn||d|j|}t|jjtfdd|jjDdd<tddjD|jri}d}|kr|||<|=n|j	|jd	|nyjy&|j
|j|j|j
Wn1tk
rK}zt|WYd
d
}~XnX|j}	Wn|jYnX|jr|jjd
|_n|j|	_|	j|	_|	S)zReturn an HTTPResponse object for the request, using http_class.

        http_class must implement the HTTPConnection API from http.client.
        z
no host givenrFc3s-|]#\}}|kr||fVqdS)NrH)rrr)r`rHrIrs	z.AbstractHTTPHandler.do_open.<locals>.<genexpr>r
Connectioncss'|]\}}|j|fVqdS)N)title)rrVrrHrHrIrszProxy-Authorizationr`N)rqrrFrrsrr`rvruZ
set_tunnelrprrrErhgetresponserZsockrrDreasonr)
r{Z
http_classrZhttp_conn_argsrqrZtunnel_headersZproxy_auth_hdrerrrrH)r`rIrws<	/
	
&
	
zAbstractHTTPHandler.do_openN)rrrr~rkrprrHrHrHrIrgGs(rgc@s%eZdZddZejZdS)r(cCs|jtjj|S)N)rrrHTTPConnection)r{rrHrHrI	http_openszHTTPHandler.http_openN)rrrrwrgrphttp_requestrHrHrHrIr(src@s:eZdZdddddZddZejZdS)rArNcCs&tj||||_||_dS)N)rgr~_context_check_hostname)r{rir=check_hostnamerHrHrIr~s	zHTTPSHandler.__init__cCs(|jtjj|d|jd|jS)Nr=r{)rrrrryrz)r{rrHrHrI
https_openszHTTPSHandler.https_open)rrrr~r|rgrp
https_requestrHrHrHrIrAsrAc@sCeZdZdddZddZddZeZeZdS)rNcCs7ddl}|dkr*|jj}n||_dS)Nr)Zhttp.cookiejar	cookiejarZ	CookieJar)r{r~rrHrHrIr~szHTTPCookieProcessor.__init__cCs|jj||S)N)r~Zadd_cookie_header)r{rprHrHrIrxsz HTTPCookieProcessor.http_requestcCs|jj|||S)N)r~Zextract_cookies)r{rprrHrHrIrsz!HTTPCookieProcessor.http_response)rrrr~rxrr}rrHrHrHrIrs
c@seZdZddZdS)r-cCs|j}td|dS)Nzunknown url type: %s)rr)r{rrrHrHrIrs	zUnknownHandler.unknown_openN)rrrrrHrHrHrIr-scCspi}xc|D][}|jdd\}}|ddkr^|ddkr^|dd}n|||<q
W|S)z>Parse list of key=value strings where keys are not duplicated.=rMrr.rNrN)r0)lZparsedZeltrrrHrHrIrJs
 rJcCsg}d}d}}x|D]}|r?||7}d}qn|r|dkr]d}qn|dkrrd}n||7}qn|dkr|j|d}qn|dkrd}n||7}qW|r|j|ndd|DS)	apParse lists as described by RFC 2068 Section 2.

    In particular, parse comma-separated lists where the elements of
    the list may include quoted-strings.  A quoted-string could
    contain a comma.  A non-quoted string could have quotes in the
    middle.  Neither commas nor quotes count if they are escaped.
    Only double-quotes count, not single-quotes.
    riF\Tr.,cSsg|]}|jqSrH)strip)rpartrHrHrIrs	z#parse_http_list.<locals>.<listcomp>)rX)rWresrescaper	ZcurrHrHrIrLs4	


	

	rLc@s:eZdZddZdZddZddZdS)r)cCs|j}|dddkrt|dddkrt|jrt|jdkrt|j|jkrtdqn
|j|SdS)Nrz//r9r	localhostz-file:// scheme is supported only on localhost)rrq	get_namesropen_local_file)r{rrDrHrHrI	file_opens	5zFileHandler.file_openNcCs}tjdkrvy7ttjddtjtjdt_Wqvtjk
rrtjdft_YqvXntjS)Nrr)r)namesr rgethostbyname_exgethostnamegaierror
gethostbyname)r{rHrHrIr)s$zFileHandler.get_namescCsaddl}ddl}|j}|j}t|}ytj|}|j}|jj	|j
dd}	|j|d}
|jd|
pd||	f}|rt
|\}}n|s|rt||jkr|rd||}
n
d|}
tt|d||
SWn1tk
rP}zt|WYdd}~XnXtddS)	NrusegmtTz6Content-type: %s
Content-length: %d
Last-modified: %s
z
text/plainzfile://rbzfile not on local host)email.utils	mimetypesrqrr3rRstatst_sizeutils
formatdatest_mtime
guess_typemessage_from_stringr
_safe_gethostbynamerrrCrhr)r{remailrrqr]Z	localfilestatsrdmodifiedmtyper`r(ZorigurlexprHrHrIr4s0			
zFileHandler.open_local_file)rrrrrrrrHrHrHrIr)s
cCs1ytj|SWntjk
r,dSYnXdS)N)rrr)rqrHrHrIrPsrc@s(eZdZddZddZdS)r*cCsddl}ddl}|j}|s6tdnt|\}}|dkr`|j}nt|}t|\}}|rt|\}}nd}t	|}|pd}|pd}yt
j|}Wn1tk
r	}zt|WYdd}~XnXt
|j\}	}
|	jd}ttt	|}|dd|d}}|r|dr|dd}ny|j||||||j}
|rdpd}xM|
D]E}t|\}}|jdkr|dkr|j}qqW|
j||\}}d}|j|jd}|rS|d
|7}n|dk	r||dkr||d|7}ntj|}t|||jSWnQ|jk
r}z.td|}|jtj dWYdd}~XnXdS)Nrzftp error: no host givenrirrMr@DraArrezContent-type: %s
zContent-length: %d
z
ftp error: %rrrNrN)rrrr@rer)!ftplibrrqrr
FTP_PORTrYrrr
rrrhrrr0rmapconnect_ftprFrroupperretrfilerrkrrr
all_errorswith_tracebacksysexc_info)r{rrrrqr(rrrrSattrsdirsrJZfwrattrr}r_retrlenr`rrexcrHrHrIftp_openWs\	!
zFTPHandler.ftp_openc	Cst||||||ddS)N
persistentF)
ftpwrapper)r{rrrqr(rrFrHrHrIrszFTPHandler.connect_ftpN)rrrrrrHrHrHrIr*Vs5c@sXeZdZddZddZddZddZd	d
ZddZd
S)r+cCs1i|_i|_d|_d|_d|_dS)Nr<rP)cacherFsoonestdelay	max_conns)r{rHrHrIr~s
				zCacheFTPHandler.__init__cCs
||_dS)N)r)r{trHrHrI
setTimeoutszCacheFTPHandler.setTimeoutcCs
||_dS)N)r)r{rrHrHrIsetMaxConnsszCacheFTPHandler.setMaxConnscCs|||dj||f}||jkrJtj|j|j|<n<t|||||||j|<tj|j|j|<|j|j|S)Nr)joinrrQrrFrcheck_cache)r{rrrqr(rrFr|rHrHrIrs
zCacheFTPHandler.connect_ftpcCs tj}|j|krxxZt|jjD]@\}}||kr1|j|j|j|=|j|=q1q1Wntt|jj|_t	|j|j
krxJt|jjD]3\}}||jkr|j|=|j|=PqqWtt|jj|_ndS)N)rQrrrFrvrrminvaluesr[r)r{rrrrHrHrIrs"
"

zCacheFTPHandler.check_cachecCsBx!|jjD]}|jqW|jj|jjdS)N)rrrclearrF)r{connrHrHrIclear_caches
zCacheFTPHandler.clear_cacheN)	rrrr~rrrrrrHrHrHrIr+sc@seZdZddZdS)r,cCs|j}|jdd\}}|jdd\}}t|}|jdrvtj|}|dd}n|sd}ntjd|t|f}t	t
j|||S)	N:rMrz;base64ztext/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
i)rkr0rendswithrdecodebytesrrr[rioBytesIO)r{rrDrrEZ	mediatyper`rHrHrI	data_opens
			zDataHandler.data_openN)rrrrrHrHrHrIr,srnt)r3r2cCs
t|S)zOS-specific conversion from a relative URL of the 'file' scheme
        to a file system path; not recommended for general use.)r
)pathnamerHrHrIr3scCs
t|S)zOS-specific conversion from a file system path to a relative URL
        of the 'file' scheme; not recommended for general use.)r	)rrHrHrIr2sc@s4eZdZdZdZdeZdddZddZdd	Z	d
dZ
dd
ZdddZdddZ
dddZdddddZddZdddZdddZddZerddZdd d!Znd"d#Zd$d%Zd&d'Zdd(d)ZdS)*r7a,Class to open URLs.
    This is a class rather than just a subroutine because we may need
    more than one set of global protocol-specific options.
    Note -- this is a base class for those who don't want the
    automatic handling of errors type 302 (relocated) and 401
    (authorization needed).NzPython-urllib/%scKsdi|jjd6}tj|tdd|dkrEt}nt|ds`td||_|j	d|_
|j	d|_d	|jfg|_
g|_tj|_d|_t|_dS)
NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsclass
stacklevelr9rzproxies must be a mappingkey_file	cert_filez
User-Agent)	__class__rr4r5DeprecationWarningr4rrrrrrversionr_URLopener__tempfilesrRrg_URLopener__unlink	tempcacheftpcache)r{rZx509rrHrHrIr~s			zURLopener.__init__cCs|jdS)N)r)r{rHrHrI__del__%szURLopener.__del__cCs|jdS)N)cleanup)r{rHrHrIr(szURLopener.closecCss|jrVx7|jD],}y|j|Wqtk
r>YqXqW|jdd=n|jro|jjndS)N)rrrhrr)r{rJrHrHrIr+s	
		zURLopener.cleanupcGs|jj|dS)zdAdd a header to be used by the HTTP interface only
        e.g. u.addheader('Accept', 'sound/basic')N)rrX)r{rrHrHrI	addheader9szURLopener.addheadercCstt|}t|dd}|jrn||jkrn|j|\}}t|d}t|||St|\}}|sd}n||jkr|j|}t|\}}	t|	\}
}|
|f}nd}d|}||_	|j
dd}t||sD|r1|j|||S|j
||Sny9|dkrft|||St||||SWnattfk
rYnGtk
r}
z'td	|
jtjd
WYdd}
~
XnXdS)z6Use URLopener().open(file) instead of open(file, 'r').safez%/:=&?~#+!$,;'@()*[]|rrJNZopen_-rzsocket errorr)rrr	rrCrrrrrrropen_unknown_proxyopen_unknownrrrrhrrr)r{rrEr]r`r_urltyperDr	proxyhostrqrrVrrHrHrIrC?s<	

	zURLopener.opencCs(t|\}}tdd|dS)z/Overridable interface to open unknown URL type.z	url errorzunknown url typeN)rrh)r{rrErrDrHrHrIrcszURLopener.open_unknowncCs,t|\}}tdd||dS)z/Overridable interface to open unknown URL type.z	url errorzinvalid proxy for %sN)rrh)r{rrrErrDrHrHrIrhszURLopener.open_unknown_proxyc Cstt|}|jr5||jkr5|j|St|\}}|dkr|sf|dkryC|j|}|j}|jtt|d|fSWqt	k
r}	zWYdd}	~	XqXn|j
||}z|j}
|r
t
|d}nddl}t|\}
}t|p7d\}
}t|pOd\}}
t
|pgd\}}
tjj|d}|j|\}}|jj|tj|d}z||
f}|jdk	r||j|<nd}d
}d}d}d	|
kr%t|
d
}n|r>||||nx]|j|}|sZPn|t|7}|j||d7}|rA||||qAqAWWd|jXWd|jX|dkr||krtd||f|n|S)ztretrieve(url) returns (filename, headers) for a local object
        or (tempfilename, headers) for a remote object.NrJrMrKrriirLzcontent-lengthzContent-Lengthz1retrieval incomplete: got only %i out of %i bytesi rN)rrrrrrQrr3rrhrCrUrrrRrSsplitextZmkstemprrXfdopenrYrZr[r\r)r{rDr]r^rErZurl1r_rrr`rarUZgarbagerSsuffixfdrbrcrdrZrerfrHrHrIretrievensl


zURLopener.retrievecCsd}d}t|tr]t|\}}|rTt|\}}t|}n|}n|\}}t|\}}t|\}	}
|
}d}|	jdkrd}n^t|
\}}
|rt|\}}n|rd|	||
f}nt|r|}n|s*tddn|r]t|}t	j
|jjd}nd}|rt|}t	j
|jjd}nd}||}
i}|rd||d<n|rd||d	<n|r||d
<nd|d<x!|j
D]\}}|||<qW|dk	rLd
|d<|
jd|||n|
jd|d|y|
j}Wn$tjjk
rtdYnXd|jkodknrt||jd||jS|j||j|j|j|j|SdS)aMake an HTTP connection using connection_class.

        This is an internal method that should be called from
        open_http() or open_https().

        Arguments:
        - connection_factory should take a host name and return an
          HTTPConnection instance.
        - url is the url to retrieval or a host, relative-path pair.
        - data is payload for a POST request or None.
        Nrz	%s://%s%sz
http errorz
no host givenrzBasic %szProxy-AuthorizationrArjrrqz!application/x-www-form-urlencodedzContent-Typerrr`z$http protocol error: bad status lineri,zhttp:)rrrrr
rrorrhrrrrrrprsrrZ
BadStatusLinerZstatusrr
http_errorr_rt)r{Zconnection_factoryrDrEZuser_passwdZproxy_passwdrqrZrealhostrrZ
proxy_authr=Z	http_connr`headerr}rrHrHrI_open_generic_httpsr
			!!



	zURLopener._open_generic_httpcCs|jtjj||S)zUse HTTP protocol.)rrrrv)r{rDrErHrHrI	open_httpszURLopener.open_httpc
Csd|}t||rwt||}|dkrO||||||}	n|||||||}	|	rw|	Sn|j|||||S)zHandle http errors.

        Derived class can override this, or provide specific handlers
        named http_error_DDD where DDD is the 3-digit error code.z
http_error_%dN)rrr)
r{rDr_errcodeerrmsgr`rErVrzrbrHrHrIrs
zURLopener.http_errorcCs&|jt||||ddS)z>Default error handler: close the connection and raise OSError.N)rr)r{rDr_rrr`rHrHrIr s
zURLopener.http_error_defaultcCs"tjj|d|jd|jS)Nrr)rrrrr)r{rqrHrHrI_https_connection&s	zURLopener._https_connectioncCs|j|j||S)zUse HTTPS protocol.)rr)r{rDrErHrHrI
open_https+szURLopener.open_httpscCst|tstdn|dddkru|dddkru|ddjdkrutd	n
|j|SdS)
z/Use local file or FTP depending on form of URL.zEfile error: proxy support for file protocol currently not implementedNrz//r9rz
localhost/z-file:// scheme is supported only on localhost)rrrror>r)r{rDrHrHrI	open_file/s
HzURLopener.open_filecCsddl}ddl}t|\}}t|}ytj|}Wn:tk
r}zt|j|j	WYdd}~XnX|j
}	|jj|j
dd}
|j|d}|jd|pd|	|
f}|s'|}
|dddkrd	|}
ntt|d
||
St|\}}|rtj|tftkr|}
|dddkrd	|}
n)|dddkrtd
|ntt|d
||
StddS)zUse local file.rNrTz6Content-Type: %s
Content-Length: %d
Last-modified: %s
z
text/plainrMrzfile://rrz./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)rrrr3rRrrhrstrerrorr]rrrrrrrrCr
rrrthishostr>)r{rDrrrqrJZ	localnamererdrrr`Zurlfiler(rHrHrIr8s:(	
"
zURLopener.open_local_filecCst|tstdnddl}t|\}}|sQtdnt|\}}t|\}}|rt|\}}nd}t|}t|pd}t|pd}t	j
|}|sddl}|j}nt
|}t|\}}	t|}|jd}
|
dd|
d}
}|
rk|
drk|
dd}
n|
r|
drd|
d<n|||dj|
f}t|jtkrxJt|jD]6}
|
|kr|j|
}|j|
=|jqqWny9||jkr:t|||||
|j|<n|sId}nd	}xM|	D]E}t|\}}|jd
krV|dkrV|j}qVqVW|j|j||\}}|jd|d}d}|r|d|7}n|dk	r|dkr|d|7}ntj|}t||d|SWnKtk
r}z(td|j t!j"dWYdd}~XnXdS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNzftp error: no host givenrirrMrr@rrrrrezftp:zContent-Type: %s
zContent-Length: %d
zftp error %rrrNrN)rrrr@rer)#rrrrrr
rrr
rrrrrYrr0rr[rMAXFTPCACHErrrrrorrrrrr	ftperrorsrrr)r{rDrrqrSr(rrrrrrJr|rrrrr}r_rrr`rrHrHrIopen_ftpXsp


"	
zURLopener.open_ftpc	Cst|tstdny|jdd\}}Wn!tk
r]tddYnX|smd}n|jd}|dkrd	||d
kr||dd
}|d
|}nd}g}|jdtj	d
tj
tj|jd||dkr>tj|j
djd}nt|}|jdt||jd|j|dj|}tj|}tj|}t|||S)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedrrMz
data errorzbad data URLztext/plain;charset=US-ASCII;rrNrizDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srrzlatin-1zContent-Length: %d
)rrrr0r>rhrfindrXrQZstrftimeZgmtimerrrrr
r[rrrrStringIOr)	r{rDrErZsemiencodingrr`frHrHrI	open_datas6
	"$

zURLopener.open_data)rrrrrrrr~rrrrrCrrrrrrrr?rrrrrrrHrHrHrIr7s.
$B\	 :c@seZdZdZddZddZdddZd	d
ZdddZdd
dZ	dddZ
ddddZddddZdddZ
dddZdddZdddZddd Zd!d"ZdS)#r8z?Derived class with handlers for errors we can handle (perhaps).cOs2tj|||i|_d|_d|_dS)Nrr)r7r~
auth_cachetriesmaxtries)r{rkwargsrHrHrIr~s		zFancyURLopener.__init__cCst||d||S)z3Default error handling -- don't raise an exception.zhttp:)r)r{rDr_rrr`rHrHrIrsz!FancyURLopener.http_error_defaultNc	Cs|jd7_|jrm|j|jkrmt|drE|j}n	|j}d|_|||dd|S|j||||||}d|_|S)z%Error 302 -- relocated (temporarily).rMhttp_error_500riz)Internal Server Error: Redirect Recursion)rrrrrredirect_internal)	r{rDr_rrr`rErrbrHrHrIrs		
		zFancyURLopener.http_error_302c	Csd|kr|d}nd|kr2|d}ndS|jt|jd||}t|}|jd	krt|||d|||n|j|S)
Nrrrrrrriz( Redirection to url '%s' is not allowed.)zhttpzhttpszftpri)rrrrrrrC)	r{rDr_rrr`rErrrHrHrIrs


	z FancyURLopener.redirect_internalcCs|j||||||S)z*Error 301 -- also relocated (permanently).)r)r{rDr_rrr`rErHrHrIrszFancyURLopener.http_error_301cCs|j||||||S)z;Error 303 -- also relocated (essentially identical to 302).)r)r{rDr_rrr`rErHrHrIrszFancyURLopener.http_error_303cCsE|dkr(|j||||||S|j|||||SdS)z1Error 307 -- relocated, but turn POST into error.N)rr)r{rDr_rrr`rErHrHrIrszFancyURLopener.http_error_307Fc
Cs$d|kr+tj||||||n|d}tjd|}	|	sltj||||||n|	j\}
}|
jdkrtj||||||n|stj||||||nd|jd}|dkrt||||St|||||SdS)z_Error 401 -- authentication required.
        This function supports Basic authentication only.zwww-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r-Zretry__basic_authN)r7rr>matchr3rorr)
r{rDr_rrr`rErfstuffrrr!rVrHrHrIrBs&

zFancyURLopener.http_error_401c
Cs$d|kr+tj||||||n|d}tjd|}	|	sltj||||||n|	j\}
}|
jdkrtj||||||n|stj||||||nd|jd}|dkrt||||St|||||SdS)zeError 407 -- proxy authentication required.
        This function supports Basic authentication only.zproxy-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r-Zretry_proxy_rN)r7rr>rr3rorr)
r{rDr_rrr`rErfrrrr!rVrHrHrIrCs&

zFancyURLopener.http_error_407cCst|\}}d||}|jd}t|\}}	t|	\}	}
|	jdd}|	|d}	|j|	||\}}
|p|
sdSdt|ddt|
dd|	f}	d|	|
|jd<|dkr|j|S|j||SdS)Nzhttp://r@rMz%s:%s@%srri)rrrrget_user_passwdr	rC)r{rDr!rErqrrrrr
proxyselectorrrrrHrHrIretry_proxy_http_basic_auth6s 

z*FancyURLopener.retry_proxy_http_basic_authcCst|\}}d||}|jd}t|\}}	t|	\}	}
|	jdd}|	|d}	|j|	||\}}
|p|
sdSdt|ddt|
dd|	f}	d|	|
|jd<|dkr|j|S|j||SdS)Nzhttps://rrrMz%s:%s@%srri)rrrrrr	rC)r{rDr!rErqrrrrrr	rrrrHrHrIretry_proxy_https_basic_authHs 

z+FancyURLopener.retry_proxy_https_basic_authc
Cst|\}}|jdd}||d}|j|||\}}|pY|s`dSdt|ddt|dd|f}d||}	|dkr|j|	S|j|	|SdS)NrrMz%s:%s@%srrizhttp://)rrrr	rC)
r{rDr!rErqrrrrrrHrHrIr7Zs
z$FancyURLopener.retry_http_basic_authc
Cst|\}}|jdd}||d}|j|||\}}|pY|s`dSdt|ddt|dd|f}d||}	|dkr|j|	S|j|	|SdS)NrrMz%s:%s@%srrizhttps://)rrrr	rC)
r{rDr!rErqrrrrrrHrHrIretry_https_basic_authhs
z%FancyURLopener.retry_https_basic_authrcCs|d|j}||jkrD|r6|j|=qD|j|Sn|j||\}}|sh|r~||f|j|<n||fS)Nr)rorprompt_user_passwd)r{rqr!rr|rrrHrHrIrvs
zFancyURLopener.get_user_passwdcCspddl}y@td||f}|jd|||f}||fSWntk
rktdSYnXdS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: )NN)getpassinputKeyboardInterruptprint)r{rqr!rrrrHrHrIr
s	
z!FancyURLopener.prompt_user_passwd)rrrrr~rrrrrrrBrCr
rr7rrr
rHrHrHrIr8s$cCs"tdkrtjdantS)z8Return the IP address of the magic hostname 'localhost'.Nr)
_localhostrrrHrHrHrIrsrcCsgtdkrcy#ttjtjdaWqctjk
r_ttjddaYqcXntS)z,Return the IP addresses of the current host.Nrr)	_thishostr rrrrrHrHrHrIrs#!rcCs(tdkr$ddl}|jantS)z1Return the set of errors raised by the FTP class.Nr)
_ftperrorsrr)rrHrHrIrsrcCs"tdkrtjdantS)z%Return an empty email Message object.Nri)
_noheadersrrrHrHrHrI	noheaderssrc@speZdZdZddddZddZdd	Zd
dZdd
ZddZ	ddZ
dS)rz;Class used by open_ftp() for cache of open FTP connections.NTc	Csr||_||_||_||_||_||_d|_||_y|jWn|j	YnXdS)Nr)
rrrqr(rrFrefcount	keepaliveinitr)r{rrrqr(rrFrrHrHrIr~s								
zftpwrapper.__init__cCsddl}d|_|j|_|jj|j|j|j|jj|j	|j
dj|j}|jj
|dS)Nrr)rbusyZFTPrZconnectrqr(rFZloginrrrrcwd)r{rZ_targetrHrHrIrs	zftpwrapper.initc-Cs:ddl}|j|dkr1d}d}nd|}d}y|jj|Wn/|jk
r|j|jj|YnXd}|r0|r0y&d|}|jj|\}}Wq0|jk
r,}zGt|ddd	krt	d
|j
tjdnWYdd}~Xq0Xn|s|jjd|r|jj
}	zVy|jj|Wn;|jk
r}zt	d
||WYdd}~XnXWd|jj|	Xd|}nd
}|jj|\}}nd|_t|jd|j}
|jd7_|j|
|fS)NrrerzTYPE ArMzTYPE zRETR r9Z550z
ftp error: %rrzLIST ZLISTr)rer)rendtransferrZvoidcmdrrZntransfercmdZ
error_permrrrrrpwdrrrmakefile
file_closerr)r{rJrrcmdisdirrrrtrZftpobjrHrHrIrsN
	



,*
	
zftpwrapper.retrfilecCs
d|_dS)Nr)r)r{rHrHrIr	szftpwrapper.endtransfercCs)d|_|jdkr%|jndS)NFr)rr
real_close)r{rHrHrIr	s	zftpwrapper.closecCsC|j|jd8_|jdkr?|jr?|jndS)NrMr)rrrr")r{rHrHrIr	s
zftpwrapper.file_closecCs7|jy|jjWntk
r2YnXdS)N)rrrr)r{rHrHrIr"	s

zftpwrapper.real_close)rrrrr~rrrrrr"rHrHrHrIrs	-rcCsi}x\tjjD]K\}}|j}|r|dddkr|||dd<qqWdtjkr|jddn|S)aReturn a dictionary of scheme -> proxy server URL mappings.

    Scan the environment for variables named <scheme>_proxy;
    this seems to be the standard convention.  If you need a
    different way, you can pass a proxies dictionary to the
    [Fancy]URLopener constructor.

    N_proxyZREQUEST_METHODrii)rRenvironrvror)rrVr}rHrHrIgetproxies_environment	s	r&cCstjjddp'tjjdd}|dkr:dSt|\}}dd|jdD}x6|D].}|ro|j|s|j|rodSqoWd	S)
zTest if proxies should not be used for a particular host.

    Checks the environment for a variable named no_proxy, which should
    be a list of DNS suffixes separated by commas, or '*' for all hosts.
    no_proxyriZNO_PROXY*rMcSsg|]}|jqSrH)r)rrrHrHrIr:	s	z,proxy_bypass_environment.<locals>.<listcomp>rr)rRr%rr
r0r)rqr'hostonlyr(Z
no_proxy_listrVrHrHrIproxy_bypass_environment-	s*
$r*c
Csddlm}t|\}}dd}d|krK|drKdSnd}x+|jd	fD]}|svqdntjd
|}|dk	rh|dkrytj|}||}Wqtk
rwdYqXn||jd}	|jd}
|
dkr-d
|jdj	dd}
nt
|
dd}
d|
}
||
?|	|
?kr{dSqd|||rddSqdWdS)aj
    Return True iff this host shouldn't be accessed using a proxy

    This function uses the MacOSX framework SystemConfiguration
    to fetch the proxy information.

    proxy_settings come from _scproxy._get_proxy_settings or get mocked ie:
    { 'exclude_simple': bool,
      'exceptions': ['foo.bar', '*.bar.com', '127.0.0.1', '10.1', '10.0/16']
    }
    r)fnmatchcSs|jd}ttt|}t|dkrY|ddddgdd}n|dd>|dd>B|dd>B|d	BS)
N.rrrMrPrrLr9)r0rrrYr[)ZipAddrr'rHrHrIip2numT	s
#z,_proxy_bypass_macosx_sysconf.<locals>.ip2numr,Zexclude_simpleTN
exceptionsz(\d+(?:\.\d+)*)(/\d+)?rMrrL F)r+r
rr>rrrrhgroupcountrY)rqproxy_settingsr+r)r(r.ZhostIPr}rr+maskrHrHrI_proxy_bypass_macosx_sysconfD	s:

#
r5darwin)_get_proxy_settings_get_proxiescCst}t||S)N)r7r5)rqr3rHrHrIproxy_bypass_macosx_sysconf	s	r9cCstS)zReturn a dictionary of scheme -> proxy server URL mappings.

        This function uses the MacOSX framework SystemConfiguration
        to fetch the proxy information.
        )r8rHrHrHrIgetproxies_macosx_sysconf	sr:cCs!trt|St|SdS)N)r&r*r9)rqrHrHrIr	s	
rcCstptS)N)r&r:rHrHrHrIr4	scCsli}yddl}Wntk
r.|SYnXy|j|jd}|j|dd}|r?t|j|dd}d|krx|jdD]M}|jdd\}}tjd	|sd
||f}n|||<qWq?|dddkr||d
<q?d||d
<d||d<d||d<n|j	Wnt
ttfk
rgYnX|S)zxReturn a dictionary of scheme -> proxy server URL mappings.

        Win32 uses the registry to store proxies.

        rNz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableZProxyServerrrrMz^([^/:]+)://z%s://%srHzhttp:rz	http://%sz
https://%srzftp://%sr)
winregImportErrorOpenKeyHKEY_CURRENT_USERQueryValueExrr0r>rZCloserhr>r)rr<internetSettingsproxyEnableZproxyServerprZaddressrHrHrIgetproxies_registry	s8
			

rDcCstptS)zReturn a dictionary of scheme -> proxy server URL mappings.

        Returns settings gathered from the environment, if specified,
        or the registry.

        )r&rDrHrHrHrIr4	sc&Csyddl}Wntk
r(dSYnXyK|j|jd}|j|dd}t|j|dd}Wntk
rdSYnX|s|rdSt|\}}|g}y/tj	|}||kr|j
|nWntk
rYnXy/tj|}||kr,|j
|nWntk
rAYnX|jd}x|D]}	|	dkr}d|kr}dSn|	j
dd	}	|	j
d
d}	|	j
dd}	x*|D]"}
tj|	|
tjrdSqWqXWdS)
Nrz;Software\Microsoft\Windows\CurrentVersion\Internet Settingsr;Z
ProxyOverriderz<local>r,rMz\.r(z.*?)r<r=r>r?r@rrhr
rrrXZgetfqdnr0rr>rr@)rqr<rArBZ
proxyOverrideZrawHostr(ZaddrZfqdnr,rrHrHrIproxy_bypass_registry	sR
			

		



rFcCs!trt|St|SdS)zReturn a dictionary of scheme -> proxy server URL mappings.

        Returns settings gathered from the environment, if specified,
        or the registry.

        N)r&r*rF)rqrHrHrIr
s	
)}rrrrrSZhttp.clientrrrRr)r>rrrQrmrUrOr4Zurllib.errorrrrZurllib.parserrrrr	r
rrr
rrrrrrrrrZurllib.responserrr@r=r?__all__rrrBrr/r0rWr5r6r?ASCIIrmrrrrr1rr.rrr
rr r!r"r#r$urandomrRr%r&r'rgr(rrrArXrr-rJrLr)rr*r+r,rrVZ
nturl2pathr3r2rr7r8rrrrrrrrrr&r*r5platformZ_scproxyr7r8r9r:rr4rDrFrHrHrHrI<module>Dsv
					!?n$h*@
7	q

+4:5!

_<
-	2