%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/urllib/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/urllib/__pycache__/request.cpython-38.pyc

U

paҌ!@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+z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
_splituser_splitpasswd
_splitattr_splitquery_splitvalue	_splittag	_to_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_handleropenerrL*/usr/local/lib/python3.8/urllib/request.pyr0s2<




cCs|adSN)rF)rKrLrLrMr1sc
Cs:t|\}}tt||}|}|dkrN|sNtj||fW5QRS|r^t|d}nt	j
dd}|j}t
||||f}	d}
d}d}d}
d|krt|d	}|r||
|
|||
}|sq|t|7}|||
d
7}
|r||
|
|qW5QRXW5QRX|dkr6||kr6td||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)delete rcontent-lengthContent-Length1retrieval incomplete: got only %i out of %i bytes)r
contextlibclosingr0infoospathnormpathrGtempfileNamedTemporaryFilename_url_tempfilesappendintreadlenwriter)rHfilename
reporthookrIZurl_typer\fpheaderstfpresultbssizerdblocknumblockrLrLrMr6sH


"c	CsDtD](}zt|Wqtk
r*YqXqtdd=tr@dadS)z0Clean up temporary files from urlretrieve calls.N)rar[unlinkOSErrorrF)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.

    rVHost)full_urlr
get_header_cut_port_resublower)requestrHhostrLrLrMrequest_host3sr|c@seZdZdidddfddZeddZejddZejddZed	d
Zejdd
Zejdd
Zd
dZ	ddZ
ddZddZddZ
ddZddZddZd#ddZdd Zd!d"ZdS)$rNFc	Csl||_i|_i|_d|_||_d|_|D]\}}|||q,|dkrRt|}||_	||_
|rh||_dSrN)rurjunredirected_hdrs_datarI_tunnel_hostitems
add_headerr|origin_req_hostunverifiablemethod)	selfrHrIrjrrrkeyvaluerLrLrM__init__EszRequest.__init__cCs|jrd|j|jS|jS)Nz{}#{})fragmentformat	_full_urlrrLrLrMruWszRequest.full_urlcCs(t||_t|j\|_|_|dSrN)rrrr_parserrHrLrLrMru]s
cCsd|_d|_d|_dS)Nrs)rrselectorrrLrLrMrudscCs|jSrN)r~rrLrLrMrIjszRequest.datacCs(||jkr$||_|dr$|ddS)NContent-length)r~
has_header
remove_header)rrIrLrLrMrIns

cCs
d|_dSrN)rIrrLrLrMrIxscCsNt|j\|_}|jdkr(td|jt|\|_|_|jrJt|j|_dS)Nzunknown url type: %r)	rrtyperBrurr{rr
)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|jSrN)rurrLrLrMget_full_urlszRequest.get_full_urlcCs2|jdkr|js|j|_n||_|j|_||_dS)Nhttps)rrr{rur)rr{rrLrLrM	set_proxys

zRequest.set_proxycCs|j|jkSrN)rrurrLrLrM	has_proxyszRequest.has_proxycCs||j|<dSrN)rj
capitalizerrvalrLrLrMrszRequest.add_headercCs||j|<dSrN)r}rrrLrLrMadd_unredirected_headerszRequest.add_unredirected_headercCs||jkp||jkSrN)rjr}rheader_namerLrLrMrs
zRequest.has_headercCs|j||j||SrN)rjgetr})rrdefaultrLrLrMrvszRequest.get_headercCs |j|d|j|ddSrN)rjpopr}rrLrLrMrszRequest.remove_headercCs|j|j}t|SrN)r}rjlistr)rhdrsrLrLrMheader_itemsszRequest.header_items)N)__name__
__module____qualname__rpropertyrusetterdeleterrIrrrrrrrrrvrrrLrLrLrMrCs8





	

c@sNeZdZddZddZddZddZd	ejfd
dZ	ddd
Z
ddZd	S)rcCs6dt}d|fg|_g|_i|_i|_i|_i|_dS)NPython-urllib/%sz
User-agent)__version__
addheadershandlershandle_openhandle_errorprocess_responseprocess_request)rZclient_versionrLrLrMrszOpenerDirector.__init__c	CsTt|dstdt|d}t|D]}|dkr6q&|d}|d|}||dd}|dr|d|d}||dd}zt|}Wntk
rYnX|j	|i}	|	|j|<n>|dkr|}|j
}	n*|d	kr|}|j}	n|d
kr&|}|j}	nq&|	
|g}
|
r"t|
|n
|
|d}q&|rPt|j|||dS)N
add_parentz%expected BaseHandler instance, got %rF)redirect_requestdo_open
proxy_open_rVerrorrGresponserzT)hasattr	TypeErrorrdirfind
startswithrcrBrrrrr
setdefaultbisectinsortrbrr)rhandlerZaddedmethiprotocolZ	conditionjkindlookuprrLrLrMadd_handlersL



zOpenerDirector.add_handlercCsdSrNrLrrLrLrMcloseszOpenerDirector.closec	Gs<||d}|D]&}t||}||}|dk	r|SqdS)NrL)rr)	rchainr	meth_nameargsrrfuncrlrLrLrM_call_chains
zOpenerDirector._call_chainNc
Cst|trt||}n|}|dk	r(||_||_|j}|d}|j|gD]}t||}||}qJt	
d|j|j|j|
|||}	|d}|j|gD]}t||}|||	}	q|	S)NZ_requestzurllib.RequestZ	_response)
isinstancestrrrIrJrrrrsysauditrurjr_openr)
rfullurlrIrJreqrrZ	processorrrrLrLrMrGs$



zOpenerDirector.opencCsP||jdd|}|r|S|j}||j||d|}|r>|S||jdd|S)NrZdefault_openrunknownunknown_open)rrr)rrrIrlrrLrLrMrs$

zOpenerDirector._opencGs~|dkr,|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|}|r^|S|rz|dd	f|}|j|SdS)
Nhttprrr:z
http_error_%srV_errorrrhttp_error_default)rr)rprotordictrZhttp_errZ	orig_argsrlrLrLrMr&s 

zOpenerDirector.error)N)rrrrrrrsocket_GLOBAL_DEFAULT_TIMEOUTrGrrrLrLrLrMrs/
c	Gst}ttttttttt	g	}t
tjdr2|
tt}|D]B}|D]8}t|trht||r|||qDt||rD||qDq<|D]}||q|D]}||q|D]}t|tr|}||q|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-rrclientrbrEsetrr
issubclassaddremover)rrKZdefault_classesskipklasscheckhrLrLrMr2?s8	




c@s(eZdZdZddZddZddZdS)	rcCs
||_dSrN)parent)rrrLrLrMrfszBaseHandler.add_parentcCsdSrNrLrrLrLrMriszBaseHandler.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)N,r)codemsgrZrr)rrzrrrrrLrLrM
http_responsezsz HTTPErrorProcessor.http_responseN)rrr__doc__rrhttps_responserLrLrLrMr/vsc@seZdZddZdS)rcCst|j||||dSrN)rru)rrrirrrrLrLrMrsz*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.
        )-./i3)rZHEAD)rrrr z%20)rTzcontent-typecs"i|]\}}|kr||qSrL)ry.0kvZCONTENT_HEADERSrLrM
<dictcomp>sz8HTTPRedirectHandler.redirect_request.<locals>.<dictcomp>T)rjrr)rrrureplacerjrrr)	rrrirrrjnewurlmZ
newheadersrLrrMrs
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)
Nlocationurirrftprsz+%s - Redirection to url '%s' is not allowed/r:z
iso-8859-1)encodingsafe
redirect_dictrrVrJ)rschemerr\Znetlocrrr	stringpunctuationrrurrrrmax_repeatsremax_redirectionsinf_msgrdrrrGrJ)
rrrirrrjrurlpartsnewZvisitedrLrLrMhttp_error_302sT



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}|}nZ|ds6td|d|krV|d}|d|}n|dd}|dkrnd}|d|}t|\}}|dk	rt|\}}	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.
    rN//zproxy URL with no authority: %r@r:rS)rrrBrrr)
proxyrZr_scheme	authorityZhost_separatorendZuserinfohostportuserpasswordrLrLrM_parse_proxys$


r'c@s"eZdZdZdddZddZdS)rdNcCsb|dkrt}t|ds td||_|D].\}}|}t|d||||jfddq.dS)Nkeysproxies must be a mappingz%s_opencSs||||SrNrL)rr!rrrLrLrM<lambda>)sz'ProxyHandler.__init__.<locals>.<lambda>)r5rAssertionErrorproxiesrrysetattrr)rr.rrHrLrLrMr!s
zProxyHandler.__init__cCs|j}t|\}}}}|dkr"|}|jr6t|jr6dS|rv|rvdt|t|f}	t|	d}
|	dd|
t|}|
||||ks|dkrdS|jj||j
dSdS)N%s:%sasciiProxy-authorizationBasic rr)rr'r{proxy_bypassr
base64	b64encodeencodedecoderrrrGrJ)rrr!rZ	orig_typeZ
proxy_typer%r&r$Z	user_passZcredsrLrLrMr,s"zProxyHandler.proxy_open)N)rrrrrrrLrLrLrMrs
c@s6eZdZddZddZddZd
dd	Zd
dZdS)r cCs
i|_dSrN)passwdrrLrLrMrJszHTTPPasswordMgr.__init__cs\t|tr|g}|jkr$ij|<dD].tfdd|D}||fj||<q(dS)NTFc3s|]}|VqdSrN)
reduce_uri)rudefault_portrrLrM	<genexpr>Tsz/HTTPPasswordMgr.add_password.<locals>.<genexpr>)rrr9tuple)rrealmrr%r9reduced_urirLr=rMadd_passwordMs


zHTTPPasswordMgr.add_passwordc	Cs`|j|i}dD]H}|||}|D].\}}|D] }|||r6|Sq6q*qdS)Nr:NN)r9rr;r	is_suburi)	rrAauthuriZdomainsr>reduced_authuriZurisZauthinforrLrLrMfind_user_passwordXs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.rVrr:rNPirz%s:%d)rr
r)
rrr>partsrr"r\r{portZdportrLrLrMr;bs$zHTTPPasswordMgr.reduce_uricCsR||krdS|d|dkr dSt|d|df}t|t|dkrNdSdS)zcCheck if test is below base in a URI tree

        Both args must be URIs in reduced form.
        TrFrV)	posixpathcommonprefixre)rbasetestcommonrLrLrMrEyszHTTPPasswordMgr.is_suburiN)T)rrrrrCrHr;rErLrLrLrMr Hs


c@seZdZddZdS)r!cCs0t|||\}}|dk	r"||fSt|d|SrN)r rH)rrArFr%r&rLrLrMrHsz2HTTPPasswordMgrWithDefaultRealm.find_user_passwordN)rrrrHrLrLrLrMr!scs<eZdZfddZd
fdd	ZdddZdd	ZZS)r"csi|_tj||dSrN)
authenticatedsuperrrrkwargs	__class__rLrMrsz%HTTPPasswordMgrWithPriorAuth.__init__Fcs<||||dk	r&td|||t||||dSrN)update_authenticatedrRrC)rrArr%r9is_authenticatedrUrLrMrCsz)HTTPPasswordMgrWithPriorAuth.add_passwordcCs>t|tr|g}dD]$}|D]}|||}||j|<qqdSNr:)rrr;rQ)rrrXr>r<rBrLrLrMrWs
z1HTTPPasswordMgrWithPriorAuth.update_authenticatedcCsDdD]:}|||}|jD]"}|||r|j|SqqdSrY)r;rQrE)rrFr>rGrrLrLrMrXs

z-HTTPPasswordMgrWithPriorAuth.is_authenticated)F)F)rrrrrCrWrX
__classcell__rLrLrUrMr"s

c@sTeZdZedejZdddZddZddZ	d	d
Z
ddZd
dZeZ
eZdS)r#z1(?:^|,)[ 	]*([^ 	,]+)[ 	]+realm=(["']?)([^"']*)\2NcCs"|dkrt}||_|jj|_dSrN)r r9rC)rZpassword_mgrrLrLrMrsz!AbstractBasicAuthHandler.__init__ccspd}tj|D]6}|\}}}|dkr8tdtd||fVd}q|sl|r^|d}nd}|dfVdS)NF)"'zBasic Auth Realm was unquotedTrrs)r#rxfinditergroupsr?r@UserWarningsplit)rheaderZfound_challengemorr	rArLrLrM_parse_realms
z%AbstractBasicAuthHandler._parse_realmc	Cs~||}|sdSd}|D]H}||D]8\}}|dkrB|}q(|dk	r(||||Sq(q|dk	rztd|fdS)NbasiczBAbstractBasicAuthHandler does not support the following scheme: %r)Zget_allreryretry_http_basic_authrB)	rauthreqr{rrjZunsupportedrcrrArLrLrMhttp_error_auth_reqeds
z.AbstractBasicAuthHandler.http_error_auth_reqedcCs||j||\}}|dk	rtd||f}dt|d}||jd|krTdS||j||j	j
||jdSdSdS)Nr0r3r1r)r9rHr5r6r7r8rvauth_headerrrrGrJ)rr{rrAr%pwrawauthrLrLrMrgsz.AbstractBasicAuthHandler.retry_http_basic_authcCstt|jdr|j|js|S|dsp|jd|j\}}d||}t	|
}|dd||S)NrX
Authorizationz{0}:{1}zBasic {})
rr9rXrurrHrr7r5Zstandard_b64encoder8rstrip)rrr%r9ZcredentialsZauth_strrLrLrMhttp_requests
z%AbstractBasicAuthHandler.http_requestcCsLt|jdrHd|jkr"dkr8nn|j|jdn|j|jd|S)NrXrrTF)rr9rrWru)rrrrLrLrMrs
z&AbstractBasicAuthHandler.http_response)N)rrrrecompileIr^rrerirgrpr
https_requestrrLrLrLrMr#s

c@seZdZdZddZdS)r$rncCs|j}|d|||}|S)Nwww-authenticate)ruri)rrrirrrjrHrrLrLrMhttp_error_401$sz#HTTPBasicAuthHandler.http_error_401N)rrrrjrvrLrLrLrMr$ sc@seZdZdZddZdS)r%r2cCs|j}|d|||}|SNproxy-authenticate)r{ri)rrrirrrjr"rrLrLrMhttp_error_407/sz$ProxyBasicAuthHandler.http_error_407N)rrrrjryrLrLrLrMr%+sc@sNeZdZdddZddZddZdd	Zd
dZdd
ZddZ	ddZ
dS)r&NcCs4|dkrt}||_|jj|_d|_d|_d|_dSNr)r r9rCretriednonce_count
last_nonce)rr9rLrLrMrIs
z"AbstractDigestAuthHandler.__init__cCs
d|_dSrz)r{rrLrLrMreset_retry_countRsz+AbstractDigestAuthHandler.reset_retry_countcCs|||d}|jdkr*t|jdd|dn|jd7_|rx|d}|dkr`|||S|dkrxtd|dS)	Nizdigest auth failedrVrdigestrfzEAbstractDigestAuthHandler does not support the following scheme: '%s')rr{rrurbryretry_http_digest_authrB)rrjr{rrjrhrrLrLrMriUs

z/AbstractDigestAuthHandler.http_error_auth_reqedcCsz|dd\}}ttdt|}|||}|rvd|}|j|jd|krRdS||j||j	j
||jd}|SdS)NrrVz	Digest %sr)rbparse_keqv_listfilterparse_http_listget_authorizationrjrrjrrrGrJ)rrrmtokenZ	challengechalZauth_valZresprLrLrMrisz0AbstractDigestAuthHandler.retry_http_digest_authcCs@d|j|tf}|dtd}t|}|ddS)Nz	%s:%s:%s:r1)r|timectimer7_randombyteshashlibsha1	hexdigest)rnoncesbdigrLrLrM
get_cnonceusz$AbstractDigestAuthHandler.get_cnoncecCsz6|d}|d}|d}|dd}|dd}Wntk
rLYdSX||\}}	|dkrhdS|j||j\}
}|
dkrdS|jdk	r||j|}nd}d|
||f}
d||j	f}|dkr|	||
d|||f}n~d	|
d
kr\||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)NrArqop	algorithmMD5opaquez%s:%s:%sr0rm,rVz%08xz%s:%s:%s:%s:%szqop '%s' is not supported.z>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"z
, opaque="%s"z
, digest="%s"z, algorithm="%s"z, qop=auth, nc=%s, cnonce="%s")rKeyErrorget_algorithm_implsr9rHrurIget_entity_digestrrrbr}r|rr)rrrrArrrrHKDr%rkZentdigZA1ZA2ZrespdigZncvalueZcnonceZnoncebitrNrLrLrMrs\




z+AbstractDigestAuthHandler.get_authorizationcsD|dkrddn|dkr$ddntd|fdd}|fS)NrcSst|dSNr1)rmd5r7rxrLrLrMr,z?AbstractDigestAuthHandler.get_algorithm_impls.<locals>.<lambda>ZSHAcSst|dSr)rrr7rrrLrLrMr,rz.Unsupported digest authentication algorithm %rcsd||fS)Nr0rL)rdrrLrMr,r)rB)rrrrLrrMrs

z-AbstractDigestAuthHandler.get_algorithm_implscCsdSrNrL)rrIrrLrLrMrsz+AbstractDigestAuthHandler.get_entity_digest)N)rrrrr~rirrrrrrLrLrLrMr&>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.
    rncCs*t|jd}|d|||}||S)NrVru)rrurir~rrrirrrjr{retryrLrLrMrvsz$HTTPDigestAuthHandler.http_error_401N)rrrrrjrrvrLrLrLrMr'sc@seZdZdZdZddZdS)r(Proxy-AuthorizationrcCs"|j}|d|||}||Srw)r{rir~rrLrLrMrysz%ProxyDigestAuthHandler.http_error_407N)rrrrjrryrLrLrLrMr(sc@s6eZdZd
ddZddZddZdd	Zd
dZdS)AbstractHTTPHandlerrcCs
||_dSrN_debuglevel)r
debuglevelrLrLrMrszAbstractHTTPHandler.__init__cCs
||_dSrNr)rlevelrLrLrMset_http_debuglevelsz'AbstractHTTPHandler.set_http_debuglevelcCstjj|j|SrN)rrHTTPConnection_get_content_lengthrIrrrzrLrLrMrsz'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||j
jD]&\}
}|
}
||
s||
|q|S)	N
no host givenz\POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.zContent-type!application/x-www-form-urlencodedrTransfer-encodingZchunkedrt)r{rrIrrrrrrrrrrrrr)rrzr{rIrZcontent_lengthZsel_hostrZselZsel_pathr`rrLrLrMdo_request_sJ






zAbstractHTTPHandler.do_request_c

sT|j}|std||fd|ji|}||jt|jfdd|j	Ddd<dd	D|j
ri}d}|kr|||<|=|j|j
|d	z`z&|j|
|j|j|d
dWn,tk
r}zt|W5d}~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.
        rrJcsi|]\}}|kr||qSrLrLrrjrLrMr/sz/AbstractHTTPHandler.do_open.<locals>.<dictcomp>r
ConnectioncSsi|]\}}||qSrL)title)rr`rrLrLrMr<srrr)Zencode_chunkedN)r{rrJZset_debuglevelrrr}updaterjrrZ
set_tunnelrzrrrIrrrgetresponsersockrrHreasonr)
rZ
http_classrZhttp_conn_argsr{rZtunnel_headersZproxy_auth_hdrerrr+rLrrMr!sB



zAbstractHTTPHandler.do_openN)r)rrrrrrrrrLrLrLrMrs

&rc@seZdZddZejZdS)r)cCs|tjj|SrN)rrrrrrrLrLrM	http_openfszHTTPHandler.http_openN)rrrrrrrprLrLrLrMr)dsrc@s$eZdZdddZddZejZdS)rErNcCst||||_||_dSrN)rr_context_check_hostname)rrr>check_hostnamerLrLrMroszHTTPSHandler.__init__cCs|jtjj||j|jdS)N)r>r)rrrrrrrrLrLrM
https_opentszHTTPSHandler.https_open)rNN)rrrrrrrrtrLrLrLrMrEms
rEc@s.eZdZdddZddZddZeZeZdS)	rNcCs$ddl}|dkr|j}||_dSrz)Zhttp.cookiejar	cookiejarZ	CookieJar)rrrrLrLrMr}s
zHTTPCookieProcessor.__init__cCs|j||SrN)rZadd_cookie_headerrrLrLrMrpsz HTTPCookieProcessor.http_requestcCs|j|||SrN)rZextract_cookies)rrzrrLrLrMrsz!HTTPCookieProcessor.http_response)N)rrrrrprrtrrLrLrLrMr|s

c@seZdZddZdS)r.cCs|j}td|dS)Nzunknown url type: %s)rr)rrrrLrLrMrszUnknownHandler.unknown_openN)rrrrrLrLrLrMr.scCsNi}|D]@}|dd\}}|ddkr@|ddkr@|dd}|||<q|S)z>Parse list of key=value strings where keys are not duplicated.=rVrr[rS)rb)lZparsedZeltrrrLrLrMrs
rcCsg}d}d}}|D]l}|r*||7}d}q|rT|dkr>d}qn|dkrJd}||7}q|dkrl||d}q|dkrxd}||7}q|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.
    rsF\Tr[rcSsg|]}|qSrL)ro)rpartrLrLrM
<listcomp>sz#parse_http_list.<locals>.<listcomp>)rb)rresrescaper	ZcurrLrLrMrs4	


rc@s(eZdZddZdZddZddZdS)r*cCs\|j}|dddkrN|dddkrN|jrN|jdkrN|j|krXtdn
||SdS)Nr:rr]r	localhost-file:// scheme is supported only on localhost)rr{	get_namesropen_local_file)rrrHrLrLrM	file_opens&
zFileHandler.file_openNcCs`tjdkrZz*ttddttdt_Wn$tjk
rXtdft_YnXtjS)Nrr:)r*namesr@rgethostbyname_exgethostnamegaierror
gethostbynamerrLrLrMrs

zFileHandler.get_namesc
Csddl}ddl}|j}|j}t|}zt|}|j}|jj	|j
dd}	||d}
|d|
pbd||	f}|r~t
|\}}|r|st||kr|rd||}
nd|}
tt|d||
WSWn*tk
r}zt|W5d}~XYnXtddS)	NrTZusegmtz6Content-type: %s
Content-length: %d
Last-modified: %s

text/plainfile://rbzfile not on local host)email.utils	mimetypesr{rr4r[statst_sizeutils
formatdatest_mtime
guess_typemessage_from_stringr
_safe_gethostbynamerrrGrrr)rremailrr{rgZ	localfilestatsrnmodifiedmtyperjrKZorigurlexprLrLrMrs:
zFileHandler.open_local_file)rrrrrrrrLrLrLrMr*s
cCs*zt|WStjk
r$YdSXdSrN)rrr)r{rLrLrMrsrc@seZdZddZddZdS)r+c
Cs*ddl}ddl}|j}|s"tdt|\}}|dkr>|j}nt|}t|\}}|rdt|\}}nd}t	|}|pvd}|p~d}zt
|}Wn*tk
r}zt|W5d}~XYnXt
|j\}	}
|	d}ttt	|}|dd|d}}|r|ds|dd}z|||||||j}
|r6dp8d}|
D]2}t|\}}|d	kr>|d
kr>|}q>|
||\}}d}||jd}|r|d|7}|dk	r|dkr|d|7}t|}t|||jWS|jk
r$}z"td
|}|t dW5d}~XYnXdS)Nrftp error: no host givenrsrrSrVrsDraArrsrrzContent-type: %s
zContent-length: %d

ftp error: %rr:)!ftplibrr{rr
FTP_PORTrcrrr
rrrrrrrbrmapconnect_ftprJrryupperretrfilerrurrr
all_errorswith_tracebackrexc_info)rrrrr{rKr%r9rr\attrsdirsrOfwrattrrriretrlenrjrrexcrLrLrMftp_opens^

zFTPHandler.ftp_openc	Cst||||||ddS)NF)
persistent)
ftpwrapper)rr%r9r{rKrrJrLrLrMr7szFTPHandler.connect_ftpN)rrrrrrLrLrLrMr+s5c@s<eZdZddZddZddZddZd	d
ZddZd
S)r,cCs"i|_i|_d|_d|_d|_dS)Nr<r)cacherJsoonestdelay	max_connsrrLrLrMr>s
zCacheFTPHandler.__init__cCs
||_dSrN)r)rtrLrLrM
setTimeoutEszCacheFTPHandler.setTimeoutcCs
||_dSrN)r)rr	rLrLrMsetMaxConnsHszCacheFTPHandler.setMaxConnscCsr|||d||f}||jkr4t|j|j|<n,t|||||||j|<t|j|j|<||j|S)Nr)joinrrrrJrcheck_cache)rr%r9r{rKrrJrrLrLrMrKs


zCacheFTPHandler.connect_ftpcCst}|j|krPt|jD].\}}||kr |j||j|=|j|=q tt|j|_t	|j|j
krt|jD]&\}}||jkr|j|=|j|=qqtt|j|_dSrN)rrrrJrrrminvaluesrer)rrrrrLrLrMrVs


zCacheFTPHandler.check_cachecCs0|jD]}|q
|j|jdSrN)rr
rclearrJ)rconnrLrLrMclear_cachejs

zCacheFTPHandler.clear_cacheN)	rrrrrr	rrrrLrLrLrMr,;sc@seZdZddZdS)r-cCs~|j}|dd\}}|dd\}}t|}|drNt|}|dd}|sVd}td|t|f}t	t
|||S)N:rVrz;base64itext/plain;charset=US-ASCIIz$Content-type: %s
Content-length: %d
)rurbrendswithr5decodebytesrrrerioBytesIO)rrrHrrIZ	mediatyperjrLrLrM	data_openqs



zDataHandler.data_openN)rrrrrLrLrLrMr-psrnt)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).NrcKsdd|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/methodsclassr])
stacklevelr)r*key_file	cert_filez
User-Agent)ZAcceptz*/*)rVrr?r@rAr5rr-r.rrrversionr_URLopener__tempfilesr[rq_URLopener__unlink	tempcacheftpcache)rr.Zx509rrLrLrMrs
zURLopener.__init__cCs|dSrN)rrrLrLrM__del__szURLopener.__del__cCs|dSrN)cleanuprrLrLrMrszURLopener.closec	CsV|jrB|jD](}z||Wqtk
r2YqXq|jdd=|jrR|jdSrN)r r!rrr"r)rrOrLrLrMr%s
zURLopener.cleanupcGs|j|dS)zdAdd a header to be used by the HTTP interface only
        e.g. u.addheader('Accept', 'sound/basic')N)rrb)rrrLrLrM	addheaderszURLopener.addheaderc
Csptt|}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|
||Sz0|dkrt|||WSt||||WSWnVttfk
r0Yn<tk
rj}
ztd
|
tdW5d}
~
XYnXdS)z6Use URLopener().open(file) instead of open(file, 'r').z%/:=&?~#+!$,;'@()*[]|rrrONZopen_-rrzsocket errorr:)rrr	r"rGrrr.rrrropen_unknown_proxyopen_unknownrrrrrrrr)rrrIrgrjriurltyperHr!	proxyhostr{rr`rrLrLrMrGs<




zURLopener.opencCst|\}}tdd|dS)/Overridable interface to open unknown URL type.	url errorzunknown url typeNrrr)rrrIrrHrLrLrMr*
szURLopener.open_unknowncCs t|\}}tdd||dS)r-r.zinvalid proxy for %sNr/)rr!rrIrrHrLrLrMr)szURLopener.open_unknown_proxyc
Cstt|}|jr&||jkr&|j|St|\}}|dkr|rF|dkrz0||}|}|tt|d|fWSt	k
r}	zW5d}	~	XYnX|
||}z<|}
|rt
|d}nrt|\}}
t|
pd\}}
t|
pd\}
}t|
pd\}
}t
j|
d}t|\}}|j|t
|d}z||
f}|jdk	rT||j|<d}d}d}d}d	|
krzt|
d
}|r||||||}|sq|t|7}|||d7}|r||||qW5|XW5|X|dkr||krtd||f||S)ztretrieve(url) returns (filename, headers) for a local object
        or (tempfilename, headers) for a remote object.NrOrVrPrsrRrSrrTrUrW)rrr"rrrZrr4rrrrGrrr[r\splitextr^mkstempr rbfdopenrcrdrerfr)rrHrgrhrIrZurl1rirrrjrkZgarbager\suffixfdrlrmrnrdrorprLrLrMretrievesn






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<|j
D]\}}|||<qX|dk	rd
|d<|
d|||n|
jd||dz|
}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 errorrr1zBasic %srrnrtrrrzContent-Typerrrz$http protocol error: bad status linerrhttp:)rrrrr
rryr4rrr5r6r7r8rrzrrrZ
BadStatusLinerstatusrr
http_errorrir)rZconnection_factoryrHrIZuser_passwdZproxy_passwdr{rZrealhostr+rZ
proxy_authrmZ	http_connrjrcrrrLrLrM_open_generic_httpVs~



zURLopener._open_generic_httpcCs|tjj||S)zUse HTTP protocol.)r9rrrrrHrIrLrLrM	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)
rrHrierrcodeerrmsgrjrIr`rrlrLrLrMr8s

zURLopener.http_errorcCs|t||||ddS)z>Default error handler: close the connection and raise OSError.N)rrrrHrir<r=rjrLrLrMrszURLopener.http_error_defaultcCstjj||j|jdS)N)rr)rrrrr)rr{rLrLrM_https_connectionszURLopener._https_connectioncCs||j||S)zUse HTTPS protocol.)r9r?r:rLrLrM
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:rr]rz
localhost/r)rrrryrBrrrLrLrM	open_files

4
zURLopener.open_filec
Cs\ddl}ddl}t|\}}t|}zt|}Wn0tk
rb}zt|j|j	W5d}~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.rNTrz6Content-Type: %s
Content-Length: %d
Last-modified: %s
rrVrrrr:z./zAlocal file url may start with / or file:. Unknown url of type: %sz#local file error: not on local host)rrrr4r[rrrrstrerrorrgrrrrrrrrGr
rrrthishostrB)rrHrrr{rOZ	localnamerernrrrjZurlfilerKrLrLrMrs@ 
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|jtkrbt|jD]*}
|
|kr6|j|
}|j|
=|q6z||jkrt|||||
|j|<|sd	}nd
}|	D]2}t|\}}|dkr|dkr|}q|j|||\}}|d
|d}d}|r|d|7}|dk	r,|dkr,|d|7}t|}t||d
|WStk
r}ztd| t!"dW5d}~XYnXdS)zUse FTP protocol.zCftp error: proxy support for ftp protocol currently not implementedrNrrsrrSrVrrsrrzftp:zContent-Type: %s
zContent-Length: %d
zftp error %rr:)#rrrrrr
rrr
rrrrrcrrbr
rer#MAXFTPCACHErrrrryrrrrrr	ftperrorsrrr)rrHrr{r\rKr%r9rrrrOrrrrrrrirrrjrrLrLrMopen_ftpst





zURLopener.open_ftpc	
Cs<t|tstdz|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 implementedrrVz
data errorzbad data URLr;rrNrszDate: %sz%a, %d %b %Y %H:%M:%S GMTzContent-type: %sr5r1zlatin-1zContent-Length: %d
)rrrrbrBrrrfindrbrstrftimegmtimer5rr7r8r
rer
rrrStringIOr)	rrHrIrZsemirrrjfrLrLrM	open_data8s8






zURLopener.open_data)N)N)N)N)NNN)N)N)N)N)rrrrr rrrr$rr%r&rGr*r)r5r9r;r8rrCr?r@rBrrHrPrLrLrLrMr8s.

$


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_cachetriesmaxtriesrSrLrLrMreszFancyURLopener.__init__cCst||d||S)z3Default error handling -- don't raise an exception.r6)rr>rLrLrMrksz!FancyURLopener.http_error_defaultNc	Csv|jd7_zZ|jrN|j|jkrNt|dr4|j}n|j}|||dd|WS|||||||}|WSd|_XdS)z%Error 302 -- relocated (temporarily).rVrhttp_error_500rz)Internal Server Error: Redirect RecursionN)rRrSrrTrredirect_internal)	rrHrir<r=rjrIrrlrLrLrMros 
zFancyURLopener.http_error_302c	Csxd|kr|d}nd|kr$|d}ndS|t|jd||}t|}|jdkrnt|||d|||||S)Nr
rrrz( Redirection to url '%s' is not allowed.)rrrrrrrG)	rrHrir<r=rjrIrrrLrLrMrUs"


z FancyURLopener.redirect_internalcCs|||||||S)z*Error 301 -- also relocated (permanently).rrrHrir<r=rjrIrLrLrMrszFancyURLopener.http_error_301cCs|||||||S)z;Error 303 -- also relocated (essentially identical to 302).rVrWrLrLrMrszFancyURLopener.http_error_303cCs2|dkr|||||||S||||||SdS)z1Error 307 -- relocated, but turn POST into error.N)rrrWrLrLrMrszFancyURLopener.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.ru![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"rfZretry__basic_authNr8rrqmatchr`ryrr
rrHrir<r=rjrIrstuffr[rrAr`rLrLrMrvs:


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.rxrXrfZretry_proxy_rYNrZr\rLrLrMrys:


zFancyURLopener.http_error_407cCst|\}}d||}|jd}t|\}}	t|	\}	}
|	dd}|	|d}	||	||\}}
|sr|
srdSdt|ddt|
dd|	f}	d|	|
|jd<|dkr||S|||SdS)Nhttp://rr rV%s:%s@%srsr'rr.rrget_user_passwdr	rGrrHrArIr{rrr!r+r,Z
proxyselectorrr%r9rLrLrMretry_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)Nhttps://rr rVr_rsr'r`rbrLrLrMretry_proxy_https_basic_auths$


z+FancyURLopener.retry_proxy_https_basic_authc
Cst|\}}|dd}||d}||||\}}|sD|sDdSdt|ddt|dd|f}d||}	|dkr||	S||	|SdS)Nr rVr_rsr'r^rrrar	rG
rrHrArIr{rrr%r9rrLrLrMrg	s

z$FancyURLopener.retry_http_basic_authc
Cst|\}}|dd}||d}||||\}}|sD|sDdSdt|ddt|dd|f}d||}	|dkr||	S||	|SdS)Nr rVr_rsr'rdrfrgrLrLrMretry_https_basic_auth	s

z%FancyURLopener.retry_https_basic_authrcCs`|d|}||jkr2|r(|j|=n
|j|S|||\}}|sJ|rX||f|j|<||fS)Nr )ryrQprompt_user_passwd)rr{rArrr%r9rLrLrMra	s


zFancyURLopener.get_user_passwdcCsXddl}z.td||f}|d|||f}||fWStk
rRtYdSXdS)z#Override this in a GUI environment!rNzEnter username for %s at %s: z#Enter password for %s in %s at %s: rD)getpassinputKeyboardInterruptprint)rr{rArjr%r9rLrLrMri)	s
z!FancyURLopener.prompt_user_passwd)N)N)N)N)NF)NF)N)N)N)N)r)rrrrrrrrUrrrrvryrcrergrhrarirLrLrLrMr9bs(










cCstdkrtdatS)z8Return the IP address of the magic hostname 'localhost'.Nr)
_localhostrrrLrLrLrMr9	s
rcCsPtdkrLztttdaWn(tjk
rJttddaYnXtS)z,Return the IP addresses of the current host.Nr:r)	_thishostr@rrrrrLrLrLrMrDA	srDcCstdkrddl}|jatS)z1Return the set of errors raised by the FTP class.Nr)
_ftperrorsrr)rrLrLrMrGL	srGcCstdkrtdatS)z%Return an empty email Message object.Nrs)
_noheadersrrrLrLrLrM	noheadersU	s
rrc@sJeZdZdZdddZddZdd	Zd
dZdd
ZddZ	ddZ
dS)rz;Class used by open_ftp() for cache of open FTP connections.NTcCsX||_||_||_||_||_||_d|_||_z|Wn|	YnXdSrz)
r%r9r{rKrrJrefcount	keepaliveinitr)rr%r9r{rKrrJrrLrLrMrb	szftpwrapper.__init__cCs\ddl}d|_||_|j|j|j|j|j|j	|j
d|j}|j
|dS)Nrr)rbusyZFTPr
connectr{rKrJZloginr%r9r
rcwd)rr_targetrLrLrMrur	s
zftpwrapper.initc
Csddl}||dkr"d}d}nd|}d}z|j|Wn*|jk
rh||j|YnXd}|r|szd|}|j|\}}WnR|jk
r}z2t|dddkrt	d	|
td
W5d}~XYnX|s|jd|rl|j
}	zJz|j|Wn4|jk
rN}zt	d	||W5d}~XYnXW5|j|	Xd|}nd}|j|\}}d|_t|d
|j}
|jd7_||
|fS)Nr)rrzTYPE ArVzTYPE zRETR r]Z550rr:zLIST LISTr)rendtransferr
ZvoidcmdrruZntransfercmdZ
error_permrrrrrpwdrxrvrmakefile
file_closersr)rrOrrcmdisdirrrrr|ZftpobjrLrLrMr{	sP

$
zftpwrapper.retrfilecCs
d|_dSrz)rvrrLrLrMr{	szftpwrapper.endtransfercCsd|_|jdkr|dS)NFr)rtrs
real_closerrLrLrMr	s
zftpwrapper.closecCs2||jd8_|jdkr.|js.|dS)NrVr)r{rsrtrrrLrLrMr~	szftpwrapper.file_closecCs2|z|jWntk
r,YnXdSrN)r{r
rrGrrLrLrMr	s
zftpwrapper.real_close)NT)rrrrrrurr{rr~rrLrLrLrMr_	s
	-rcCsi}tjD]4\}}|}|r|dddkr|||dd<qdtjkrZ|ddtjD]J\}}|dddkrd|}|r|||dd<qd||dddqd|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)r[environrryr)r.r`rrLrLrMgetproxies_environment	s	
rcCs|dkrt}z|d}Wntk
r0YdSX|dkr>dS|}t|\}}|dD]Z}|}|r\|d}|}||ks||krdSd|}||s||r\dSq\dS)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.

    NnoF*Tr.)rrryr
rbrolstripr)r{r.Zno_proxyhostonlyrKr`rLrLrMproxy_bypass_environment	s*
rc	Cs0ddlm}t|\}}dd}d|kr4|dr4dSd}|d	d
D]}|sNqDtd|}|dk	r|dkrzt|}||}Wntk
rYqDYnX||d}	|d
}
|
dkrd|d	dd}
nt
|
dd}
|
dksD|
dkrqDd|
}
||
?|	|
?kr*dSqD|||rDdSqDdS)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)
NrrrrVrr:rr])rbrrrcre)ZipAddrrJrLrLrMip2num
s

z,_proxy_bypass_macosx_sysconf.<locals>.ip2numrZexclude_simpleTN
exceptionsrLz(\d+(?:\.\d+)*)(/\d+)?rVr:r F)rr
rrqr[rrrrgroupcountrc)r{proxy_settingsrrrKrZhostIPrr	rNmaskrLrLrM_proxy_bypass_macosx_sysconf
s>




rdarwin)_get_proxy_settings_get_proxiescCst}t||SrN)rr)r{rrLrLrMproxy_bypass_macosx_sysconfF
srcCstS)zReturn a dictionary of scheme -> proxy server URL mappings.

        This function uses the MacOSX framework SystemConfiguration
        to fetch the proxy information.
        )rrLrLrLrMgetproxies_macosx_sysconfJ
srcCs 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)rrrr{r.rLrLrMr4T
s
r4cCstp
tSrN)rrrLrLrLrMr5a
sc
Csi}zddl}Wntk
r(|YSXz||jd}||dd}|rt||dd}d|kr|dD]4}|dd\}}td	|sd
||f}|||<qtn>|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.

        rN;Software\Microsoft\Windows\CurrentVersion\Internet SettingsProxyEnableZProxyServerrrIrVz
(?:[^/:]+)://z%s://%srr6rz	http://%sz
https://%srzftp://%sr
)
winregImportErrorOpenKeyHKEY_CURRENT_USERQueryValueExrrbrqr[CloserrrBr)r.rinternetSettingsproxyEnableZproxyServerpraddressrLrLrMgetproxies_registryf
sF

rcCstp
tS)zReturn a dictionary of scheme -> proxy server URL mappings.

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

        )rrrLrLrLrMr5
scCs|zddl}Wntk
r"YdSXz6||jd}||dd}t||dd}Wntk
rpYdSX|rz|s~dSt|\}}|g}z t	|}||kr|
|Wntk
rYnXz t|}||kr|
|Wntk
rYnX|d}|D]j}	|	dkr*d|kr*dS|	
dd	}	|	
d
d}	|	
dd}	|D] }
t|	|
tjrRdSqRqdS)
NrrrZ
ProxyOverriderIz<local>rrVz\.rz.*?)rrrrrrrrr
rrrbgetfqdnrbrrqr[rs)r{rrrZ
proxyOverrideZrawHostrKaddrZfqdnrOrrLrLrMproxy_bypass_registry
s`





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

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

        N)rrrrrLrLrMr4
s
)NNN)N)~rr5rrrZhttp.clientrrr[rLrqrrrrr^rXr?Zurllib.errorrrrZurllib.parserrrrr	r
rrr
rrrrrrrrrZurllib.responserrrDrrC__all__version_inforrFrr0r1rar6r7rrASCIIrwr|rrr2rr/rrr'rr r!r"r#r$r%urandomrr&r'r(rr)rrrErbrr.rrr*rr+r,r-rFr`Z
nturl2pathr4r3r#r8r9rnrrorDrprGrqrrrrrrplatformZ_scproxyrrrrr4r5rrrLrLrLrM<module>s SP
U
?m$q!+@
ov

+3:5!@W

_
%A

-	2


Zerion Mini Shell 1.0