Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/
Upload File :
Current File : //usr/lib/python2.7/urllib2.pyc


|_c@s	dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
yddlmZWn!ek
rddlmZnXddlmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZm Z m!Z!m"Z"e
j#d Z$da&de	j'dZ(dZ)d	e*fd
YZ+de+efdYZ,ej-d
Z.dZ/ddDdYZ0ddEdYZ1dZ2ddFdYZ3de3fdYZ4de3fdYZ5de3fdYZ6dZ7de3fdYZ8ddGd YZ9d!e9fd"YZ:d#dHd$YZ;d%e;e3fd&YZ<d'e;e3fd(YZ=d)Z>d*dId+YZ?d,e3e?fd-YZ@d.e3e?fd/YZAd0e3fd1YZBd2eBfd3YZCeDed4r|d5eBfd6YZEnd7e3fd8YZFd9e3fd:YZGd;ZHd<ZId=ZJd>e3fd?YZKd@e3fdAYZLdBeLfdCYZMdS(Js!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 -- 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 --

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='PDQ Application',
                      uri='https://mahler:8092/site-updates.py',
                      user='klem',
                      passwd='geheim$parole')

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/')


iN(tStringIO(
tunwraptunquotet	splittypet	splithosttquotet
addinfourlt	splitporttsplittagt	splitattrt
ftpwrappert	splitusertsplitpasswdt
splitvalue(t	localhostturl2pathnamet
getproxiestproxy_bypassicCs+tdkrtantj|||S(N(t_openertNonetbuild_openertopen(turltdatattimeout((s/usr/lib/python2.7/urllib2.pyturlopenzscCs
|adS(N(R(topener((s/usr/lib/python2.7/urllib2.pytinstall_openerstURLErrorcBseZdZdZRS(cCs|f|_||_dS(N(targstreason(tselfR((s/usr/lib/python2.7/urllib2.pyt__init__scCsd|jS(Ns<urlopen error %s>(R(R((s/usr/lib/python2.7/urllib2.pyt__str__s(t__name__t
__module__R R!(((s/usr/lib/python2.7/urllib2.pyRs	t	HTTPErrorcBs8eZdZejZdZdZedZRS(sBRaised when HTTP error occurs, but also acts like non-error returncCsV||_||_||_||_||_|dk	rR|j||||ndS(N(tcodetmsgthdrstfptfilenameRt_HTTPError__super_init(RRR%R&R'R(((s/usr/lib/python2.7/urllib2.pyR s					cCsd|j|jfS(NsHTTP Error %s: %s(R%R&(R((s/usr/lib/python2.7/urllib2.pyR!scCs|jS(N(R&(R((s/usr/lib/python2.7/urllib2.pyRs(	R"R#t__doc__RR R*R!tpropertyR(((s/usr/lib/python2.7/urllib2.pyR$s
		
	s:\d+$cCs_|j}tj|d}|dkr@|jdd}ntjd|d}|jS(sReturn 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/usr/lib/python2.7/urllib2.pytrequest_hoststRequestcBseZdidedZdZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZddZdZRS(cCst||_t|j\|_|_d|_d|_d|_d|_||_	i|_
x*|jD]\}}|j||qmWi|_
|dkrt|}n||_||_dS(N(Rt_Request__originalRt_Request__fragmentRttypeR6tportt_tunnel_hostRtheaderstitemst
add_headertunredirected_hdrsR7torigin_req_hosttunverifiable(RRRR>RBRCtkeytvalue((s/usr/lib/python2.7/urllib2.pyR s								cCs^|d dkrQ|d}ttd|rQt|d|t||Snt|dS(Nit_Request__r_tget_(thasattrR8tgetattrtAttributeError(Rtattrtname((s/usr/lib/python2.7/urllib2.pyt__getattr__s
cCs|jrdSdSdS(NtPOSTtGET(thas_data(R((s/usr/lib/python2.7/urllib2.pyt
get_methodscCs
||_dS(N(R(RR((s/usr/lib/python2.7/urllib2.pytadd_datascCs
|jdk	S(N(RR(R((s/usr/lib/python2.7/urllib2.pyRPscCs|jS(N(R(R((s/usr/lib/python2.7/urllib2.pytget_datascCs(|jrd|j|jfS|jSdS(Ns%s#%s(R:R9(R((s/usr/lib/python2.7/urllib2.pyR/s	cCsV|jdkrOt|j\|_|_|jdkrOtd|jqOn|jS(Nsunknown url type: %s(R;RRR9t_Request__r_typet
ValueError(R((s/usr/lib/python2.7/urllib2.pytget_types
cCsR|jdkrKt|j\|_|_|jrKt|j|_qKn|jS(N(R6RRRTt_Request__r_hostR(R((s/usr/lib/python2.7/urllib2.pytget_hosts
	cCs|jS(N(RW(R((s/usr/lib/python2.7/urllib2.pytget_selectorscCsJ|jdkr(|jr(|j|_n||_|j|_||_dS(Nthttps(R;R=R6R9RW(RR6R;((s/usr/lib/python2.7/urllib2.pyt	set_proxys
	cCs|j|jkS(N(RWR9(R((s/usr/lib/python2.7/urllib2.pyt	has_proxyscCs|jS(N(RB(R((s/usr/lib/python2.7/urllib2.pytget_origin_req_hostscCs|jS(N(RC(R((s/usr/lib/python2.7/urllib2.pytis_unverifiablescCs||j|j<dS(N(R>t
capitalize(RRDtval((s/usr/lib/python2.7/urllib2.pyR@scCs||j|j<dS(N(RAR_(RRDR`((s/usr/lib/python2.7/urllib2.pytadd_unredirected_header!scCs||jkp||jkS(N(R>RA(Rtheader_name((s/usr/lib/python2.7/urllib2.pyt
has_header%scCs"|jj||jj||S(N(R>tgetRA(RRbtdefault((s/usr/lib/python2.7/urllib2.pyR1)s	cCs)|jj}|j|j|jS(N(RAtcopytupdateR>R?(RR'((s/usr/lib/python2.7/urllib2.pytheader_items.sN(R"R#RtFalseR RMRQRRRPRSR/RVRXRYR[R\R]R^R@RaRcR1Rh(((s/usr/lib/python2.7/urllib2.pyR8s(																	tOpenerDirectorcBsSeZdZdZdZdZdejdZ	ddZ
dZRS(cCsMdt}d|fg|_g|_i|_i|_i|_i|_dS(NsPython-urllib/%ss
User-agent(t__version__t
addheadersthandlersthandle_openthandle_errortprocess_responsetprocess_request(Rtclient_version((s/usr/lib/python2.7/urllib2.pyR 4s
				cCst|ds(tdt|nt}xet|D]W}|dkrSq;n|jd}|| }||d}|jdr|jd|d}||d}yt|}Wntk
rnX|j	j
|i}	|	|j	|<n]|d	kr|}|j}	n?|d
kr3|}|j}	n!|dkr;|}|j
}	nq;|	j|g}
|
rtj|
|n
|
j|t}q;W|rtj|j||j|ndS(
Nt
add_parents%expected BaseHandler instance, got %rtredirect_requesttdo_opent
proxy_opent_iterrorRtresponseR5(sredirect_requestsdo_opens
proxy_open(RHt	TypeErrorR;Ritdirtfindt
startswithtintRURoRdRnRpRqt
setdefaulttbisecttinsorttappendtTrueRmRs(Rthandlertaddedtmethtitprotocolt	conditiontjtkindtlookupRm((s/usr/lib/python2.7/urllib2.pytadd_handler?sJ



cCsdS(N((R((s/usr/lib/python2.7/urllib2.pytclosensc	GsR|j|d}x9|D]1}t||}||}|dk	r|SqWdS(N((RdRIR(	RtchainRt	meth_nameRRmRtfunctresult((s/usr/lib/python2.7/urllib2.pyt_call_chainrs
c
Cst|tr!t||}n"|}|dk	rC|j|n||_|j}|d}x8|jj|gD]!}t	||}||}qxW|j
||}	|d}x;|jj|gD]$}t	||}|||	}	qW|	S(Nt_requestt	_response(t
isinstancet
basestringR8RRRRRVRqRdRIt_openRp(
RtfullurlRRtreqRRt	processorRRy((s/usr/lib/python2.7/urllib2.pyR~s"	

cCss|j|jdd|}|r%|S|j}|j|j||d|}|rZ|S|j|jdd|S(NRetdefault_openRtunknowntunknown_open(RRnRV(RRRRR((s/usr/lib/python2.7/urllib2.pyRs
cGs|d
kr<|jd}|d}d|}d}|}n|j}|d}d}|||f|}|j|}|r|S|r|dd	f|}|j|SdS(NthttpRZis
http_error_%sit_erroriRethttp_error_default(Rshttps(RoR(RtprotoRtdictRthttp_errt	orig_argsR((s/usr/lib/python2.7/urllib2.pyRxs 


		
N(R"R#R RRRRtsockett_GLOBAL_DEFAULT_TIMEOUTRRRx(((s/usr/lib/python2.7/urllib2.pyRj3s		/		csRddlfd}t}tttttttt	g}t
tdra|jt
nt}xl|D]d}x[|D]S}||rt||r|j|qq~t||r~|j|q~q~WqqWx|D]}|j|qWx|D]}|j|qWx3|D]+}||r=|}n|j|qW|S(s+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.
    iNcst|jtfS(N(Rt	ClassTypeR;(tobj(ttypes(s/usr/lib/python2.7/urllib2.pytisclassstHTTPS(RRjtProxyHandlertUnknownHandlertHTTPHandlertHTTPDefaultErrorHandlertHTTPRedirectHandlert
FTPHandlertFileHandlertHTTPErrorProcessorRHthttplibRtHTTPSHandlertsett
issubclasstaddRtremoveR(RmRRtdefault_classestskiptklasstcheckth((Rs/usr/lib/python2.7/urllib2.pyRs2				




tBaseHandlercBs)eZdZdZdZdZRS(icCs
||_dS(N(tparent(RR((s/usr/lib/python2.7/urllib2.pyRsscCsdS(N((R((s/usr/lib/python2.7/urllib2.pyRscCs#t|dstS|j|jkS(Nt
handler_order(RHRR(Rtother((s/usr/lib/python2.7/urllib2.pyt__lt__s(R"R#RRsRR(((s/usr/lib/python2.7/urllib2.pyRs		RcBs#eZdZdZdZeZRS(sProcess HTTP error responses.icCsd|j|j|j}}}d|ko7dkns`|jjd|||||}n|S(Nii,R(R%R&tinfoRRx(RR5RyR%R&R'((s/usr/lib/python2.7/urllib2.pyt
http_responses
 	(R"R#R+RRthttps_response(((s/usr/lib/python2.7/urllib2.pyRs	RcBseZdZRS(cCs"t|j||||dS(N(R$R/(RRR(R%R&R'((s/usr/lib/python2.7/urllib2.pyRs(R"R#R(((s/usr/lib/python2.7/urllib2.pyR
sRcBs:eZdZdZdZdZeZZZdZ	RS(ii
c	Cs|j}|dkr$|dks<|dkr|dkr|jdd	}td
|jjD}t|d|d|jd
tSt|j	||||dS(sReturn 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/i3ROtHEADRNt s%20css3|])\}}|jdkr||fVqdS(scontent-lengthscontent-typeN(scontent-lengthscontent-type(R4(t.0tktv((s/usr/lib/python2.7/urllib2.pys	<genexpr>-s	R>RBRCN(i-i.i/i3(sGETR(i-i.i/(
RQtreplaceRR>R?R8R]RR$R/(	RRR(R%R&R>tnewurltmt
newheaders((s/usr/lib/python2.7/urllib2.pyRts
	c	Csd|kr"|jdd}n&d|krD|jdd}ndStj|}|jsyt|}d|d<ntj|}tj|j|}|j}|jdp|jdp|jdst	|||d	|||n|j
||||||}	|	dkr*dSt|d
r|j
}
|	_
|
j|d|jksyt|
|jkrt	|j||j|||qni}
|	_
|_
|
j|dd|
|<|j|j|jj|	d|jS(
Ntlocationiturit/ishttp://shttps://sftp://s) - Redirection to url '%s' is not allowedt
redirect_dictiR(t
getheadersR0tpathtlistt
urlunparseturljoinR/R4R}R$RtRRHRRdtmax_repeatstlentmax_redirectionstinf_msgtreadRRRR(RRR(R%R&R>Rturlpartstnewurl_lowertnewtvisited((s/usr/lib/python2.7/urllib2.pythttp_error_302;sB	
	

soThe HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
(
R"R#RRRtRthttp_error_301thttp_error_303thttp_error_307R(((s/usr/lib/python2.7/urllib2.pyRs	"	8c	Cst|\}}|jds0d}|}nV|jdsRtd|n|jdd}|dkryd}n|d|!}t|\}}|dk	rt|\}}n
d}}||||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')

    Rs//sproxy URL with no authority: %riiN(RR}RRUR|RR(	tproxytschemetr_schemet	authoritytendtuserinfothostporttusertpassword((s/usr/lib/python2.7/urllib2.pyt_parse_proxyzs2		

RcBs#eZdZddZdZRS(idcCs|dkrt}nt|ds3td||_x=|jD]/\}}t|d||||jdqIWdS(Nthas_keysproxies must be a mappings%s_opencSs||||S(N((trRR;R((s/usr/lib/python2.7/urllib2.pyt<lambda>s(RRRHtAssertionErrortproxiesR?tsetattrRv(RRR;R((s/usr/lib/python2.7/urllib2.pyR s	
cCs|j}t|\}}}}|dkr9|}n|jrUt|jrUdS|r|rdt|t|f}	tj|	j}
|j	dd|
nt|}|j
||||ks|dkrdS|jj|d|j
SdS(Ns%s:%ssProxy-authorizationsBasic RZR(RVRRR6RRtbase64t	b64encodetstripR@R[RRR(RRRR;t	orig_typet
proxy_typeRRRt	user_passtcreds((s/usr/lib/python2.7/urllib2.pyRvs	N(R"R#RRR Rv(((s/usr/lib/python2.7/urllib2.pyRs
tHTTPPasswordMgrcBs8eZdZdZdZedZdZRS(cCs
i|_dS(N(tpasswd(R((s/usr/lib/python2.7/urllib2.pyR scCst|tr|g}n||jkr:i|j|<nxVttfD]H}tg|D]}|j||^qW}||f|j||<qGWdS(N(RRRRRittuplet
reduce_uri(RtrealmRRRtdefault_porttutreduced_uri((s/usr/lib/python2.7/urllib2.pytadd_passwords(c	Cs|jj|i}xjttfD]\}|j||}xA|jD]3\}}x$|D]}|j||rZ|SqZWqGWq"WdS(N(NN(RRdRRiRt	iteritemst	is_suburiR(	RRtauthuritdomainsRtreduced_authurituristauthinfoR((s/usr/lib/python2.7/urllib2.pytfind_user_passwords
c
Cstj|}|dr@|d}|d}|dp:d}nd
}|}d}t|\}}|r|d
kr|d
k	ridd6dd6j|}	|	d
k	rd	||	f}qn||fS(s@Accept authority or URI and extract only the authority and path.iiiRiPRiRZs%s:%dN(R0turlsplitRRRd(
RRRtpartsRRRR6R<tdport((s/usr/lib/python2.7/urllib2.pyRs 




	cCsi||krtS|d|dkr(tStj|d|df}t|t|dkretStS(scCheck if test is below base in a URI tree

        Both args must be URIs in reduced form.
        ii(RRit	posixpathtcommonprefixR(Rtbasettesttcommon((s/usr/lib/python2.7/urllib2.pyRs(R"R#R RRRRR(((s/usr/lib/python2.7/urllib2.pyRs
			
tHTTPPasswordMgrWithDefaultRealmcBseZdZRS(cCsDtj|||\}}|dk	r1||fStj|d|S(N(RRR(RRR	RR((s/usr/lib/python2.7/urllib2.pyR/s

(R"R#R(((s/usr/lib/python2.7/urllib2.pyR-stAbstractBasicAuthHandlercBsDeZejdejZddZdZdZ	dZ
RS(s0(?:^|,)[ 	]*([^ 	]+)[ 	]+realm=(["']?)([^"']*)\2cCs=|dkrt}n||_|jj|_d|_dS(Ni(RRRRtretried(Rtpassword_mgr((s/usr/lib/python2.7/urllib2.pyR Ls
	cCs
d|_dS(Ni(R(R((s/usr/lib/python2.7/urllib2.pytreset_retry_countSsc
Cs|j|d}|jdkrBt|jdd|dn|jd7_|rtjj|}|r|j\}}}|j	dkr|j
|||}	|	r|	jdkrd|_n|	SqndS(Niisbasic auth faileditbasici(RdRRR$R/RtrxtsearchtgroupsR4tretry_http_basic_authR%(
RtauthreqR6RR>tmoRRRRy((s/usr/lib/python2.7/urllib2.pythttp_error_auth_reqedVscCs|jj||\}}|dk	rd||f}dtj|j}|jj|jd|krrdS|j	|j||j
j|d|jSdSdS(Ns%s:%ssBasic %sR(
RRRRRRR>Rdtauth_headerRaRRR(RR6RRRtpwtrawtauth((s/usr/lib/python2.7/urllib2.pyR msN(R"R#tretcompiletIRRR RR#R (((s/usr/lib/python2.7/urllib2.pyR7s			tHTTPBasicAuthHandlercBseZdZdZRS(t
AuthorizationcCs2|j}|jd|||}|j|S(Nswww-authenticate(R/R#R(RRR(R%R&R>RRy((s/usr/lib/python2.7/urllib2.pythttp_error_401~s
	
(R"R#R$R-(((s/usr/lib/python2.7/urllib2.pyR+zstProxyBasicAuthHandlercBseZdZdZRS(sProxy-authorizationcCs2|j}|jd|||}|j|S(Nsproxy-authenticate(RXR#R(RRR(R%R&R>RRy((s/usr/lib/python2.7/urllib2.pythttp_error_407s
	
(R"R#R$R/(((s/usr/lib/python2.7/urllib2.pyR.scCs}tjjdr;td}|j|}|j|Sgt|D]}ttj	dd^qH}dj
|SdS(sReturn n random bytes.s/dev/urandomiiR-N(tosRtexistsRRRtrangetchrtrandomt	randrangetjoin(tntftsRtL((s/usr/lib/python2.7/urllib2.pytrandombytess
1tAbstractDigestAuthHandlercBsSeZddZdZdZdZdZdZdZ	dZ
RS(	cCsO|dkrt}n||_|jj|_d|_d|_d|_dS(Ni(RRRRRtnonce_countt
last_nonce(RR((s/usr/lib/python2.7/urllib2.pyR s			cCs
d|_dS(Ni(R(R((s/usr/lib/python2.7/urllib2.pyRscCs|j|d}|jdkrBt|jdd|dn|jd7_|r|jd}|jdkr|j||SndS(Niisdigest auth failediitdigest(RdRRR$R/tsplitR4tretry_http_digest_auth(RR$R6RR>R!R((s/usr/lib/python2.7/urllib2.pyR#scCs|jdd\}}tt|}|j||}|rd|}|jj|jd|krndS|j|j||j	j
|d|j}|SdS(NRis	Digest %sR(R@tparse_keqv_listtparse_http_listtget_authorizationR>RdR$RRaRRR(RRR'ttokent	challengetchaltauth_valtresp((s/usr/lib/python2.7/urllib2.pyRAs
cCs<tjd|j|tjtdfj}|d S(Ns%s:%s:%s:%sii(thashlibtsha1R=ttimetctimeR;t	hexdigest(Rtnoncetdig((s/usr/lib/python2.7/urllib2.pyt
get_cnoncescCsdyK|d}|d}|jd}|jdd}|jdd}Wntk
r_dSX|j|\}}	|dkrdS|jj||j\}
}|
dkrdS|jr|j|j	|}nd}d|
||f}
d|j
|jf}|d	kr||jkr?|j
d
7_
nd
|_
||_d|j
}|j|}d||||||f}|	||
|}nD|dkr|	||
d|||f}ntd
|d|
|||j|f}|r|d|7}n|r5|d|7}n|d|7}|r`|d||f7}n|S(NRROtqopt	algorithmtMD5topaques%s:%s:%ss%s:%sR'is%08xs%s:%s:%s:%s:%ssqop '%s' is not supported.s>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"(RdRtKeyErrortget_algorithm_implsRRR/RPtget_entity_digestRSRQRYR>R=RQR(RRRGRRORRRSRUtHtKDRR%tentdigtA1tA2tncvaluetcnoncetnoncebittrespdigR((s/usr/lib/python2.7/urllib2.pyRDsV


!		
(
csU|j}|dkr$dn|dkr<dnfd}|fS(NRTcSstj|jS(N(RJtmd5RN(tx((s/usr/lib/python2.7/urllib2.pyR$stSHAcSstj|jS(N(RJRKRN(Rc((s/usr/lib/python2.7/urllib2.pyR&scsd||fS(Ns%s:%s((R9td(RY(s/usr/lib/python2.7/urllib2.pyR(s(tupper(RRSRZ((RYs/usr/lib/python2.7/urllib2.pyRWscCsdS(N(R(RRRG((s/usr/lib/python2.7/urllib2.pyRX+sN(R"R#RR RR#RARQRDRWRX(((s/usr/lib/python2.7/urllib2.pyR<s					
	=	tHTTPDigestAuthHandlercBs#eZdZdZdZdZRS(sAn authentication protocol defined by RFC 2069

    Digest authentication improves on basic authentication because it
    does not transmit passwords in the clear.
    R,icCs?tj|jd}|jd|||}|j|S(Niswww-authenticate(R0R/R#R(RRR(R%R&R>R6tretry((s/usr/lib/python2.7/urllib2.pyR-:s
	
(R"R#R+R$RR-(((s/usr/lib/python2.7/urllib2.pyRg0stProxyDigestAuthHandlercBseZdZdZdZRS(sProxy-AuthorizationicCs2|j}|jd|||}|j|S(Nsproxy-authenticate(RXR#R(RRR(R%R&R>R6Rh((s/usr/lib/python2.7/urllib2.pyR/Gs
	
(R"R#R$RR/(((s/usr/lib/python2.7/urllib2.pyRiBstAbstractHTTPHandlercBs/eZddZdZdZdZRS(icCs
||_dS(N(t_debuglevel(Rt
debuglevel((s/usr/lib/python2.7/urllib2.pyR PscCs
||_dS(N(Rk(Rtlevel((s/usr/lib/python2.7/urllib2.pytset_http_debuglevelSsc
Cs:|j}|s!tdn|jr|j}|jds[|jddn|jds|jddt|qn|}|jrt|j	\}}t
|\}}n|jds|jd|nxH|jjD]:\}}	|j
}|j|s|j||	qqW|S(Ns
no host givensContent-types!application/x-www-form-urlencodedsContent-lengths%dR.(RXRRPRSRcRaRR\RRYRRRlR_(
RR5R6Rtsel_hostRtseltsel_pathRLRE((s/usr/lib/python2.7/urllib2.pytdo_request_Vs.
cs|j}|s!tdn||d|j}|j|jt|jjtfd|jj	Ddd<tdj	D|j
ri}d}|kr|||<|=n|j|j
d|ny)|j|j
|j|jWn,tjk
rP}|jt|n7Xy|jd	t}Wntk
r|j}nX|j|_tj|dt}	t|	|j|j}
|j|
_|j|
_|
S(
sReturn 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 givenRc3s-|]#\}}|kr||fVqdS(N((RRR(R>(s/usr/lib/python2.7/urllib2.pys	<genexpr>s	Rt
Connectioncss'|]\}}|j|fVqdS(N(ttitle(RRLR`((s/usr/lib/python2.7/urllib2.pys	<genexpr>ssProxy-AuthorizationR>t	buffering(RXRRtset_debuglevelRkRRARgR>R?R=t
set_tunnelR5RQRYRRRxRtgetresponseRRzRtrecvt_fileobjectRR&R/tstatusR%R(Rt
http_classRR6Rttunnel_headerstproxy_auth_hdrterrRR(RI((R>s/usr/lib/python2.7/urllib2.pyRuss@
,	
	
)


(R"R#R RnRrRu(((s/usr/lib/python2.7/urllib2.pyRjNs		RcBseZdZejZRS(cCs|jtj|S(N(RuRtHTTPConnection(RR((s/usr/lib/python2.7/urllib2.pyt	http_opens(R"R#RRjRrthttp_request(((s/usr/lib/python2.7/urllib2.pyRs	RRcBseZdZejZRS(cCs|jtj|S(N(RuRtHTTPSConnection(RR((s/usr/lib/python2.7/urllib2.pyt
https_opens(R"R#RRjRrt
https_request(((s/usr/lib/python2.7/urllib2.pyRs	tHTTPCookieProcessorcBs2eZddZdZdZeZeZRS(cCs4ddl}|dkr'|j}n||_dS(Ni(t	cookielibRt	CookieJart	cookiejar(RRR((s/usr/lib/python2.7/urllib2.pyR scCs|jj||S(N(Rtadd_cookie_header(RR5((s/usr/lib/python2.7/urllib2.pyRscCs|jj|||S(N(Rtextract_cookies(RR5Ry((s/usr/lib/python2.7/urllib2.pyRsN(R"R#RR RRRR(((s/usr/lib/python2.7/urllib2.pyRs
		RcBseZdZRS(cCs |j}td|dS(Nsunknown url type: %s(RVR(RRR;((s/usr/lib/python2.7/urllib2.pyRs(R"R#R(((s/usr/lib/python2.7/urllib2.pyRscCsmi}x`|D]X}|jdd\}}|ddkr[|ddkr[|dd!}n|||<q
W|S(s>Parse list of key=value strings where keys are not duplicated.t=iit"i(R@(tltparsedteltRR((s/usr/lib/python2.7/urllib2.pyRBs
 cCsg}d}t}}x|D]}|r?||7}t}qn|r|dkr]t}qn|dkrrt}n||7}qn|dkr|j|d}qn|dkrt}n||7}qW|r|j|ng|D]}|j^qS(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\Rt,(RiRRR(R9trestparttescapeRtcur((s/usr/lib/python2.7/urllib2.pyRCs4	


	

	cCs-ytj|SWntjk
r(dSXdS(N(Rt
gethostbynametgaierrorR(R6((s/usr/lib/python2.7/urllib2.pyt_safe_gethostbynamesRcBs)eZdZdZdZdZRS(cCsq|j}|d dkr`|dd!dkr`|jr`|jdkr`d|_|jj|S|j|SdS(Nis//iRRtftp(RYR6R;RRtopen_local_file(RRR((s/usr/lib/python2.7/urllib2.pyt	file_opens,	cCs|tjdkruy7ttjddtjtjdt_Wqutjk
rqtjdft_quXntjS(NRi(	RtnamesRRRtgethostbyname_extgethostnameRR(R((s/usr/lib/python2.7/urllib2.pyt	get_names)s$cCs[ddl}ddl}|j}|j}t|}ytj|}|j}|jj	|j
dt}	|j|d}
t
jtd|
pd||	f}|rt|\}}n|s|r(t||jkr(|rd||}
n
d|}
tt|d||
SWntk
rJ}t|nXtddS(	Nitusegmtis6Content-type: %s
Content-length: %d
Last-modified: %s
s
text/plainsfile://trbsfile not on local host(temail.utilst	mimetypesRXRYRR0tstattst_sizetutilst
formatdatetst_mtimeRt
guess_typet	mimetoolstMessageRRRRRRtOSErrorR(RRtemailRR6R)t	localfiletstatstsizetmodifiedtmtypeR>R<torigurlR&((s/usr/lib/python2.7/urllib2.pyR4s0		
N(R"R#RRRRR(((s/usr/lib/python2.7/urllib2.pyRs	
	RcBseZdZdZRS(cCsddl}ddl}|j}|s9tdnt|\}}|dkrc|j}nt|}t|\}}|rt	|\}}nd}t
|}|pd}|pd}ytj|}Wn"tj
k
r}t|nXt|j\}	}
|	jd}tt
|}|d |d}}|rg|drg|d}ny/|j||||||j}
|rdpd}xM|
D]E}t|\}}|jd	kr|dkr|j}qqW|
j||\}}d}|j|jd}|r;|d|7}n|dk	rd|dkrd|d|7}nt|}tj|}t|||jSWn0|jk
r}td|tj dnXdS(Nisftp error: no host givenR-RiiR*tDR;tatARResContent-type: %s
sContent-length: %d
s
ftp error: %si(RRRR*ReR(!tftplibRRXRRRtFTP_PORTR~RRRRRRxR	RYR@tmaptconnect_ftpRR
R4RftretrfileRR/RRRRt
all_errorstsystexc_info(RRRRR6R<RRR&RtattrstdirstfiletfwR;RKRER(tretrlenR>Rtsf((s/usr/lib/python2.7/urllib2.pytftp_openQs\
!
c	Cs%t||||||dt}|S(Nt
persistent(R
Ri(RRRR6R<RRR((s/usr/lib/python2.7/urllib2.pyRs	(R"R#RR(((s/usr/lib/python2.7/urllib2.pyRPs	5tCacheFTPHandlercBs>eZdZdZdZdZdZdZRS(cCs1i|_i|_d|_d|_d|_dS(Nii<i(tcacheRtsoonesttdelayt	max_conns(R((s/usr/lib/python2.7/urllib2.pyR s
				cCs
||_dS(N(R(Rtt((s/usr/lib/python2.7/urllib2.pyt
setTimeoutscCs
||_dS(N(R(RR((s/usr/lib/python2.7/urllib2.pytsetMaxConnsscCs|||dj||f}||jkrJtj|j|j|<n<t|||||||j|<tj|j|j|<|j|j|S(NR(R6RRLRRR
tcheck_cache(RRRR6R<RRRD((s/usr/lib/python2.7/urllib2.pyRs"
cCstj}|j|krrxT|jjD]@\}}||kr+|j|j|j|=|j|=q+q+Wnt|jj|_t|j|j	krxD|jjD]3\}}||jkr|j|=|j|=PqqWt|jj|_ndS(N(
RLRRR?RRtmintvaluesRR(RRRR((s/usr/lib/python2.7/urllib2.pyRs


cCsBx!|jjD]}|jqW|jj|jjdS(N(RRRtclearR(Rtconn((s/usr/lib/python2.7/urllib2.pytclear_caches
(R"R#R RRRRR(((s/usr/lib/python2.7/urllib2.pyRs				
	(((((((NR+RRJRRR0RR4R(RRRLR0Rt	cStringIORtImportErrorturllibRRRRRRRRR	R
RRR
RRRRtversionRkRRRRRtIOErrorRR$R)R2R7R8RjRRRRRRRRRRR+R.R;R<RgRiRjRRHRRRRBRCRRRR(((s/usr/lib/python2.7/urllib2.pyt<module>Lsr
X"
	
	r	'i	H+@
C	m	
	+	4<