Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/urllib2.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c@s0dZddkZddkZddkZddkZddkZddkZddkZddkZddk	Z	ddk
Z
ddkZddkZddk
Z
yddklZWn#ej
oddklZnXddklZlZlZlZlZlZlZlZlZlZlZlZlZlZl Z ddkl!Z!l"Z"l#Z#e
i$d Z%da'dd�Z(d�Z)d	e*fd
��YZ+de+efd��YZ,d
e+fd��YZ-ei.d�Z/d�Z0ddGd��YZ1ddHd��YZ2d�Z3ddId��YZ4de4fd��YZ5de4fd��YZ6de4fd��YZ7d�Z8de4fd ��YZ9d!dJd"��YZ:d#e:fd$��YZ;d%dKd&��YZ<d'e<e4fd(��YZ=d)e<e4fd*��YZ>d+�Z?d,dLd-��YZ@d.e4e@fd/��YZAd0e4e@fd1��YZBd2e4fd3��YZCd4eCfd5��YZDeEed6�od7eCfd8��YZFnd9e4fd:��YZGd;e4fd<��YZHd=�ZId>�ZJd?e4fd@��YZKdAe4fdB��YZLdCeLfdD��YZMdEe4fdF��YZNdS(Ms
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
IOError); 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 --

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

BaseHandler --

exceptions:
URLError-- a subclass of IOError, individual protocols have their own
specific subclass

HTTPError-- also a valid HTTP response, so you can treat an HTTP error
as an exceptional event or valid response

internals:
BaseHandler and parent
_call_chain conventions

Example usage:

import urllib2

# set up authentication info
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password('realm', 'host', 'username', 'password')

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

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

# install it
urllib2.install_opener(opener)

f = urllib2.urlopen('http://www.python.org/')


i�N(tStringIO(tunwraptunquotet	splittypet	splithosttquotet
addinfourlt	splitporttsplitgophertypet
splitqueryt	splitattrt
ftpwrappert	noheaderst	splitusertsplitpasswdt
splitvalue(t	localhostturl2pathnamet
getproxiesicCs*tdjo
t�anti||�S(N(t_openertNonetbuild_openertopen(turltdata((s/sys/lib/python/urllib2.pyturlopenus

cCs
|adS(N(R(topener((s/sys/lib/python/urllib2.pytinstall_opener{stURLErrorcBseZd�Zd�ZRS(cCs|f|_||_dS(N(targstreason(tselfR((s/sys/lib/python/urllib2.pyt__init__�scCsd|iS(Ns<urlopen error %s>(R(R((s/sys/lib/python/urllib2.pyt__str__�s(t__name__t
__module__R R!(((s/sys/lib/python/urllib2.pyR�s	t	HTTPErrorcBs)eZdZeiZd�Zd�ZRS(sBRaised when HTTP error occurs, but also acts like non-error returncCsU||_||_||_||_||_|dj	o|i|||�ndS(N(tcodetmsgthdrstfptfilenameRt_HTTPError__super_init(RRR%R&R'R(((s/sys/lib/python/urllib2.pyR �s					
cCsd|i|ifS(NsHTTP Error %s: %s(R%R&(R((s/sys/lib/python/urllib2.pyR!�s(R"R#t__doc__RR R*R!(((s/sys/lib/python/urllib2.pyR$�s		
tGopherErrorcBseZRS((R"R#(((s/sys/lib/python/urllib2.pyR,�ss:\d+$cCsa|i�}ti|�d}|djo|idd�}ntid|d�}|i�S(s�Return request-host, as defined by RFC 2965.

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

    ittHost(tget_full_urlturlparset
get_headert_cut_port_retsubtlower(trequestRthost((s/sys/lib/python/urllib2.pytrequest_host�s
tRequestcBs�eZdhded�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zd
�Zd�Zd�Zdd�Zd�ZRS(cCs�t|�|_d|_d|_d|_||_h|_x*|i�D]\}}|i	||�qIWh|_
|djot|�}n||_||_
dS(N(Rt_Request__originalRttypeR6tportRtheaderstitemst
add_headertunredirected_hdrsR7torigin_req_hosttunverifiable(RRRR<R@RAtkeytvalue((s/sys/lib/python/urllib2.pyR �s					
	
	cCse|d djoG|d}ttd|�o%t|d|��t||�SqXnt|�dS(Nit_Request__r_tget_(thasattrR8tgetattrtAttributeError(Rtattrtname((s/sys/lib/python/urllib2.pyt__getattr__�s
cCs|i�odSndSdS(NtPOSTtGET(thas_data(R((s/sys/lib/python/urllib2.pyt
get_method�s
cCs
||_dS(N(R(RR((s/sys/lib/python/urllib2.pytadd_data�scCs
|idj	S(N(RR(R((s/sys/lib/python/urllib2.pyRN�scCs|iS(N(R(R((s/sys/lib/python/urllib2.pytget_data�scCs|iS(N(R9(R((s/sys/lib/python/urllib2.pyR/�scCsZ|idjoCt|i�\|_|_|idjotd|i�qSn|iS(Nsunknown url type: %s(R:RRR9t_Request__r_typet
ValueError(R((s/sys/lib/python/urllib2.pytget_type�s
cCsV|idjo?t|i�\|_|_|iot|i�|_qOn|iS(N(R6RRRRt_Request__r_hostR(R((s/sys/lib/python/urllib2.pytget_host�s

cCs|iS(N(RU(R((s/sys/lib/python/urllib2.pytget_selector�scCs#|||_|_|i|_dS(N(R6R:R9RU(RR6R:((s/sys/lib/python/urllib2.pyt	set_proxy�scCs|iS(N(R@(R((s/sys/lib/python/urllib2.pytget_origin_req_hostscCs|iS(N(RA(R((s/sys/lib/python/urllib2.pytis_unverifiablescCs||i|i�<dS(N(R<t
capitalize(RRBtval((s/sys/lib/python/urllib2.pyR>scCs||i|i�<dS(N(R?R[(RRBR\((s/sys/lib/python/urllib2.pytadd_unredirected_headerscCs||ijp
||ijS(N(R<R?(Rtheader_name((s/sys/lib/python/urllib2.pyt
has_headerscCs"|ii||ii||��S(N(R<tgetR?(RR^tdefault((s/sys/lib/python/urllib2.pyR1s	cCs)|ii�}|i|i�|i�S(N(R?tcopytupdateR<R=(RR'((s/sys/lib/python/urllib2.pytheader_itemssN(R"R#RtFalseR RKRORPRNRQR/RTRVRWRXRYRZR>R]R_R1Rd(((s/sys/lib/python/urllib2.pyR8�s&															tOpenerDirectorcBsMeZd�Zd�Zd�Zd�Zdd�Zdd�Zd�Z	RS(cCsMdt}d|fg|_g|_h|_h|_h|_h|_dS(NsPython-urllib/%ss
User-agent(t__version__t
addheadersthandlersthandle_openthandle_errortprocess_responsetprocess_request(Rtclient_version((s/sys/lib/python/urllib2.pyR s
				c
Cs�t}xst|�D]e}|d
joqn|id�}|| }||d}|id�oq|id�|d}||d}yt|�}Wntj
onX|ii|h�}	|	|i|<nd|djo|}|i}	nD|djo|}|i	}	n$|d	jo|}|i
}	nq|	i|g�}
|
oti
|
|�n|
i|�t}qW|o$ti
|i|�|i|�ndS(Ntredirect_requesttdo_opent
proxy_opent_iterrorRtresponseR5(sredirect_requestsdo_opens
proxy_open(Retdirtfindt
startswithtintRSRkR`RjRlRmt
setdefaulttbisecttinsorttappendtTrueRit
add_parent(Rthandlertaddedtmethtitprotocolt	conditiontjtkindtlookupRi((s/sys/lib/python/urllib2.pytadd_handler)sF










cCsdS(N((R((s/sys/lib/python/urllib2.pytcloseUsc	GsW|i|d�}x>|D]6}t||�}||�}|dj	o|SqqWdS(N((R`RGR(	RtchainR�t	meth_nameRRiRtfunctresult((s/sys/lib/python/urllib2.pyt_call_chainYs
c	Cs�t|t�ot||�}n%|}|dj	o|i|�n|i�}|d}x8|ii|g�D]!}t||�}||�}qsW|i	||�}|d}x;|i
i|g�D]$}t||�}|||�}q�W|S(Nt_requestt	_response(t
isinstancet
basestringR8RRPRTRmR`RGt_openRl(	RtfullurlRtreqR�R�t	processorR�Rt((s/sys/lib/python/urllib2.pyRes$


cCs}|i|idd|�}|o|Sn|i�}|i|i||d|�}|o|Sn|i|idd|�S(NRatdefault_openR�tunknowntunknown_open(R�RjRT(RR�RR�R�((s/sys/lib/python/urllib2.pyR��s
cGs�|d
jo1|id}|d}d|}d}|}n|i}|d}d}|||f|}|i|�}|o|Sn|o$|dd	f|}|i|�SndS(Nthttpthttpsis
http_error_%sit_erroriRathttp_error_default(shttpshttps(RkR�(RtprotoRtdictR�thttp_errt	orig_argsR�((s/sys/lib/python/urllib2.pyRs�s 




	
N(
R"R#R R�R�R�RRR�Rs(((s/sys/lib/python/urllib2.pyRfs	
	,		csYddk��fd�}t�}tttttttt	g}t
td�o|it
�ng}xr|D]j}xa|D]Y}||�o%t||�o|i|�q�q}t||�o|i|�q}q}WqpWx|D]}|i|�q�x|D]}|i|��qWx5|D]-}||�o
|�}n|i|�q$W|S(sCreate an opener object from a list of handlers.

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

    If any of the handlers passed as arguments are subclasses of the
    default handlers, the default handlers will not be used.
    i�Ncs t|�i�p
t|d�S(Nt	__bases__(R�t	ClassTypeRF(tobj(ttypes(s/sys/lib/python/urllib2.pytisclass�stHTTPS(R�RftProxyHandlertUnknownHandlertHTTPHandlertHTTPDefaultErrorHandlertHTTPRedirectHandlert
FTPHandlertFileHandlertHTTPErrorProcessorRFthttplibR|tHTTPSHandlert
issubclassR�tremoveR�(RiR�Rtdefault_classestskiptklasstcheckth((R�s/sys/lib/python/urllib2.pyR�s<			


tBaseHandlercBs)eZdZd�Zd�Zd�ZRS(i�cCs
||_dS(N(tparent(RR�((s/sys/lib/python/urllib2.pyR~�scCsdS(N((R((s/sys/lib/python/urllib2.pyR��scCs(t|d�ptSn|i|ijS(Nt
handler_order(RFR}R�(Rtother((s/sys/lib/python/urllib2.pyt__lt__�s(R"R#R�R~R�R�(((s/sys/lib/python/urllib2.pyR��s		R�cBs#eZdZdZd�ZeZRS(sProcess HTTP error responses.i�cCsV|i|i|i�}}}|djo%|iid|||||�}n|S(Ni�i�R�(i�i�(R%R&tinfoR�Rs(RR5RtR%R&R'((s/sys/lib/python/urllib2.pyt
http_response�s
 
	(R"R#R+R�R�thttps_response(((s/sys/lib/python/urllib2.pyR��s		R�cBseZd�ZRS(cCs"t|i�||||��dS(N(R$R/(RR�R(R%R&R'((s/sys/lib/python/urllib2.pyR��s(R"R#R�(((s/sys/lib/python/urllib2.pyR��sR�cBs:eZdZdZd�Zd�ZeZZZdZ	RS(ii
cCs�|i�}|djo
|djp|djoH|djo;|idd	�}t|d
|id|i�dt�Snt|i�||||��d
S(s�Return 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/i3RMtHEADRLt s%20R<R@RAN(i-i.i/i3(sGETR�(i-i.i/(ROtreplaceR8R<RYR}R$R/(RR�R(R%R&R<tnewurltm((s/sys/lib/python/urllib2.pyRo�s
		c	Cshd|jo|id�d}n)d|jo|id�d}ndSti|i�|�}|i||||||�}|djodSnt|d�oo|i}|_|i|d�|i	jpt
|�|ijo)t|i�||i
|||��q*nh}|_|_|i|d�d||<|i�|i�|ii|�S(Ntlocationiturit
redirect_dicti(t
getheadersR0turljoinR/RoRRFR�R`tmax_repeatstlentmax_redirectionsR$tinf_msgtreadR�R�R(	RR�R(R%R&R<R�tnewtvisited((s/sys/lib/python/urllib2.pythttp_error_302s(




soThe HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
(
R"R#R�R�RoR�thttp_error_301thttp_error_303thttp_error_307R�(((s/sys/lib/python/urllib2.pyR��s		%c	Cs�t|�\}}|id�pd}|}n[|id�ptd|��n|idd�}|djo
d}n|d|!}t|�\}}|dj	ot|�\}}nd}}||||fS(s3Return (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:

    >>> _parse_proxy('file:/ftp.example.com/')
    Traceback (most recent call last):
    ValueError: proxy URL with no authority: 'file:/ftp.example.com/'

    The first three items of the returned tuple may be None.

    Examples of authority parsing:

    >>> _parse_proxy('proxy.example.com')
    (None, None, None, 'proxy.example.com')
    >>> _parse_proxy('proxy.example.com:3128')
    (None, None, None, 'proxy.example.com:3128')

    The authority component may optionally include userinfo (assumed to be
    username:password):

    >>> _parse_proxy('joe:password@proxy.example.com')
    (None, 'joe', 'password', 'proxy.example.com')
    >>> _parse_proxy('joe:password@proxy.example.com:3128')
    (None, 'joe', 'password', 'proxy.example.com:3128')

    Same examples, but with URLs instead:

    >>> _parse_proxy('http://proxy.example.com/')
    ('http', None, None, 'proxy.example.com')
    >>> _parse_proxy('http://proxy.example.com:3128/')
    ('http', None, None, 'proxy.example.com:3128')
    >>> _parse_proxy('http://joe:password@proxy.example.com/')
    ('http', 'joe', 'password', 'proxy.example.com')
    >>> _parse_proxy('http://joe:password@proxy.example.com:3128')
    ('http', 'joe', 'password', 'proxy.example.com:3128')

    Everything after the authority is ignored:

    >>> _parse_proxy('ftp://joe:password@proxy.example.com/rubbish:3128')
    ('ftp', 'joe', 'password', 'proxy.example.com')

    Test for no trailing '/' case:

    >>> _parse_proxy('http://joe:password@proxy.example.com')
    ('http', 'joe', 'password', 'proxy.example.com')

    t/s//sproxy URL with no authority: %rii�N(RRwRRSRvR
R(	tproxytschemetr_schemet	authoritytendtuserinfothostporttusertpassword((s/sys/lib/python/urllib2.pyt_parse_proxyHs2





R�cBs#eZdZdd�Zd�ZRS(idcCs�|djo
t�}nt|d�p
td�||_x=|i�D]/\}}t|d||||id��qJWdS(Nthas_keysproxies must be a mappings%s_opencSs||||�S(((trR�R:R�((s/sys/lib/python/urllib2.pyt<lambda>�s(RRRFtAssertionErrortproxiesR=tsetattrRq(RR�R:R((s/sys/lib/python/urllib2.pyR �s

	

cCs�|i�}t|�\}}}}|djo
|}n|oP|oIdt|�t|�f}	ti|	�i�}
|idd|
�nt|�}|i||�||jodSn|i	i
|�SdS(Ns%s:%ssProxy-authorizationsBasic (RTR�RRtbase64t	b64encodetstripR>RXR�R(RR�R�R:t	orig_typet
proxy_typeR�R�R�t	user_passtcreds((s/sys/lib/python/urllib2.pyRq�s


N(R"R#R�RR Rq(((s/sys/lib/python/urllib2.pyR��s
tHTTPPasswordMgrcBs8eZd�Zd�Zd�Zed�Zd�ZRS(cCs
h|_dS(N(tpasswd(R((s/sys/lib/python/urllib2.pyR �sc	Cs�t|t�o
|g}n||ijoh|i|<nx^ttfD]P}tg}|D]}||i||�q_~�}||f|i||<qKWdS(N(R�R�R�R}Rettuplet
reduce_uri(	RtrealmR�R�R�tdefault_portt_[1]tutreduced_uri((s/sys/lib/python/urllib2.pytadd_password�s

0c	Cs�|ii|h�}xottfD]a}|i||�}xF|i�D]8\}}x)|D]!}|i||�o|SqZqZWqGWq"WdS(N(NN(R�R`R}ReR�t	iteritemst	is_suburiR(	RR�tauthuritdomainsR�treduced_authurituristauthinfoR�((s/sys/lib/python/urllib2.pytfind_user_password�s

c
Cs�ti|�}|do)|d}|d}|dpd}nd
}|}d}t|�\}}|o`|d
joS|d
j	oFhdd<dd<i|�}	|	d
j	od	||	f}q�n||fS(s@Accept authority or URI and extract only the authority and path.iiiR�iPR�i�R�s%s:%dN(R0turlsplitRRR`(
RR�R�tpartsR�R�tpathR6R;tdport((s/sys/lib/python/urllib2.pyR��s 

!
	
cCsx||jotSn|d|djotSnti|d|df�}t|�t|d�jotSntS(scCheck if test is below base in a URI tree

        Both args must be URIs in reduced form.
        ii(R}Ret	posixpathtcommonprefixR�(Rtbasettesttcommon((s/sys/lib/python/urllib2.pyR��s
(R"R#R R�R�R}R�R�(((s/sys/lib/python/urllib2.pyR��s
			
tHTTPPasswordMgrWithDefaultRealmcBseZd�ZRS(cCsIti|||�\}}|dj	o||fSnti|d|�S(N(R�R�R(RR�R�R�R�((s/sys/lib/python/urllib2.pyR��s

(R"R#R�(((s/sys/lib/python/urllib2.pyR	�stAbstractBasicAuthHandlercBs;eZeidei�Zdd�Zd�Zd�Z	RS(s)(?:.*,)*[ 	]*([^ 	]+)[ 	]+realm="([^"]*)"cCs6|djo
t�}n||_|ii|_dS(N(RR�R�R�(Rtpassword_mgr((s/sys/lib/python/urllib2.pyR 
s

	cCsz|i|d�}|o]tii|�}|o@|i�\}}|i�djo|i|||�SqrqvndS(Ntbasic(R`RR
trxtsearchtgroupsR4tretry_http_basic_auth(RtauthreqR6R�R<tmoR�R�((s/sys/lib/python/urllib2.pythttp_error_auth_reqedscCs�|ii||�\}}|dj	owd||f}dti|�i�}|ii|id�|jodSn|i	|i|�|i
i|�SndSdS(Ns%s:%ssBasic %s(R�R�RR�R�R�R<R`tauth_headerR>R�R(RR6R�R�R�tpwtrawtauth((s/sys/lib/python/urllib2.pyRs
N(
R"R#tretcompiletIR
RR RR(((s/sys/lib/python/urllib2.pyR
�s	tHTTPBasicAuthHandlercBseZdZd�ZRS(t
AuthorizationcCs"|i�}|id|||�S(Nswww-authenticate(R/R(RR�R(R%R&R<R((s/sys/lib/python/urllib2.pythttp_error_401-s	(R"R#RR(((s/sys/lib/python/urllib2.pyR)stProxyBasicAuthHandlercBseZdZd�ZRS(sProxy-authorizationcCs"|i�}|id|||�S(Nsproxy-authenticate(RVR(RR�R(R%R&R<R�((s/sys/lib/python/urllib2.pythttp_error_4077s	(R"R#RR(((s/sys/lib/python/urllib2.pyR3scCs�tiid�o-td�}|i|�}|i�|SnGg}t|�D]}|tti	dd��qQ~}di
|�SdS(sReturn n random bytes.s/dev/urandomiiR-N(tosRtexistsRR�R�trangetchrtrandomt	randrangetjoin(tntftsR�R�tL((s/sys/lib/python/urllib2.pytrandombytesAs
9tAbstractDigestAuthHandlercBsSeZdd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(	cCsH|djo
t�}n||_|ii|_d|_d|_dS(Ni(RR�R�R�tretriedtnonce_count(RR�((s/sys/lib/python/urllib2.pyR Zs

		cCs
d|_dS(Ni(R-(R((s/sys/lib/python/urllib2.pytreset_retry_countbscCs�|i|d�}|idjo"t|i�dd|d��n|id7_|o;|i�d}|i�djo|i||�Sq�ndS(Nii�sdigest auth failediitdigest(R`RR-R$R/tsplitR4tretry_http_digest_auth(RRR6R�R<RR�((s/sys/lib/python/urllib2.pyRescCs�|idd�\}}tt|��}|i||�}|o^d|}|ii|id�|jodSn|i|i|�|i	i
|�}|SndS(NR�is	Digest %s(R1tparse_keqv_listtparse_http_listtget_authorizationR<R`RRR]R�R(RR�Rttokent	challengetchaltauth_valtresp((s/sys/lib/python/urllib2.pyR2vs
cCs<tid|i|ti�td�f�i�}|d S(Ns%s:%s:%s:%sii(thashlibtsha1R.ttimetctimeR+t	hexdigest(Rtnoncetdig((s/sys/lib/python/urllib2.pyt
get_cnonce�sc
CsKyK|d}|d}|id�}|idd�}|idd�}Wntj
odSnX|i|�\}}	|djodSn|ii||i��\}
}|
djodSn|i�o|i|i	�|�}nd}d|
||f}
d|i
�|i�f}|d	joc|id
7_d|i}|i
|�}d||||||�f}|	||
�|�}n7|djo)|	||
�d|||�f�}nd
|
|||i�|f}|o|d|7}n|o|d|7}n|d|7}|o|d||f7}n|S(NR�R@tqopt	algorithmtMD5topaques%s:%s:%ss%s:%sRis%08xs%s:%s:%s:%s:%ss>username="%s", realm="%s", nonce="%s", uri="%s", response="%s"s
, opaque="%s"s
, digest="%s"s, algorithm="%s"s, qop=auth, nc=%s, cnonce="%s"(R`RtKeyErrortget_algorithm_implsR�R�R/RNtget_entity_digestRQRORWR.RB(RR�R8R�R@RCRDRFtHtKDR�RtentdigtA1tA2tncvaluetcnoncetnoncebittrespdigR((s/sys/lib/python/urllib2.pyR5�sN

	
!




)
csM|djo
d��n|djo
d��n�fd�}�|fS(NREcSsti|�i�S((R;tmd5R?(tx((s/sys/lib/python/urllib2.pyR��stSHAcSsti|�i�S((R;R<R?(RT((s/sys/lib/python/urllib2.pyR��scs�d||f�S(s%s:%s((R)td(RJ(s/sys/lib/python/urllib2.pyR��s((RRDRK((RJs/sys/lib/python/urllib2.pyRH�s



cCsdS(N(R(RRR8((s/sys/lib/python/urllib2.pyRI�sN(R"R#RR R/RR2RBR5RHRI(((s/sys/lib/python/urllib2.pyR,Os				
	8	
tHTTPDigestAuthHandlercBs#eZdZdZdZd�ZRS(s�An authentication protocol defined by RFC 2069

    Digest authentication improves on basic authentication because it
    does not transmit passwords in the clear.
    Ri�cCs?ti|i��d}|id|||�}|i�|S(Niswww-authenticate(R0R/RR/(RR�R(R%R&R<R6tretry((s/sys/lib/python/urllib2.pyR�s
	
(R"R#R+RR�R(((s/sys/lib/python/urllib2.pyRW�stProxyDigestAuthHandlercBseZdZdZd�ZRS(sProxy-Authorizationi�cCs2|i�}|id|||�}|i�|S(Nsproxy-authenticate(RVRR/(RR�R(R%R&R<R6RX((s/sys/lib/python/urllib2.pyR�s
	
(R"R#RR�R(((s/sys/lib/python/urllib2.pyRY�stAbstractHTTPHandlercBs/eZdd�Zd�Zd�Zd�ZRS(icCs
||_dS(N(t_debuglevel(Rt
debuglevel((s/sys/lib/python/urllib2.pyR �scCs
||_dS(N(R[(Rtlevel((s/sys/lib/python/urllib2.pytset_http_debuglevel�sc
Cs8|i�}|ptd��n|i�ob|i�}|id�p|idd�n|id�p|iddt|��q�nt|i��\}}t	|�\}}|id�p|id|p|�nxJ|i
iD]<\}}	|i�}|i|�p|i||	�q��S(Ns
no host givensContent-types!application/x-www-form-urlencodedsContent-lengths%dR.(
RVRRNRQR_R]R�RRWRR�RhR[(
RR5R6RR�tseltsel_hosttsel_pathRJRC((s/sys/lib/python/urllib2.pytdo_request_�s,

c
Cs8|i�}|ptd��n||�}|i|i�t|i�}|i|i�d|d<td�|i�D��}y5|i	|i
�|i�|i|�|i
�}Wn$tij
o}t|��nX|i|_ti|dt�}t||i|i��}	|i|	_|i|	_|	S(s�Return an addinfourl object for the request, using http_class.

        http_class must implement the HTTPConnection API from httplib.
        The addinfourl return value is a file-like object.  It also
        has methods and attributes including:
            - info(): return a mimetools.Message object for the headers
            - geturl(): return the original request URL
            - code: HTTP status code
        s
no host givenR�t
Connectioncss+x$|]\}}|i�|fVqWdS(N(ttitle(t.0RJR\((s/sys/lib/python/urllib2.pys	<genexpr>.s(RVRtset_debuglevelR[R�R<RcR?R=R5RORWRtgetresponsetsocketRsR�trecvt_fileobjectR}RR&R/tstatusR%R(
Rt
http_classR�R6R�R<R�terrR(R:((s/sys/lib/python/urllib2.pyRps*

%
(R"R#R R^RbRp(((s/sys/lib/python/urllib2.pyRZ�s		R�cBseZd�ZeiZRS(cCs|iti|�S(N(RpR�tHTTPConnection(RR�((s/sys/lib/python/urllib2.pyt	http_openKs(R"R#RoRZRbthttp_request(((s/sys/lib/python/urllib2.pyR�Is	R�R�cBseZd�ZeiZRS(cCs|iti|�S(N(RpR�tHTTPSConnection(RR�((s/sys/lib/python/urllib2.pyt
https_openSs(R"R#RrRZRbt
https_request(((s/sys/lib/python/urllib2.pyR�Qs	tHTTPCookieProcessorcBs2eZdd�Zd�Zd�ZeZeZRS(cCs6ddk}|djo|i�}n||_dS(Ni�(t	cookielibRt	CookieJart	cookiejar(RRwRu((s/sys/lib/python/urllib2.pyR Ys
cCs|ii|�|S(N(Rwtadd_cookie_header(RR5((s/sys/lib/python/urllib2.pyRp_scCs|ii||�|S(N(Rwtextract_cookies(RR5Rt((s/sys/lib/python/urllib2.pyR�csN(R"R#RR RpR�RsR�(((s/sys/lib/python/urllib2.pyRtXs
		R�cBseZd�ZRS(cCs |i�}td|��dS(Nsunknown url type: %s(RTR(RR�R:((s/sys/lib/python/urllib2.pyR�ks(R"R#R�(((s/sys/lib/python/urllib2.pyR�jscCsph}xc|D][}|idd�\}}|ddjo"|ddjo|dd!}n|||<q
W|S(s>Parse list of key=value strings where keys are not duplicated.t=iit"i�(R1(tltparsedtelttktv((s/sys/lib/python/urllib2.pyR3os"cCsg}d}t}}x�|D]�}|o||7}t}qn|oB|djo
t}qn|djo
t}n||7}qn|djo|i|�d}qn|djo
t}n||7}qW|o|i|�ng}|D]}||i�q�S(spParse 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.
    R-s\R{t,(ReR}R|R�(R)trestparttescapeRtcurR�((s/sys/lib/python/urllib2.pyR4ys6	









R�cBs)eZd�ZdZd�Zd�ZRS(cCs_|i�}|d djo1|dd!djod|_|ii|�Sn|i|�SdS(Nis//iR�tftp(RWR:R�Rtopen_local_file(RR�R((s/sys/lib/python/urllib2.pyt	file_open�s
%	cCsttidjo]y+tid�titi��ft_Wqmtij
otid�ft_qmXntiS(NR(R�tnamesRRht
gethostbynametgethostnametgaierror(R((s/sys/lib/python/urllib2.pyt	get_names�sc
Cs%ddk}ddk}|i�}|i�}t|�}ti|�}|i}|ii	|i
dt�}	|i|�d}
t
itd|
pd||	f��}|ot|�\}}n|p$|o=ti|�|i�jo!tt|d�|d|�Sntd��dS(	Ni�tusegmtis6Content-type: %s
Content-length: %d
Last-modified: %s
s
text/plaintrbsfile:sfile not on local host(temail.Utilst	mimetypesRVRWRR tstattst_sizetUtilst
formatdatetst_mtimeR}t
guess_typet	mimetoolstMessageRRRhR�R�RRR(
RR�temailR�R6tfilet	localfiletstatstsizetmodifiedtmtypeR<R;((s/sys/lib/python/urllib2.pyR��s&		$N(R"R#R�RR�R�R�(((s/sys/lib/python/urllib2.pyR��s			
R�cBseZd�Zd�ZRS(cCs�ddk}ddk}|i�}|p
td�nt|�\}}|djo
|i}n
t|�}t|�\}}|ot	|�\}}nd}t
|�}t
|pd�}t
|pd�}yti|�}Wn$ti
j
o}t|��nXt|i��\}	}
|	id�}tt
|�}|d |d}}|o|do|d}ny3|i|||||�}
|odpd	}xP|
D]H}t|�\}}|i�d
jo|djo|i�}q�q�W|
i||�\}}d}|i|i��d}|o|d|7}n|dj	o|djo|d|7}nt|�}ti|�}t|||i��SWn4|ij
o%}td|fti �d�nXdS(Ni�s	ftp errors
no host givenR-R�iiRtDR:tatAR�RVsContent-type: %s
sContent-length: %d
i(s	ftp errors
no host given(R�R�R�RRVR�(!tftplibR�RVtIOErrorRRtFTP_PORTRxR
RRRhR�RsRR
RWR1tmaptconnect_ftpRR4tuppertretrfileR�R/RR�R�Rt
all_errorstsystexc_info(RR�R�R�R6R;R�R�R&RtattrstdirsR�tfwR:RIRCR(tretrlenR<R�tsf((s/sys/lib/python/urllib2.pytftp_open�s^



cCst|||||�}|S(N(R(RR�R�R6R;R�R�((s/sys/lib/python/urllib2.pyR�s(R"R#R�R�(((s/sys/lib/python/urllib2.pyR��s	5tCacheFTPHandlercBs5eZd�Zd�Zd�Zd�Zd�ZRS(cCs1h|_h|_d|_d|_d|_dS(Nii<i(tcachettimeouttsoonesttdelayt	max_conns(R((s/sys/lib/python/urllib2.pyR 
s
				cCs
||_dS(N(R�(Rtt((s/sys/lib/python/urllib2.pyt
setTimeoutscCs
||_dS(N(R�(RR�((s/sys/lib/python/urllib2.pytsetMaxConnsscCs�|||di|�f}||ijoti�|i|i|<n:t|||||�|i|<ti�|i|i|<|i�|i|S(NR�(R&R�R=R�R�Rtcheck_cache(RR�R�R6R;R�RB((s/sys/lib/python/urllib2.pyR�s
cCsti�}|i|joZxW|ii�D]B\}}||jo)|i|i�|i|=|i|=q,q,Wnt|ii��|_t|i�|i	joexF|ii�D]5\}}||ijo|i|=|i|=Pq�q�Wt|ii��|_ndS(N(
R=R�R�R=R�R�tmintvaluesR�R�(RR�RR�((s/sys/lib/python/urllib2.pyR�$s"



	(R"R#R R�R�R�R�(((s/sys/lib/python/urllib2.pyR�
s
				
t
GopherHandlercBseZd�ZRS(cCs�ddk}|i�}|ptd��nt|�}|i�}t|�\}}t|�\}}t|�}|o%t|�}|i|||�}n|i||�}t	|t
�|i��S(Ni�s
no host given(t	gopherlibRVR,RRWRR	t
send_queryt
send_selectorRRR/(RR�R�R6tselectorR:tqueryR(((s/sys/lib/python/urllib2.pytgopher_open9s(R"R#R�(((s/sys/lib/python/urllib2.pyR�8s(((((((OR+R�R;R�R�R RR$RRhR�R=R0Rzt	cStringIORtImportErrorturllibRRRRRRRRR	R
RRR
RRRRRtversionRgRRRRR�RR$R,RR2R7R8RfRR�R�R�R�R�R�R�R	R
RRR+R,RWRYRZR�RFR�RtR�R3R4R�R�R�R�(((s/sys/lib/python/urllib2.pys<module>Gstd
	
	e�'S	H%@
*
	�X	
	++;.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.