File "request.cpython-37.pyc"

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

B

 f!@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+yddl,Z,Wne-k
rdZ.YnXdZ.dd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(g!Z/d)e
j0dd*Z1da2dej3fddddd+d,dZ4d-d Z5gZ6d~d.d%Z7d/d&Z8e
9d0e
j:Z;d1d2Z<Gd3ddZ=Gd4d	d	Z>d5d!Z?Gd6d
d
Z@Gd7dde@ZAGd8dde@ZBGd9dde@ZCd:d;ZDGd<dde@ZEGd=ddZFGd>ddeFZGGd?ddeGZHGd@ddZIGdAddeIe@ZJGdBddeIe@ZKejLZMGdCddZNGdDdde@eNZOGdEdde@eNZPGdFdGdGe@ZQGdHddeQZReSejTdIr*GdJdKdKeQZUe/VdKGdLd
d
e@ZWGdMdde@ZXdNdOZYdPdQZZGdRdde@Z[dSdTZ\GdUdde@Z]GdVdde]Z^GdWdde@Z_dXZ`ejadYkrddZlbmcZcmdZdnd[d#Zcd\d"ZdiZeGd]d'd'ZfGd^d(d(efZgdahd_d`ZidajdadbZkdaldcddZmdandedfZoGdgdhdhZpdidjZqddkdlZrdmdnZse
jtdokrddplumvZvmwZwdqdrZxdsdtZydudvZzdwd$Z{n6ejadYkrdxdyZ|dzd$Z{d{d|Z}d}dvZzneqZ{erZzdS)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ProxyHandlerHTTPPasswordMgrHTTPPasswordMgrWithDefaultRealmHTTPPasswordMgrWithPriorAuthAbstractBasicAuthHandlerHTTPBasicAuthHandlerProxyBasicAuthHandlerAbstractDigestAuthHandlerHTTPDigestAuthHandlerProxyDigestAuthHandlerHTTPHandlerFileHandler
FTPHandlerCacheFTPHandlerDataHandlerUnknownHandlerHTTPErrorProcessorurlopeninstall_openerbuild_openerpathname2urlurl2pathname
getproxiesurlretrieve
urlcleanup	URLopenerFancyURLopenerz%d.%d)cafilecapath	cadefaultcontextc
Cs|s|s|rfddl}|dtd|dk	r2tdts>tdtjtjj||d}t	|d}t
|}	n0|r~t	|d}t
|}	ntdkrt
a}	nt}	|	|||S)	a$
Open the URL url, which can be either a string or a Request object.

    *data* must be an object specifying additional data to be sent to
    the server, or None if no such data is needed.  See Request for
    details.

    urllib.request module uses HTTP/1.1 and includes a "Connection:close"
    header in its HTTP requests.

    The optional *timeout* parameter specifies a timeout in seconds for
    blocking operations like the connection attempt (if not specified, the
    global default timeout setting will be used). This only works for HTTP,
    HTTPS and FTP connections.

    If *context* is specified, it must be a ssl.SSLContext instance describing
    the various SSL options. See HTTPSConnection for more details.

    The optional *cafile* and *capath* parameters specify a set of trusted CA
    certificates for HTTPS requests. cafile should point to a single file
    containing a bundle of CA certificates, whereas capath should point to a
    directory of hashed certificate files. More information can be found in
    ssl.SSLContext.load_verify_locations().

    The *cadefault* parameter is ignored.

    This function always returns an object which can work as a context
    manager and has methods such as

    * geturl() - return the URL of the resource retrieved, commonly used to
      determine if a redirect was followed

    * info() - return the meta-information of the page, such as headers, in the
      form of an email.message_from_string() instance (see Quick Reference to
      HTTP Headers)

    * getcode() - return the HTTP status code of the response.  Raises URLError
      on errors.

    For HTTP and HTTPS URLs, this function returns a http.client.HTTPResponse
    object slightly modified. In addition to the three new methods above, the
    msg attribute contains the same information as the reason attribute ---
    the reason phrase returned by the server --- instead of the response
    headers as it is specified in the documentation for HTTPResponse.

    For FTP, file, and data URLs and requests explicitly handled by legacy
    URLopener and FancyURLopener classes, this function returns a
    urllib.response.addinfourl object.

    Note that None may be returned if no handler handles the request (though
    the default installed global OpenerDirector uses UnknownHandler to ensure
    this never happens).

    In addition, if proxy settings are detected (for example, when a *_proxy
    environment variable like http_proxy is set), ProxyHandler is default
    installed and makes sure the requests are handled through the proxy.

    rNzJcafile, 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>)
warningswarnDeprecationWarning
ValueError	_have_sslsslZcreate_default_contextZPurposeZSERVER_AUTHHTTPSHandlerr2_openeropen)
urldatatimeoutr;r<r=r>r?Z
https_handleropenerrL3/opt/alt/python37/lib64/python3.7/urllib/request.pyr0s*<




cCs|adS)N)rF)rKrLrLrMr1sc
Cs2t|\}}tt||}|}|dkrB|sBtj||fS|rRt|d}nt	j
dd}|j}t
||||f}	d}
d}d}d}
d|krt|d	}|r||
|
|xB||
}|sP|t|7}|||
d
7}
|r||
|
|qWWdQRXWdQRX|dkr.||kr.td||f|	|	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.
    filewbF)deletei rzcontent-lengthzContent-LengthNz1retrieval incomplete: got only %i out of %i bytes)r
contextlibclosingr0infoospathnormpathrGtempfileZNamedTemporaryFilename_url_tempfilesappendintreadlenwriter)rHfilename
reporthookrIZurl_typerWfpheaderstfpresultbssizer^blocknumblockrLrLrMr6sD


$c	CsHx0tD](}yt|Wqtk
r,YqXqWtdd=trDdadS)z0Clean up temporary files from urlretrieve calls.N)r[rVunlinkOSErrorrF)Z	temp_filerLrLrMr7$s


z:\d+$cCs<|j}t|d}|dkr&|dd}td|d}|S)zReturn request-host, as defined by RFC 2965.

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

    rRHost)full_urlr
get_header_cut_port_resublower)requestrHhostrLrLrMrequest_host3srvc@seZdZdidddfddZeddZejddZejddZed	d
Zejdd
Zejdd
Zd
dZ	ddZ
ddZddZddZ
ddZddZddZd#ddZdd Zd!d"ZdS)$rNFc	Csp||_i|_i|_d|_||_d|_x |D]\}}|||q.W|dkrVt|}||_	||_
|rl||_dS)N)rordunredirected_hdrs_datarI_tunnel_hostitems
add_headerrvorigin_req_hostunverifiablemethod)	selfrHrIrdr|r}r~keyvaluerLrLrM__init__EszRequest.__init__cCs|jrd|j|jS|jS)Nz{}#{})fragmentformat	_full_url)rrLrLrMroWszRequest.full_urlcCs(t||_t|j\|_|_|dS)N)rrrr_parse)rrHrLrLrMro]s
cCsd|_d|_d|_dS)Nrm)rrselector)rrLrLrMrodscCs|jS)N)rx)rrLrLrMrIjszRequest.datacCs(||jkr$||_|dr$|ddS)NzContent-length)rx
has_header
remove_header)rrIrLrLrMrIns

cCs
d|_dS)N)rI)rrLrLrMrIxscCsNt|j\|_}|jdkr(td|jt|\|_|_|jrJt|j|_dS)Nzunknown url type: %r)	rrtyperBrorrurr
)rrestrLrLrMr|s
zRequest._parsecCs|jdk	rdnd}t|d|S)z3Return a string indicating the HTTP request method.NPOSTGETr~)rIgetattr)rZdefault_methodrLrLrM
get_methodszRequest.get_methodcCs|jS)N)ro)rrLrLrMget_full_urlszRequest.get_full_urlcCs2|jdkr|js|j|_n||_|j|_||_dS)Nhttps)rryruror)rrurrLrLrM	set_proxys

zRequest.set_proxycCs|j|jkS)N)rro)rrLrLrM	has_proxyszRequest.has_proxycCs||j|<dS)N)rd
capitalize)rrvalrLrLrMr{szRequest.add_headercCs||j|<dS)N)rwr)rrrrLrLrMadd_unredirected_headerszRequest.add_unredirected_headercCs||jkp||jkS)N)rdrw)rheader_namerLrLrMrs
zRequest.has_headercCs|j||j||S)N)rdgetrw)rrdefaultrLrLrMrpszRequest.get_headercCs |j|d|j|ddS)N)rdpoprw)rrrLrLrMrszRequest.remove_headercCs"|j}||jt|S)N)rwcopyupdaterdlistrz)rhdrsrLrLrMheader_itemss
zRequest.header_items)N)__name__
__module____qualname__rpropertyrosetterdeleterrIrrrrrr{rrrprrrLrLrLrMrCs(

c@sNeZdZddZddZddZddZd	ejfd
dZ	ddd
Z
ddZd	S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NzPython-urllib/%sz
User-agent)__version__
addheadershandlershandle_openhandle_errorprocess_responseprocess_request)rZclient_versionrLrLrMrszOpenerDirector.__init__c	CsZt|dstdt|d}xt|D]}|dkr:q*|d}|d|}||dd}|dr|d|d}||dd}yt|}Wntk
rYnX|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_requestdo_open
proxy_open_rRerrorrGresponsertT)hasattr	TypeErrorrdirfind
startswithr]rBrrrrr
setdefaultbisectZinsortr\rr)rhandlerZaddedmethiprotocolZ	conditionjkindlookuprrLrLrMadd_handlersJ



zOpenerDirector.add_handlercCsdS)NrL)rrLrLrMcloseszOpenerDirector.closec	Gs<||d}x*|D]"}t||}||}|dk	r|SqWdS)NrL)rr)	rchainr	meth_nameargsrrfuncrfrLrLrM_call_chains

zOpenerDirector._call_chainNc
Cst|trt||}n|}|dk	r(||_||_|j}|d}x(|j|gD]}t||}||}qLW|	||}	|d}x*|j
|gD]}t||}|||	}	qW|	S)NZ_requestZ	_response)
isinstancestrrrIrJrrrr_openr)
rfullurlrIrJreqrrZ	processorrrrLrLrMrGs"


zOpenerDirector.opencCsP||jdd|}|r|S|j}||j||d|}|r>|S||jdd|S)NrZdefault_openrunknownunknown_open)rrr)rrrIrfrrLrLrMrs


zOpenerDirector._opencGs~|dkr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|}|r^|S|rz|dd	f|}|j|SdS)
N)httprrr:z
http_error_%srRZ_errorrrhttp_error_default)rr)rprotordictrZhttp_errZ	orig_argsrfrLrLrMr&s 

zOpenerDirector.error)N)rrrrrrrsocket_GLOBAL_DEFAULT_TIMEOUTrGrrrLrLrLrMrs/
c	Gst}ttttttttt	g	}t
tjdr2|
tt}xN|D]F}x@|D]8}t|trlt||r||qHt||rH||qHWq>Wx|D]}||qWx|D]}||qWx&|D]}t|tr|}||qW|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-rrclientr\rEsetrr
issubclassaddremover)rrKZdefault_classesskipklassZcheckhrLrLrMr2?s0	









c@s(eZdZdZddZddZddZdS)	ricCs
||_dS)N)parent)rrrLrLrMrfszBaseHandler.add_parentcCsdS)NrL)rrLrLrMriszBaseHandler.closecCst|dsdS|j|jkS)N
handler_orderT)rr)rotherrLrLrM__lt__ms
zBaseHandler.__lt__N)rrrrrrrrLrLrLrMrcsc@s eZdZdZdZddZeZdS)r/zProcess HTTP error responses.icCsH|j|j|}}}d|kr,dksDn|jd|||||}|S)Ni,r)codemsgrUrr)rrtrrrrrLrLrM
http_responsezs
z HTTPErrorProcessor.http_responseN)rrr__doc__rrhttps_responserLrLrLrMr/vsc@seZdZddZdS)rcCst|j||||dS)N)rro)rrrcrrrrLrLrMrsz*HTTPDefaultErrorHandler.http_error_defaultN)rrrrrLrLrLrMrsc@s4eZdZdZdZddZddZeZZZ	dZ
dS)	r
c	st|}|dkr|dks:|dkr(|dks:t|j|||||dd}dfdd	|jD}t|||jd
dS)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.
        )i-i.i/i3)rZHEAD)i-i.i/r z%20)zcontent-lengthzcontent-typecs"i|]\}}|kr||qSrL)rs).0kv)CONTENT_HEADERSrLrM
<dictcomp>sz8HTTPRedirectHandler.redirect_request.<locals>.<dictcomp>T)rdr|r})rrroreplacerdrzrr|)	rrrcrrrdnewurlmZ
newheadersrL)rrMrs
z$HTTPRedirectHandler.redirect_requestc
CsLd|kr|d}nd|kr$|d}ndSt|}|jdkrRt||d||f|||jsn|jrnt|}d|d<t|}t|dtj	d}t
|j|}|||||||}|dkrdSt
|d	r|j}	|_|	|d
|jkst|	|jkrt|j||j|||ni}	|_|_|	|d
d|	|<|||jj||jdS)
Nlocationuri)rrftprmz+%s - Redirection to url '%s' is not allowed/r:z
iso-8859-1)encodingsafe
redirect_dictrrR)rJ)rschemerrWZnetlocrrr	stringZpunctuationrrorrrrmax_repeatsr_max_redirectionsinf_msgr^rrrGrJ)
rrrcrrrdrurlpartsnewZvisitedrLrLrMhttp_error_302s@



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_307rrLrLrLrMrs&<c	Cst|\}}|ds d}|}n:|ds6td||dd}|dkrNd}|d|}t|\}}|dk	r|t|\}}nd}}||||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: %rr:rQ)rrrBrrr)	proxyrZr_scheme	authorityendZuserinfohostportuserpasswordrLrLrM_parse_proxys

rc@s"eZdZdZdddZddZdS)rdNcCs^|dkrt}t|ds td||_x2|D]&\}}t|d||||jfddq0WdS)Nkeyszproxies must be a mappingz%s_opencSs||||S)NrL)rrrrrLrLrM<lambda>$sz'ProxyHandler.__init__.<locals>.<lambda>)r5rAssertionErrorproxiesrzsetattrr)rrrrHrLrLrMrs
zProxyHandler.__init__cCs|j}t|\}}}}|dkr"|}|jr6t|jr6dS|rv|rvdt|t|f}	t|	d}
|	dd|
t|}|
||||ks|dkrdS|jj||j
dSdS)Nz%s:%sasciizProxy-authorizationzBasic r)rJ)rrruproxy_bypassr
base64	b64encodeencodedecoder{rrrGrJ)rrrrZ	orig_typeZ
proxy_typer
rr	Z	user_passZcredsrLrLrMr's zProxyHandler.proxy_open)N)rrrrrrrLrLrLrMrs

c@s6eZdZddZddZddZd
dd	Zd
dZdS)r cCs
i|_dS)N)passwd)rrLrLrMrEszHTTPPasswordMgr.__init__cs`t|tr|g}|jkr$ij|<x6dD].tfdd|D}||fj||<q*WdS)N)TFc3s|]}|VqdS)N)
reduce_uri)ru)default_portrrLrM	<genexpr>Psz/HTTPPasswordMgr.add_password.<locals>.<genexpr>)rrrtuple)rrealmrr
rreduced_urirL)rrrMadd_passwordHs



zHTTPPasswordMgr.add_passwordc	Cs`|j|i}xLdD]D}|||}x2|D]&\}}x|D]}|||r<|Sq<Wq.WqWdS)N)TF)NN)rrrrz	is_suburi)	rr authuriZdomainsrreduced_authuriZurisZauthinforrLrLrMfind_user_passwordSs

z"HTTPPasswordMgr.find_user_passwordTc
Cst|}|dr.|d}|d}|dp*d}nd}|}d}t|\}}|r~|dkr~|dk	r~ddd|}	|	dk	r~d	||	f}||fS)
z@Accept authority or URI and extract only the authority and path.rRrr:rNPi)rrz%s:%d)rr
r)
rrrpartsrrrWruportZdportrLrLrMr]s zHTTPPasswordMgr.reduce_uricCsN||krdS|d|dkr dS|d}|dddkr@|d7}|d|S)zcCheck if test is below base in a URI tree

        Both args must be URIs in reduced form.
        TrFrRrQNr)r)rbasetestprefixrLrLrMr#tszHTTPPasswordMgr.is_suburiN)T)rrrrr"r&rr#rLrLrLrMr Cs


c@seZdZddZdS)r!cCs0t|||\}}|dk	r"||fSt|d|S)N)r r&)rr r$r
rrLrLrMr&s

z2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)rrrr&rLrLrLrMr!scs<eZdZfddZd
fdd	ZdddZdd	ZZS)r"csi|_tj||dS)N)
authenticatedsuperr)rrkwargs)	__class__rLrMrsz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<||||dk	r&td|||t||||dS)N)update_authenticatedr.r")rr rr
ris_authenticated)r0rLrMr"sz)HTTPPasswordMgrWithPriorAuth.add_passwordcCsFt|tr|g}x0dD](}x"|D]}|||}||j|<q WqWdS)N)TF)rrrr-)rrr2rrr!rLrLrMr1s


z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDx>dD]6}|||}x$|jD]}|||r|j|SqWqWdS)N)TF)rr-r#)rr$rr%rrLrLrMr2s

z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)rrrrr"r1r2
__classcell__rLrL)r0rMr"s

c@sTeZdZedejZdddZddZddZ	d	d
Z
ddZd
dZeZ
eZdS)r#z1(?:^|,)[ 	]*([^ 	,]+)[ 	]+realm=(["']?)([^"']*)\2NcCs"|dkrt}||_|jj|_dS)N)r rr")rZpassword_mgrrLrLrMrsz!AbstractBasicAuthHandler.__init__ccstd}xFtj|D]6}|\}}}|dkr:tdtd||fVd}qW|sp|rb|d}nd}|dfVdS)NF)"'zBasic Auth Realm was unquotedTrrm)r#rxfinditergroupsr?r@UserWarningsplit)rheaderZfound_challengeZmorr	r rLrLrM_parse_realms
z%AbstractBasicAuthHandler._parse_realmc	Cs~||}|sdSd}xL|D]D}x>||D]0\}}|dkrF|}q,|dk	r,||||Sq,WqW|dk	rztd|fdS)NbasiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allr=rsretry_http_basic_authrB)	rauthreqrurrdZunsupportedr<rr rLrLrMhttp_error_auth_reqeds

z.AbstractBasicAuthHandler.http_error_auth_reqedcCs||j||\}}|dk	rtd||f}dt|d}||jd|krTdS||j||j	j
||jdSdSdS)Nz%s:%szBasic r)rJ)rr&rrrrrpauth_headerrrrGrJ)rrurr r
pwrawauthrLrLrMr?sz.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jdr|j|js|S|dsp|jd|j\}}d||}t	|
}|dd||S)Nr2
Authorizationz{0}:{1}zBasic {})
rrr2rorr&rrrZstandard_b64encoderrstrip)rrr
rZcredentialsZauth_strrLrLrMhttp_requests
z%AbstractBasicAuthHandler.http_requestcCsLt|jdrHd|jkr"dkr8nn|j|jdn|j|jd|S)Nr2ri,TF)rrrr1ro)rrrrLrLrMrs
z&AbstractBasicAuthHandler.http_response)N)rrrrecompileIr7rr=rAr?rHr
https_requestrrLrLrLrMr#s

c@seZdZdZddZdS)r$rFcCs|j}|d|||}|S)Nzwww-authenticate)rorA)rrrcrrrdrHrrLrLrMhttp_error_401s
z#HTTPBasicAuthHandler.http_error_401N)rrrrBrMrLrLrLrMr$sc@seZdZdZddZdS)r%zProxy-authorizationcCs|j}|d|||}|S)Nzproxy-authenticate)rurA)rrrcrrrdrrrLrLrMhttp_error_407*s
z$ProxyBasicAuthHandler.http_error_407N)rrrrBrNrLrLrLrMr%&sc@sNeZdZdddZddZddZdd	Zd
dZdd
ZddZ	ddZ
dS)r&NcCs4|dkrt}||_|jj|_d|_d|_d|_dS)Nr)r rr"retriednonce_count
last_nonce)rrrLrLrMrDs
z"AbstractDigestAuthHandler.__init__cCs
d|_dS)Nr)rO)rrLrLrMreset_retry_countMsz+AbstractDigestAuthHandler.reset_retry_countcCs|||d}|jdkr*t|jdd|dn|jd7_|rx|d}|dkr`|||S|dkrxtd|dS)	Nizdigest auth failedrRrZdigestr>zEAbstractDigestAuthHandler does not support the following scheme: '%s')rrOrror;rsretry_http_digest_authrB)rrBrurrdr@rrLrLrMrAPs


z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|dd\}}ttdt|}|||}|rvd|}|j|jd|krRdS||j||j	j
||jd}|SdS)NrrRz	Digest %s)rJ)r;parse_keqv_listfilterparse_http_listget_authorizationrdrrBrrrGrJ)rrrEtokenZ	challengechalZauth_valZresprLrLrMrTdsz0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|tf}|dtd}t|}|ddS)Nz	%s:%s:%s:r)rPtimeZctimer_randombyteshashlibsha1	hexdigest)rnoncesbdigrLrLrM
get_cnoncepsz$AbstractDigestAuthHandler.get_cnoncecCsy6|d}|d}|d}|dd}|dd}Wntk
rJdSX||\}}	|dkrfdS|j||j\}
}|
dkrdS|jdk	r||j|}nd}d|
||f}
d||j	f}|dkr|	||
d|||f}n~d	|
d
krZ||jkr|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)Nr rbqop	algorithmMD5opaquez%s:%s:%sz%s:%srE,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")rKeyErrorget_algorithm_implsrr&rorIget_entity_digestrrr;rQrPrfr)rrrZr rbrgrhrjHKDr
rCZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitr*rLrLrMrX{sV





z+AbstractDigestAuthHandler.get_authorizationcsD|dkrddn|dkr$ddntd|fdd}|fS)NricSst|dS)Nr)r_Zmd5rra)xrLrLrMrz?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSst|dS)Nr)r_r`rra)rqrLrLrMrrrz.Unsupported digest authentication algorithm %rcsd||fS)Nz%s:%srL)rcd)rorLrMrrr)rB)rrhrprL)rorMrms

z-AbstractDigestAuthHandler.get_algorithm_implscCsdS)NrL)rrIrZrLrLrMrnsz+AbstractDigestAuthHandler.get_entity_digest)N)rrrrrRrArTrfrXrmrnrLrLrLrMr&9s
	>
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.
    rFicCs*t|jd}|d|||}||S)NrRzwww-authenticate)rrorArR)rrrcrrrdruretryrLrLrMrMs

z$HTTPDigestAuthHandler.http_error_401N)rrrrrBrrMrLrLrLrMr'sc@seZdZdZdZddZdS)r(zProxy-AuthorizationicCs"|j}|d|||}||S)Nzproxy-authenticate)rurArR)rrrcrrrdrurtrLrLrMrNs

z%ProxyDigestAuthHandler.http_error_407N)rrrrBrrNrLrLrLrMr(sc@s6eZdZd
ddZddZddZdd	Zd
dZdS)AbstractHTTPHandlerrcCs
||_dS)N)_debuglevel)r
debuglevelrLrLrMrszAbstractHTTPHandler.__init__cCs
||_dS)N)rv)rlevelrLrLrMset_http_debuglevelsz'AbstractHTTPHandler.set_http_debuglevelcCstjj|j|S)N)rrHTTPConnection_get_content_lengthrIr)rrtrLrLrMr{sz'AbstractHTTPHandler._get_content_lengthcCs|j}|std|jdk	r|j}t|tr8d}t||dsN|dd|ds|ds||}|dk	r|dt|n|dd|}|	rt
|j\}}t|\}}	|ds|d|x2|j
jD]&\}
}|
}
||
s||
|qW|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)rurrIrrrrrr{rrrrrrr)rrtrurIrZcontent_lengthZsel_hostrZselZsel_pathrZrrLrLrMdo_request_s>







zAbstractHTTPHandler.do_request_c

sT|j}|std||fd|ji|}||jt|jfdd|j	Ddd<dd	D|j
ri}d}|kr|||<|=|j|j
|d	y`y&|j|
|j|j|d
dWn,tk
r}zt|Wdd}~XYnX|}	Wn|YnX|jr>|jd|_||	_|	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 givenrJcsi|]\}}|kr||qSrLrL)rrr)rdrLrMr*sz/AbstractHTTPHandler.do_open.<locals>.<dictcomp>r
ConnectioncSsi|]\}}||qSrL)title)rrZrrLrLrMr7szProxy-Authorization)rdzTransfer-encoding)Zencode_chunkedN)rurrJZset_debuglevelrvrrwrrdrzryZ
set_tunnelrtrrrIrrlgetresponserZsockrrHreasonr)
rZ
http_classrZhttp_conn_argsrurZtunnel_headersZproxy_auth_hdrerrrrL)rdrMrs@


zAbstractHTTPHandler.do_openN)r)rrrrryr{r|rrLrLrLrMrus

&ruc@seZdZddZejZdS)r)cCs|tjj|S)N)rrrrz)rrrLrLrM	http_openaszHTTPHandler.http_openN)rrrrrur|rHrLrLrLrMr)_src@s$eZdZdddZddZejZdS)rErNcCst||||_||_dS)N)rur_context_check_hostname)rrwr>check_hostnamerLrLrMrjszHTTPSHandler.__init__cCs|jtjj||j|jdS)N)r>r)rrrrrr)rrrLrLrM
https_openoszHTTPSHandler.https_open)rNN)rrrrrrur|rLrLrLrLrMrEhs
rEc@s.eZdZdddZddZddZeZeZdS)	rNcCs$ddl}|dkr|j}||_dS)Nr)Zhttp.cookiejar	cookiejarZ	CookieJar)rrrrLrLrMrxs
zHTTPCookieProcessor.__init__cCs|j||S)N)rZadd_cookie_header)rrtrLrLrMrH~sz HTTPCookieProcessor.http_requestcCs|j|||S)N)rZextract_cookies)rrtrrLrLrMrsz!HTTPCookieProcessor.http_response)N)rrrrrHrrLrrLrLrLrMrws

c@seZdZddZdS)r.cCs|j}td|dS)Nzunknown url type: %s)rr)rrrrLrLrMrszUnknownHandler.unknown_openN)rrrrrLrLrLrMr.scCsRi}xH|D]@}|dd\}}|ddkrB|ddkrB|dd}|||<q
W|S)z>Parse list of key=value strings where keys are not duplicated.=rRrr4rQ)r;)lZparsedZeltrrrLrLrMrUs
rUcCsg}d}d}}xt|D]l}|r,||7}d}q|rV|dkr@d}qn|dkrLd}||7}q|dkrn||d}q|dkrzd}||7}qW|r||dd|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.
    rmF\Tr4rkcSsg|]}|qSrL)rG)rpartrLrLrM
<listcomp>sz#parse_http_list.<locals>.<listcomp>)r\)rcZresrescaper	ZcurrLrLrMrWs4	


rWc@s(eZdZddZdZddZddZdS)r*cCs\|j}|dddkrN|dddkrN|jrN|jdkrN|j|krXtdn
||SdS)Nr:z//r6r	localhostz-file:// scheme is supported only on localhost)rru	get_namesropen_local_file)rrrHrLrLrM	file_opens&

zFileHandler.file_openNcCs`tjdkrZy*ttddttdt_Wn$tjk
rXtdft_YnXtjS)Nrr:)r*namesrrgethostbyname_exgethostnamegaierror
gethostbyname)rrLrLrMrs
zFileHandler.get_namesc
Csddl}ddl}|j}|j}t|}yt|}|j}|jj	|j
dd}	||d}
|d|
pbd||	f}|r~t
|\}}|r|st||kr|rd||}
nd|}
tt|d||
SWn*tk
r}zt|Wdd}~XYnXtddS)	NrT)usegmtz6Content-type: %s
Content-length: %d
Last-modified: %s
z
text/plainzfile://rbzfile not on local host)email.utils	mimetypesrurr4rVstatst_sizeutils
formatdatest_mtime
guess_typemessage_from_stringr
_safe_gethostbynamerrrGrlr)rremailrruraZ	localfilestatsrhmodifiedmtyperdr)ZorigurlexprLrLrMrs0
zFileHandler.open_local_file)rrrrrrrrLrLrLrMr*s
cCs&y
t|Stjk
r dSXdS)N)rrr)rurLrLrMrs
rc@seZdZddZddZdS)r+c
Cs,ddl}ddl}|j}|s"tdt|\}}|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|ds|dd}y|||||||j}
|r6dp8d}x:|
D]2}t|\}}|d	kr@|d
kr@|}q@W|
||\}}d}||jd}|r|d|7}|dk	r|dkr|d|7}t|}t|||jS|jk
r&}z"td
|}|t dWdd}~XYnXdS)Nrzftp error: no host givenrmrrQrRrKDr)aArrKrsrzContent-type: %s
zContent-length: %d
z
ftp error: %rr:)!ftplibrrurr
FTP_PORTr]rrr
rrrlrrr;rmapconnect_ftprJrrsupperretrfilerrorrr
all_errorswith_tracebacksysexc_info)rrrrrur)r
rrrWattrsdirsrNfwrattrrrcretrlenrdrrexcrLrLrMftp_opens\



zFTPHandler.ftp_openc	Cst||||||ddS)NF)
persistent)
ftpwrapper)rr
rrur)rrJrLrLrMr2szFTPHandler.connect_ftpN)rrrrrrLrLrLrMr+s5c@s<eZdZddZddZddZddZd	d
ZddZd
S)r,cCs"i|_i|_d|_d|_d|_dS)Nr<r\)cacherJsoonestdelay	max_conns)rrLrLrMr9s
zCacheFTPHandler.__init__cCs
||_dS)N)r)rtrLrLrM
setTimeout@szCacheFTPHandler.setTimeoutcCs
||_dS)N)r)rrrLrLrMsetMaxConnsCszCacheFTPHandler.setMaxConnscCsr|||d||f}||jkr4t|j|j|<n,t|||||||j|<t|j|j|<||j|S)Nr)joinrr]rrJrcheck_cache)rr
rrur)rrJrrLrLrMrFs

zCacheFTPHandler.connect_ftpcCst}|j|krTx@t|jD].\}}||kr"|j||j|=|j|=q"Wtt|j|_t	|j|j
krx6t|jD]$\}}||jkr|j|=|j|=PqWtt|j|_dS)N)r]rrrJrzrrminvaluesr_r)rrrrrLrLrMrQs

zCacheFTPHandler.check_cachecCs4x|jD]}|qW|j|jdS)N)rrrclearrJ)rconnrLrLrMclear_cachees
zCacheFTPHandler.clear_cacheN)	rrrrrrrrrrLrLrLrMr,6sc@seZdZddZdS)r-cCs~|j}|dd\}}|dd\}}t|}|drNt|}|dd}|sVd}td|t|f}t	t
|||S)N:rRrkz;base64iztext/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
)ror;rendswithrdecodebytesrrr_rioBytesIO)rrrHrrIZ	mediatyperdrLrLrM	data_openls


zDataHandler.data_openN)rrrrrLrLrLrMr-ksrnt)r4r3cCst|S)zOS-specific conversion from a relative URL of the 'file' scheme
        to a file system path; not recommended for general use.)r
)pathnamerLrLrMr4scCst|S)zOS-specific conversion from a file system path to a relative URL
        of the 'file' scheme; not recommended for general use.)r	)rrLrLrMr3sc@seZdZdZdZdeZd*ddZddZdd	Z	d
dZ
dd
Zd+ddZd,ddZ
d-ddZd.ddZddZd/ddZd0ddZddZerddZd1d d!Zd"d#Zd$d%Zd&d'Zd2d(d)ZdS)3r8a,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/%scKsdd|jji}tj|tdd|dkr.t}t|ds@td||_|	d|_
|	d|_d	|jfd
g|_
g|_tj|_d|_t|_dS)NzW%(class)s style of invoking requests is deprecated. Use newer urlopen functions/methodsclassr6)
stacklevelrzproxies must be a mappingkey_file	cert_filez
User-Agent)ZAcceptz*/*)r0rr?r@rAr5rrrrrrversionr_URLopener__tempfilesrVrk_URLopener__unlink	tempcacheftpcache)rrZx509rrLrLrMrszURLopener.__init__cCs|dS)N)r)rrLrLrM__del__szURLopener.__del__cCs|dS)N)cleanup)rrLrLrMrszURLopener.closec	CsZ|jrFx2|jD](}y||Wqtk
r4YqXqW|jdd=|jrV|jdS)N)rrrlrr)rrNrLrLrMrs
zURLopener.cleanupcGs|j|dS)zdAdd a header to be used by the HTTP interface only
        e.g. u.addheader('Accept', 'sound/basic')N)rr\)rrrLrLrM	addheaderszURLopener.addheaderc
Csltt|}t|dd}|jrL||jkrL|j|\}}t|d}t|||St|\}}|s`d}||jkr|j|}t|\}}	t|	\}
}|
|f}nd}d|}||_	|
dd}t||r|d	kr|r||||S|
||Sy,|dkrt|||St||||SWnVttfk
r,Yn<tk
rf}
ztd
|
tdWdd}
~
XYnXdS)z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|)rrrNNZopen_-rrzsocket errorr:)rrr	rrGrrrrrrropen_unknown_proxyopen_unknownrrrrlrrr)rrrIrardrcurltyperHr	proxyhostrurrZrrLrLrMrGs<




zURLopener.opencCst|\}}tdd|dS)z/Overridable interface to open unknown URL type.z	url errorzunknown url typeN)rrl)rrrIrrHrLrLrMrszURLopener.open_unknowncCs t|\}}tdd||dS)z/Overridable interface to open unknown URL type.z	url errorzinvalid proxy for %sN)rrl)rrrrIrrHrLrLrMr
szURLopener.open_unknown_proxyc
Cstt|}|jr&||jkr&|j|St|\}}|dkr|rF|dkry.||}|}|tt|d|fSt	k
r}	zWdd}	~	XYnX|
||}z>|}
|rt
|d}nrt|\}}
t|
pd\}}
t|
pd\}
}t|
pd\}
}t
j|
d}t|\}}|j|t
|d}z||
f}|jdk	rR||j|<d}d}d}d}d	|
krxt|
d
}|r||||xH||}|sP|t|7}|||d7}|r||||qWWd|XWd|X|dkr||krtd||f||S)ztretrieve(url) returns (filename, headers) for a local object
        or (tempfilename, headers) for a remote object.NrNrRrOrmi rQrzcontent-lengthzContent-Lengthz1retrieval incomplete: got only %i out of %i bytes)rrrrrrUrr4rrlrGrrrVrWsplitextrYZmkstemprr\fdopenr]r^r_r`r)rrHrarbrIrZurl1rcrrrdreZgarbagerWsuffixfdrfrgrhr^rirjrLrLrMretrievesj






zURLopener.retrievecCs(d}d}t|tr<t|\}}|r6t|\}}t|}|}nt|\}}t|\}}t|\}	}
|
}d}|	dkrvd}n:t|
\}}
|rt|\}}|rd|	||
f}t|r|}|stdd|rt|}t	
|d}nd}|rt|}t	
|d}nd}||}
i}|r*d||d<|r<d||d	<|rJ||d
<d|d<x|j
D]\}}|||<qZW|dk	rd
|d<|
d|||n|
jd||dy|
}Wn"tjjk
rtdYnXd|jkrdkrnnt||jd||jS|||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-AuthorizationrFrnrr}z!application/x-www-form-urlencodedzContent-Typerr)rdz$http protocol error: bad status lineri,zhttp:)rrrrr
rrsrrlrrrrrrtrrrZ
BadStatusLinerZstatusrr
http_errorrcr)rZconnection_factoryrHrIZuser_passwdZproxy_passwdrurZrealhostrrZ
proxy_authrEZ	http_connrdr<rrrLrLrM_open_generic_httpQsr



zURLopener._open_generic_httpcCs|tjj||S)zUse HTTP protocol.)rrrrz)rrHrIrLrLrM	open_httpszURLopener.open_httpc
Csbd|}t||rPt||}|dkr6||||||}	n|||||||}	|	rP|	S||||||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)
rrHrcerrcodeerrmsgrdrIrZr~rfrLrLrMrs

zURLopener.http_errorcCs|t||||ddS)z>Default error handler: close the connection and raise OSError.N)rr)rrHrcrrrdrLrLrMrszURLopener.http_error_defaultcCstjj||j|jdS)N)rr)rrrrr)rrurLrLrM_https_connectionszURLopener._https_connectioncCs||j||S)zUse HTTPS protocol.)rr)rrHrIrLrLrM
open_httpsszURLopener.open_httpscCs^t|tstd|dddkrP|dddkrP|dddkrPtd	n
||SdS)
z/Use local file or FTP depending on form of URL.zEfile error: proxy support for file protocol currently not implementedNr:z//r6rz
localhost/z-file:// scheme is supported only on localhost)rrrrsrBr)rrHrLrLrM	open_files

4
zURLopener.open_filec
Cs\ddl}ddl}t|\}}t|}yt|}Wn0tk
rb}zt|j|j	Wdd}~XYnX|j
}	|jj|j
dd}
||d}|d|pd|	|
f}|s|}
|dddkrd	|}
tt|d
||
St|\}}|sPt|tftkrP|}
|dddkr d	|}
n|dddkr>td
|tt|d
||
StddS)zUse local file.rNT)rz6Content-Type: %s
Content-Length: %d
Last-modified: %s
z
text/plainrRrzfile://rr:z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)rrrr4rVrrlrstrerrorrarrrrrrrrGr
rrrthishostrB)rrHrrrurNZ	localnamererhrrrdZurlfiler)rLrLrMrs: 
zURLopener.open_local_filec
Cst|tstdddl}t|\}}|s2tdt|\}}t|\}}|r\t|\}}nd}t|}t|ppd}t|p|d}t	
|}|sddl}|j}nt
|}t|\}}	t|}|d}
|
dd|
d}
}|
r|
ds|
dd}
|
r
|
ds
d|
d<|||d|
f}t|jtkrfx8t|jD]*}
|
|kr8|j|
}|j|
=|q8Wy||jkrt|||||
|j|<|sd	}nd
}x:|	D]2}t|\}}|dkr|dkr|}qW|j|||\}}|d
|d}d}|r|d|7}|dk	r4|dkr4|d|7}t|}t||d
|Stk
r}ztd| t!"dWdd}~XYnXdS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNzftp error: no host givenrmrrQrRrrKr)rrrrKrsrzftp:zContent-Type: %s
zContent-Length: %d
zftp error %rr:)#rrrrrr
rrr
rrrrr]rr;rr_rMAXFTPCACHErrrrrsrrrrrr	ftperrorsrrr)rrHrrurWr)r
rrrrrNrrrrrrrcrrrdrrLrLrMopen_ftpsp







zURLopener.open_ftpc	
Cs<t|tstdy|dd\}}Wntk
rDtddYnX|sNd}|d}|dkrd	||d
kr||dd
}|d
|}nd}g}|dt	d
t
t|d||dkrt|
dd}nt|}|dt||d||d|}t|}t|}t|||S)zUse "data" URL.zEdata error: proxy support for data protocol currently not implementedrkrRz
data errorzbad data URLztext/plain;charset=US-ASCII;rrNrmzDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %srrzlatin-1zContent-Length: %d
)rrrr;rBrlrfindr\r]ZstrftimeZgmtimerrrrr
r_rrrrStringIOr)	rrHrIrZsemirrrdfrLrLrM	open_data3s6






zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)rrrrrrrrrrrrrGrrrrrrrrCrrrrrrrLrLrLrMr8s.

$


A\


	 :c@seZdZdZddZddZd#ddZd	d
Zd$ddZd%d
dZ	d&ddZ
d'ddZd(ddZd)ddZ
d*ddZd+ddZd,ddZd-dd Zd!d"ZdS).r9z?Derived class with handlers for errors we can handle (perhaps).cOs(tj|f||i|_d|_d|_dS)Nrr)r8r
auth_cachetriesmaxtries)rrr/rLrLrMr`szFancyURLopener.__init__cCst||d||S)z3Default error handling -- don't raise an exception.zhttp:)r)rrHrcrrrdrLrLrMrfsz!FancyURLopener.http_error_defaultNc	Csn|jd7_zR|jrJ|j|jkrJt|dr4|j}n|j}|||dd|S|||||||}|Sd|_XdS)z%Error 302 -- relocated (temporarily).rRhttp_error_500iz)Internal Server Error: Redirect RecursionNr)rrrrrredirect_internal)	rrHrcrrrdrIrrfrLrLrMrjs
zFancyURLopener.http_error_302c	Csxd|kr|d}nd|kr$|d}ndS|t|jd||}t|}|jdkrnt|||d|||||S)Nrrr)rrrrmz( Redirection to url '%s' is not allowed.)rrrrrrrG)	rrHrcrrrdrIrrrLrLrMr|s


z FancyURLopener.redirect_internalcCs|||||||S)z*Error 301 -- also relocated (permanently).)r)rrHrcrrrdrIrLrLrMrszFancyURLopener.http_error_301cCs|||||||S)z;Error 303 -- also relocated (essentially identical to 302).)r)rrHrcrrrdrIrLrLrMrszFancyURLopener.http_error_303cCs2|dkr|||||||S||||||SdS)z1Error 307 -- relocated, but turn POST into error.N)rr)rrHrcrrrdrIrLrLrMrszFancyURLopener.http_error_307Fc
Csd|krt|||||||d}td|}	|	sHt|||||||	\}
}|
dkrtt|||||||st||||||d|jd}|dkrt||||St|||||SdS)z_Error 401 -- authentication required.
        This function supports Basic authentication only.zwww-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r>Zretry__basic_authN)r8rrImatchr9rsrr)
rrHrcrrrdrIrtstuffrrr rZrLrLrMrMs&





zFancyURLopener.http_error_401c
Csd|krt|||||||d}td|}	|	sHt|||||||	\}
}|
dkrtt|||||||st||||||d|jd}|dkrt||||St|||||SdS)zeError 407 -- proxy authentication required.
        This function supports Basic authentication only.zproxy-authenticatez![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"r>Zretry_proxy_rN)r8rrIrr9rsrr)
rrHrcrrrdrIrtrrrr rZrLrLrMrNs&





zFancyURLopener.http_error_407cCst|\}}d||}|jd}t|\}}	t|	\}	}
|	dd}|	|d}	||	||\}}
|sr|
srdSdt|ddt|
dd|	f}	d|	|
|jd<|dkr||S|||SdS)Nzhttp://r@rRz%s:%s@%srm)r)rrrrget_user_passwdr	rG)rrHr rIrurrrrr
proxyselectorrr
rrLrLrMretry_proxy_http_basic_auths 

z*FancyURLopener.retry_proxy_http_basic_authcCst|\}}d||}|jd}t|\}}	t|	\}	}
|	dd}|	|d}	||	||\}}
|sr|
srdSdt|ddt|
dd|	f}	d|	|
|jd<|dkr||S|||SdS)Nzhttps://rrrRz%s:%s@%srm)r)rrrrr	r	rG)rrHr rIrurrrrrr
rr
rrLrLrMretry_proxy_https_basic_auths 

z+FancyURLopener.retry_proxy_https_basic_authc
Cst|\}}|dd}||d}||||\}}|sD|sDdSdt|ddt|dd|f}d||}	|dkr||	S||	|SdS)NrrRz%s:%s@%srm)rzhttp://)rrr	r	rG)
rrHr rIrurrr
rrrLrLrMr?s
z$FancyURLopener.retry_http_basic_authc
Cst|\}}|dd}||d}||||\}}|sD|sDdSdt|ddt|dd|f}d||}	|dkr||	S||	|SdS)NrrRz%s:%s@%srm)rzhttps://)rrr	r	rG)
rrHr rIrurrr
rrrLrLrMretry_https_basic_auth	s
z%FancyURLopener.retry_https_basic_authrcCs`|d|}||jkr2|r(|j|=n
|j|S|||\}}|sJ|rX||f|j|<||fS)Nr)rsrprompt_user_passwd)rrur rrr
rrLrLrMr		s


zFancyURLopener.get_user_passwdcCsTddl}y,td||f}|d|||f}||fStk
rNtdSXdS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: )NN)getpassinputKeyboardInterruptprint)rrur rr
rrLrLrMr$	sz!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)rrrrrrrrrrrrMrNrrr?r
r	rrLrLrLrMr9]s$










cCstdkrtdatS)z8Return the IP address of the magic hostname 'localhost'.Nr)
_localhostrrrLrLrLrMr4	s
rcCsPtdkrLytttdaWn(tjk
rJttddaYnXtS)z,Return the IP addresses of the current host.Nr:r)	_thishostrrrrrrLrLrLrMr<	srcCstdkrddl}|jatS)z1Return the set of errors raised by the FTP class.Nr)
_ftperrorsrr)rrLrLrMrG	srcCstdkrtdatS)z%Return an empty email Message object.Nrm)
_noheadersrrrLrLrLrM	noheadersP	s
rc@sJeZdZdZdddZddZdd	Zd
dZdd
ZddZ	ddZ
dS)rz;Class used by open_ftp() for cache of open FTP connections.NTcCsX||_||_||_||_||_||_d|_||_y|Wn|	YnXdS)Nr)
r
rrur)rrJrefcount	keepaliveinitr)rr
rrur)rrJrrLrLrMr]	szftpwrapper.__init__cCs\ddl}d|_||_|j|j|j|j|j|j	|j
d|j}|j
|dS)Nrr)rbusyZFTPrZconnectrur)rJZloginr
rrrcwd)rrZ_targetrLrLrMrm	s
zftpwrapper.initc
Csddl}||dkr"d}d}nd|}d}y|j|Wn*|jk
rh||j|YnXd}|r|syd|}|j|\}}WnR|jk
r}z2t|dddkrt	d	|
td
Wdd}~XYnX|s|jd|rl|j
}	zJy|j|Wn4|jk
rN}zt	d	||Wdd}~XYnXWd|j|	Xd|}nd}|j|\}}d|_t|d
|j}
|jd7_||
|fS)Nr)rsrzTYPE ArRzTYPE zRETR r6Z550z
ftp error: %rr:zLIST ZLISTr)rendtransferrZvoidcmdrrZntransfercmdZ
error_permrrrrrpwdrrrZmakefile
file_closerr)rrNrrcmdisdirrrrrZftpobjrLrLrMrv	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|jWntk
r,YnXdS)N)rrrr)rrLrLrMr"	s
zftpwrapper.real_close)NT)rrrrrrrrrrr"rLrLrLrMrZ	s
	-rcCsi}xBtjD]4\}}|}|r|dddkr|||dd<qWdtjkr^|ddxXtjD]J\}}|dddkrj|}|r|||dd<qj||dddqjW|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.

    iN_proxyZREQUEST_METHODr)rVenvironrzrsr)rrZrrLrLrMgetproxies_environment	s	
r%cCs|dkrt}y|d}Wntk
r.dSX|dkr<dS|}t|\}}xd|dD]V}|}|r\|d}|}||ks||krdSd|}||s||r\dSq\WdS)zTest if proxies should not be used for a particular host.

    Checks the proxy dict for the value of no_proxy, which should
    be a list of comma separated DNS suffixes, or '*' for all hosts.

    NZnoF*Trk.)r%rlrsr
r;rGlstripr)rurZno_proxyhostonlyr)rZrLrLrMproxy_bypass_environment	s*
r*c	Csddlm}t|\}}dd}d|kr4|dr4dSd}x|d	d
D]}|sPqFtd|}|dk	r|dkryt|}||}Wntk
rwFYnX||d}	|d
}
|
dkrd|d	dd}
nt
|
dd}
d|
}
||
?|	|
?krdSqF|||rFdSqFWdS)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)fnmatchcSsh|d}ttt|}t|dkr<|ddddgdd}|dd>|dd>B|dd>B|d	BS)
Nr'rrrRr\r:r[r6)r;rrr]r_)ZipAddrr(rLrLrMip2num
s

z,_proxy_bypass_macosx_sysconf.<locals>.ip2numr'Zexclude_simpleTN
exceptionsrLz(\d+(?:\.\d+)*)(/\d+)?rRr:r[ F)r+r
rrIrrrrlgroupcountr])ruproxy_settingsr+r)r)r-ZhostIPrrr*maskrLrLrM_proxy_bypass_macosx_sysconf	s:



r4darwin)_get_proxy_settings_get_proxiescCst}t||S)N)r6r4)rur2rLrLrMproxy_bypass_macosx_sysconf<
sr8cCstS)zReturn a dictionary of scheme -> proxy server URL mappings.

        This function uses the MacOSX framework SystemConfiguration
        to fetch the proxy information.
        )r7rLrLrLrMgetproxies_macosx_sysconf@
sr9cCs t}|rt||St|SdS)zReturn True, if host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or from the MacOSX framework SystemConfiguration.

        N)r%r*r8)rurrLrLrMrJ
s
rcCstp
tS)N)r%r9rLrLrLrMr5W
sc
Csi}yddl}Wntk
r$|SXy||jd}||dd}|rt||dd}d|krx|dD]4}|dd\}}td	|sd
||f}|||<qrWn>|dddkr||d
<n$d||d
<d||d<d||d<|	Wnt
ttfk
rYnX|S)zxReturn a dictionary of scheme -> proxy server URL mappings.

        Win32 uses the registry to store proxies.

        rNz;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableZProxyServerrrrRz
(?:[^/:]+)://z%s://%srSzhttp:rz	http://%sz
https://%srzftp://%sr)
winregImportErrorOpenKeyHKEY_CURRENT_USERQueryValueExrr;rIrZCloserlrBr)rr;internetSettingsproxyEnableZproxyServerprZaddressrLrLrMgetproxies_registry\
s8

rCcCstp
tS)zReturn a dictionary of scheme -> proxy server URL mappings.

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

        )r%rCrLrLrLrMr5
scCsxyddl}Wntk
r dSXy6||jd}||dd}t||dd}Wntk
rldSX|rv|szdSt|\}}|g}y t	|}||kr|
|Wntk
rYnXy t|}||kr|
|Wntk
rYnX|d}xp|D]h}	|	dkr$d|kr$dS|	
dd	}	|	
d
d}	|	
dd}	x$|D]}
t|	|
tjrNdSqNWqWdS)
Nrz;Software\Microsoft\Windows\CurrentVersion\Internet Settingsr:Z
ProxyOverriderz<local>r'rRz\.r&z.*?)r;r<r=r>r?rrlr
rrr\Zgetfqdnr;rrIrrK)rur;r@rAZ
proxyOverrideZrawHostr)ZaddrZfqdnr+rrLrLrMproxy_bypass_registry
sR







rEcCs t}|rt||St|SdS)zReturn True, if host should be bypassed.

        Checks proxy settings gathered from the environment, if specified,
        or the registry.

        N)r%r*rE)rurrLrLrMr
s
)NNN)N)~rrrrr_Zhttp.clientrrrV	posixpathrIrrrr]rYrSr?Zurllib.errorrrrZurllib.parserrrrr	r
rrr
rrrrrrrrrZurllib.responserrrDr<rC__all__version_inforrFrr0r1r[r6r7rJASCIIrqrvrrr2rr/rrrrr r!r"r#r$r%urandomr^r&r'r(rur)rrrEr\rr.rUrWr*rr+r,r-rrZZ
nturl2pathr4r3rr8r9rrrrrrrrrr%r*r4platformZ_scproxyr6r7r8r9rr5rCrErLrLrLrM<module>DsP
T
?n$q*@
ov

+3:5!@W

_
%<

-	2