%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python2.7/test/
Upload File :
Create Path :
Current File : //usr/local/lib/python2.7/test/test_urllib2.pyc


Nac@sddlZddlmZddlmZddlZddlZddlZddlZddlmZm	Z	m
Z
ddlZyddlZWne
k
reZnXddlmZdejfdYZdZd	Zd
ZdZdfd
YZdfdYZdefdYZdejfdYZdfdYZdfdYZdfdYZdfdYZdfdYZ dZ!dZ"d ej#fd!YZ$d"ej%fd#YZ&d$fd%YZ'd&ejfd'YZ(d(Z)d)ejfd*YZ*d+ejefd,YZ+d-ejfd.YZ,ed/Z-e.d0kre-d1e/ndS(2iN(ttest_support(ttest_urllib(tRequesttOpenerDirectortAbstractDigestAuthHandler(t
FakeHTTPMixintTrivialTestscBs5eZdZdZejeddZRS(cCs|jttjdtjjtjjtj	d}tj
dkrddl}tj|}|j
|jdd}ntj
dkrd|}n
d	|}tj|}|j}|jdS(
Ns	bogus urlt/triscosis/.s./tnts
file:///%ss	file://%s(tassertRaisest
ValueErrorturllib2turlopentostpathtabspatht__file__treplacetseptnametstringtexpandt	translatet	maketranstreadtclose(tselftfnameRtfile_urltftbuf((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_trivials$

c
Csddddgfdddgfdddd	d
ddd
gfddddgfg}x-|D]%\}}|jtj||q^WdS(Nsa,b,ctatbtcspath"o,l"og"i"cal, examplespath"o,l"og"i"caltexamplesa, b, "c", "d", "e,f", g, hs"c"s"d"s"e,f"tgthsa="b\"c", d="e\,f", g="h\\i"sa="b"c"sd="e,f"sg="h\i"(tassertEqualRtparse_http_list(RttestsRtlist((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_parse_http_list4ssssl module requiredc
Cs?tj}|jttjdddd|WdQXdS(Nshttps://localhosttcafiles/nonexistent/pathtcontext(tssltcreate_default_contextR
RRR
(RR-((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_cafile_and_context<s(t__name__t
__module__R R+tunittestt
skipUnlessR.R0(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs		cCsdS(s
    The Request.headers dictionary is not a documented interface.  It should
    stay that way, because the complete set of headers are only accessible
    through the .get_header(), .has_header(), .header_items() interface.
    However, .headers pre-dates those methods, and so real code will be using
    the dictionary.

    The introduction in 2.4 of those methods was a mistake for the same reason:
    code that previously saw all (urllib2 user)-provided headers in .headers
    now sees only a subset (and the function interface is ugly and incomplete).
    A better change would have been to replace .headers dict with a dict
    subclass (or UserDict.DictMixin instance?)  that preserved the .headers
    interface and also provided access to the "unredirected" headers.  It's
    probably too late to fix that, though.


    Check .capitalize() case normalization:

    >>> url = "http://example.com"
    >>> Request(url, headers={"Spam-eggs": "blah"}).headers["Spam-eggs"]
    'blah'
    >>> Request(url, headers={"spam-EggS": "blah"}).headers["Spam-eggs"]
    'blah'

    Currently, Request(url, "Spam-eggs").headers["Spam-Eggs"] raises KeyError,
    but that could be changed in future.

    N((((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_request_headers_dictEtcCsdS(s
    Note the case normalization of header names here, to .capitalize()-case.
    This should be preserved for backwards-compatibility.  (In the HTTP case,
    normalization to .title()-case is done by urllib2 before sending headers to
    httplib).

    >>> url = "http://example.com"
    >>> r = Request(url, headers={"Spam-eggs": "blah"})
    >>> r.has_header("Spam-eggs")
    True
    >>> r.header_items()
    [('Spam-eggs', 'blah')]
    >>> r.add_header("Foo-Bar", "baz")
    >>> items = r.header_items()
    >>> items.sort()
    >>> items
    [('Foo-bar', 'baz'), ('Spam-eggs', 'blah')]

    Note that e.g. r.has_header("spam-EggS") is currently False, and
    r.get_header("spam-EggS") returns None, but that could be changed in
    future.

    >>> r.has_header("Not-there")
    False
    >>> print r.get_header("Not-there")
    None
    >>> r.get_header("Not-there", "default")
    'default'

    N((((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_request_headers_methodscR6cCsdS(s
    >>> mgr = urllib2.HTTPPasswordMgr()
    >>> add = mgr.add_password
    >>> add("Some Realm", "http://example.com/", "joe", "password")
    >>> add("Some Realm", "http://example.com/ni", "ni", "ni")
    >>> add("c", "http://example.com/foo", "foo", "ni")
    >>> add("c", "http://example.com/bar", "bar", "nini")
    >>> add("b", "http://example.com/", "first", "blah")
    >>> add("b", "http://example.com/", "second", "spam")
    >>> add("a", "http://example.com", "1", "a")
    >>> add("Some Realm", "http://c.example.com:3128", "3", "c")
    >>> add("Some Realm", "d.example.com", "4", "d")
    >>> add("Some Realm", "e.example.com:3128", "5", "e")

    >>> mgr.find_user_password("Some Realm", "example.com")
    ('joe', 'password')
    >>> mgr.find_user_password("Some Realm", "http://example.com")
    ('joe', 'password')
    >>> mgr.find_user_password("Some Realm", "http://example.com/")
    ('joe', 'password')
    >>> mgr.find_user_password("Some Realm", "http://example.com/spam")
    ('joe', 'password')
    >>> mgr.find_user_password("Some Realm", "http://example.com/spam/spam")
    ('joe', 'password')
    >>> mgr.find_user_password("c", "http://example.com/foo")
    ('foo', 'ni')
    >>> mgr.find_user_password("c", "http://example.com/bar")
    ('bar', 'nini')

    Actually, this is really undefined ATM
##     Currently, we use the highest-level path where more than one match:

##     >>> mgr.find_user_password("Some Realm", "http://example.com/ni")
##     ('joe', 'password')

    Use latest add_password() in case of conflict:

    >>> mgr.find_user_password("b", "http://example.com/")
    ('second', 'spam')

    No special relationship between a.example.com and example.com:

    >>> mgr.find_user_password("a", "http://example.com/")
    ('1', 'a')
    >>> mgr.find_user_password("a", "http://a.example.com/")
    (None, None)

    Ports:

    >>> mgr.find_user_password("Some Realm", "c.example.com")
    (None, None)
    >>> mgr.find_user_password("Some Realm", "c.example.com:3128")
    ('3', 'c')
    >>> mgr.find_user_password("Some Realm", "http://c.example.com:3128")
    ('3', 'c')
    >>> mgr.find_user_password("Some Realm", "d.example.com")
    ('4', 'd')
    >>> mgr.find_user_password("Some Realm", "e.example.com:3128")
    ('5', 'e')

    N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_password_managers>cCsdS(sV
    >>> mgr = urllib2.HTTPPasswordMgr()
    >>> add = mgr.add_password

    The point to note here is that we can't guess the default port if there's
    no scheme.  This applies to both add_password and find_user_password.

    >>> add("f", "http://g.example.com:80", "10", "j")
    >>> add("g", "http://h.example.com", "11", "k")
    >>> add("h", "i.example.com:80", "12", "l")
    >>> add("i", "j.example.com", "13", "m")
    >>> mgr.find_user_password("f", "g.example.com:100")
    (None, None)
    >>> mgr.find_user_password("f", "g.example.com:80")
    ('10', 'j')
    >>> mgr.find_user_password("f", "g.example.com")
    (None, None)
    >>> mgr.find_user_password("f", "http://g.example.com:100")
    (None, None)
    >>> mgr.find_user_password("f", "http://g.example.com:80")
    ('10', 'j')
    >>> mgr.find_user_password("f", "http://g.example.com")
    ('10', 'j')
    >>> mgr.find_user_password("g", "h.example.com")
    ('11', 'k')
    >>> mgr.find_user_password("g", "h.example.com:80")
    ('11', 'k')
    >>> mgr.find_user_password("g", "http://h.example.com:80")
    ('11', 'k')
    >>> mgr.find_user_password("h", "i.example.com")
    (None, None)
    >>> mgr.find_user_password("h", "i.example.com:80")
    ('12', 'l')
    >>> mgr.find_user_password("h", "http://i.example.com:80")
    ('12', 'l')
    >>> mgr.find_user_password("i", "j.example.com")
    ('13', 'm')
    >>> mgr.find_user_password("i", "j.example.com:80")
    (None, None)
    >>> mgr.find_user_password("i", "http://j.example.com")
    ('13', 'm')
    >>> mgr.find_user_password("i", "http://j.example.com:80")
    (None, None)

    N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyt"test_password_manager_default_portR6t
MockOpenercBs)eZgZdejdZdZRS(cCs!||||_|_|_dS(N(treqtdatattimeout(RR;R<R=((s-/usr/local/lib/python2.7/test/test_urllib2.pytopenscGs|||_|_dS(N(tprototargs(RR?R@((s-/usr/local/lib/python2.7/test/test_urllib2.pyterrorsN(R1R2t
addheaderstNonetsockett_GLOBAL_DEFAULT_TIMEOUTR>RA(((s-/usr/local/lib/python2.7/test/test_urllib2.pyR:stMockFilecBs)eZddZddZdZRS(cCsdS(N((Rtcount((s-/usr/local/lib/python2.7/test/test_urllib2.pyRR6cCsdS(N((RRG((s-/usr/local/lib/python2.7/test/test_urllib2.pytreadlineR6cCsdS(N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRR6N(R1R2RCRRHR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRFstMockHeaderscBseZdZRS(cCs
|jS(N(tvalues(RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
getheaderss(R1R2RK(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRIstMockResponsecBs&eZddZdZdZRS(cCsAtjj||||||f\|_|_|_|_dS(N(tStringIOt__init__tcodetmsgtheadersturl(RRORPRQR<RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNscCs|jS(N(RQ(R((s-/usr/local/lib/python2.7/test/test_urllib2.pytinfoscCs|jS(N(RR(R((s-/usr/local/lib/python2.7/test/test_urllib2.pytgeturl
sN(R1R2RCRNRSRT(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRLs	t
MockCookieJarcBseZdZdZRS(cCs
||_dS(N(tach_req(Rtrequest((s-/usr/local/lib/python2.7/test/test_urllib2.pytadd_cookie_headerscCs|||_|_dS(N(tec_reqtec_r(RtresponseRW((s-/usr/local/lib/python2.7/test/test_urllib2.pytextract_cookiess(R1R2RXR\(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRU
s	t
FakeMethodcBseZdZdZRS(cCs||_||_||_dS(N(t	meth_namethandletaction(RR^R`R_((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNs		cGs|j|j|j|S(N(R_R^R`(RR@((s-/usr/local/lib/python2.7/test/test_urllib2.pyt__call__s(R1R2RNRa(((s-/usr/local/lib/python2.7/test/test_urllib2.pyR]s	tMockHTTPResponsecBseZdZdZRS(cCs(||_||_||_||_dS(N(tfpRPtstatustreason(RRcRPRdRe((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNs			cCsdS(NR6((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyR!s(R1R2RNR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRbs	t
MockHTTPClasscBsYeZdZejdZdZdddZdddZ	dZ
dZRS(cCs(g|_d|_t|_i|_dS(N(treq_headersRCR<tFalsetraise_on_endheaderst_tunnel_headers(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRN%s			cCs||_||_|S(N(thostR=(RRkR=((s-/usr/local/lib/python2.7/test/test_urllib2.pyRa+s		cCs
||_dS(N(tlevel(RRl((s-/usr/local/lib/python2.7/test/test_urllib2.pytset_debuglevel0scCs5||_||_|r$||_n
|jjdS(N(t_tunnel_hostt_tunnel_portRjtclear(RRktportRQ((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
set_tunnel3s
		cCs}||_||_|dk	r6|j|j7_n|jj|rU||_n|jryddl}|j	ndS(Ni(
tmethodtselectorRCRgtitemstsortR<RiRDRA(RRsRRtbodyRQRD((s-/usr/local/lib/python2.7/test/test_urllib2.pyRW;s		
	cCsttiddS(NitOK(RbRF(R((s-/usr/local/lib/python2.7/test/test_urllib2.pytgetresponseGscCsdS(N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRJsN(R1R2RNRDRERaRmRCRrRWRyR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRf$s			tMockHandlercBsDeZdZdZdZdZdZdZdZRS(icCs|j|dS(N(t_define_methods(Rtmethods((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNQscCskxd|D]\}t|dkr.|\}}n
|d}}t|||j}t|j||qWdS(Ni(tlenRCR]R_tsetattrt	__class__(RR|tspecRR`tmeth((s-/usr/local/lib/python2.7/test/test_urllib2.pyR{Ss

cOs*|jjj||||f|dkr/dS|dkr?|S|dkrdtddid}|S|dkrztdS|jdr||jd	d
}yt|}Wnt	k
rnXtddid}|jj
d|d||diS|d
krtjdnt
s&tdS(Nsreturn selfsreturn responseiRxR6sreturn requestshttp://blah/RAt ithttpitraisetblah(tparenttcallstappendRCRLRt
startswithtrfindtintRRARtURLErrorRhtAssertionError(Rtfn_nameR`R@tkwdstresRO((s-/usr/local/lib/python2.7/test/test_urllib2.pyR_Ys*

#cCsdS(N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRoR6cCs||_g|j_dS(N(RR(RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
add_parentps	cCs#t|dstS|j|jkS(Nt
handler_order(thasattrtTrueR(Rtother((s-/usr/local/lib/python2.7/test/test_urllib2.pyt__lt__ss(	R1R2RRNR{R_RRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRzMs					cCsg}d}xp|D]h}dtfdY}||}|j|7_|j||d}|j||j|qW|S(sCreate MockHandlers and add them to an OpenerDirector.

    meth_spec: list of lists of tuples and strings defining methods to define
    on handlers.  eg:

    [["http_error", "ftp_open"], ["http_open"]]

    defines methods .http_error() and .ftp_open() on one handler, and
    .http_open() on another.  These methods just record their arguments and
    return None.  Using a tuple instead of a string causes the method to
    perform some action (see MockHandler.handle()), eg:

    [["http_error"], [("http_open", "return request")]]

    defines .http_error() on one handler (which simply returns None), and
    .http_open() on another handler, which returns a Request object.

    itMockHandlerSubclasscBseZRS((R1R2(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRsi(RzRRRtadd_handler(topenert	meth_specthandlersRGtmethsRR&((s-/usr/local/lib/python2.7/test/test_urllib2.pytadd_ordered_mock_handlersys



cGs+t}x|D]}|j|qW|S(N(RR(thandler_instancesRR&((s-/usr/local/lib/python2.7/test/test_urllib2.pytbuild_test_openers	
tMockHTTPHandlercBs#eZdZdZdZRS(cCs ||_||_|jdS(N(RORQtreset(RRORQ((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNs		cCsd|_g|_dS(Ni(t_counttrequests(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs	cCsddl}ddl}ddlm}|jj|j||jdkr|jd|_tj|j	}|j
||j}|jj
d|t|j	||S||_|j
|d}tdd|d	|jSdS(
Ni(RMiiRs

iRxR6(t	mimetoolstcopyRMRRtdeepcopyRthttplibt	responsesROtMessageRQRRARFR;RLtget_full_url(RR;RRRMRRP((s-/usr/local/lib/python2.7/test/test_urllib2.pyt	http_opens		(R1R2RNRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs		tMockHTTPSHandlercBseZdZdZRS(cCs tjj|t|_dS(N(RtAbstractHTTPHandlerRNRfthttpconn(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNscCs|j|j|S(N(tdo_openR(RR;((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
https_opens(R1R2RNR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs	tMockPasswordManagercBseZdZdZRS(cCs(||_||_||_||_dS(N(trealmRRtusertpassword(RRturiRR((s-/usr/local/lib/python2.7/test/test_urllib2.pytadd_passwords			cCs"||_||_|j|jfS(N(ttarget_realmt
target_urlRR(RRtauthuri((s-/usr/local/lib/python2.7/test/test_urllib2.pytfind_user_passwords		(R1R2RR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs	tOpenerDirectorTestscBsGeZdZdZdZdZdZdZdZRS(cCs6dtfdY}|jttj|dS(Nt
NonHandlercBseZRS((R1R2(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs(tobjectR
t	TypeErrorRR(RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_add_non_handlers	cCsddlm}t}ddgd
gg}t||}|jtjx(dD] }|j||j|d
qWWdS(Ni(RRsreturn selft
proxy_opentredirect_requesttdotproxytredirects://example.com/(Rsreturn self(Rsreturn self(Rsreturn self(RRR(RRRRRtUnknownHandlerR
R>(RRtoRRtscheme((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_badly_named_methodss			
c
Cst}dddgdgdgd	gg}t||}td}|j|}|j||d|ddf|ddfg}x[t||jD]G\}}|\}	}
}}|j|	|
f||j||fqWdS(
NRtftp_openthttp_error_302sreturn selfshttp://example.com/ii(Rsreturn self(Rsreturn self(RRRR>R'tzipR(
RRRRR;trRtexpectedtgotthandlerRR@R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_handleds	 cCst}g}xqd	gdfdgdfgD]Q\}}dtfdY}||}||_|j||j|q.W|jd}|j|jdd|d|j|jdd|ddS(
NRsreturn selfiiRcBseZRS((R1R2(((s-/usr/local/lib/python2.7/test/test_urllib2.pyR
sshttp://example.com/i(Rsreturn self(RRzRRRR>R'R(RRRRRRR&R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_handler_orders		
cCs|t}dgdgg}t||}td}|jtj|j||j|j|dd|fifgdS(NRRsreturn selfshttp://example.com/i(RR(Rsreturn self(	RRRR
RRR>R'R(RRRRR;((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_raises	c
Cs't}dgddgdddgdgg}t||}d	dd
Y}td}|j|}t|jdkst|d
d|ff|dd||ddiffg}x]t||jD]I\}}	|\}
}}|j|
|f|	d |j||	dqWdS(NRs	error 302thttp_error_400RRsreturn responsethttp_error_303t
http_errortUnknowncBseZdZRS(cSstS(N(R(RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt__eq__7R6(R1R2R(((s-/usr/local/lib/python2.7/test/test_urllib2.pyR6sshttp://example.com/iii.R6(Rs	error 302(RR(Rsreturn response((	RRRR>R}RRRR'(
RRRRRR;RRRRRtmethod_nameR@((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_http_error)s$		
cCsst}d	d
gddgg}t||}td}|j|}|ddf|ddf|ddf|ddfg}xt|jD]\}\}}	}
}|dkr|j||	f|||jt|
d|j|
dtq|j||	f|||jt|
d|j|
dt|
ddk	r|j|
dt
qqWdS(
Nthttp_requestsreturn requestt
http_responsesreturn responseshttp://example.com/iii(Rsreturn request(Rsreturn response(Rsreturn request(Rsreturn response(RRRR>t	enumerateRR'R}tassertIsInstanceRCRL(RRRRR;RRtiRRR@R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_processorsDs(	 ((	R1R2RRRRRRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs						cCsJddl}|j|}tjdkrF|jdrF|d}n|S(NiR	s///i(turllibtpathname2urlRRR(RRturlpath((s-/usr/local/lib/python2.7/test/test_urllib2.pytsanepathname2urlhs

tHandlerTestscBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZddZdZdZdZdZdZRS(csndddYdtjffdY}ddl}d}||}t}|_xdd|jd	d	d
ddgd
df	dd|jdd	d
ddgd
df	dd|jdd	d
ddgd
df	dd|jdd	d
ddgd
df	dddd	d	dddgd	df	dd|jd	d	dgddf	gD]\	}}}}	}
}}}
}t|}d|_|j	|}|j
|j|	|j
|j|
|j
|j
tj||j
|j||j
|j||j
|jj|
|j
|jj||j}|j
|jd||j
t|dt|qHWdS(NtMockFTPWrappercBs#eZdZdZdZRS(cSs
||_dS(N(R<(RR<((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNtR6cSs2|||_|_tj|jt|jfS(N(tfilenametfiletypeRMR<R}(RRR((s-/usr/local/lib/python2.7/test/test_urllib2.pytretrfileuscSsdS(N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRxR6(R1R2RNRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRss		tNullFTPHandlercs&eZdZejfdZRS(cSs
||_dS(N(R<(RR<((s-/usr/local/lib/python2.7/test/test_urllib2.pyRN{R6csH|||_|_|||_|_||_|j|_|jS(N(RtpasswdRkRqtdirsR<t
ftpwrapper(RRRRkRqRR=(R(s-/usr/local/lib/python2.7/test/test_urllib2.pytconnect_ftp|s
	(R1R2RNRDRER((R(s-/usr/local/lib/python2.7/test/test_urllib2.pyRzs	isrheum rhaponicums ftp://localhost/foo/bar/baz.htmlt	localhostR6tItfootbarsbaz.htmls	text/htmls'ftp://parrot@localhost/foo/bar/baz.htmltparrots*ftp://%25parrot@localhost/foo/bar/baz.htmls%parrots,ftp://%2542parrot@localhost/foo/bar/baz.htmls	%42parrotsftp://localhost:80/foo/bar/iPtDsftp://localhost/baz.gif;type=atAsbaz.gifsContent-typesContent-length((Rt
FTPHandlertftplibR:RtFTP_PORTRCRR=RR'RRRkRDt
gethostbynameRqRRRRRStgetRR}(RRRR<R&RRRRkRqRRttype_RRtmimetypeR;RRQ((Rs-/usr/local/lib/python2.7/test/test_urllib2.pyttest_ftprsL
1	cCsddl}ddl}tj}t}|_tj}tt	j
j|}d}d|d|d|jd|fg}y|j|j
}	Wn|jk
rd}	nX|	r|jd|	|fnx|D]}
t|d}zz|j|Wd|jX|jt|
}z(|j}
|j}|j}Wd|jXt	j|}|j|j}Wdt	j|X|j|
||j|d	d
|j|dd|j|d
||j||
qWxd|dd|jdt	j|fdt	j|fgD]h}
zQt|d}z|j|Wd|jX|jtj|jt|
Wdt	j|Xq:Wtj}t}|_xdt fdt!fdt!fdt fdt!fgD]\}
}t|
}y|j|Wn(tjt"fk
rI|j#|n*X|j#|j$|k|j|j%d|j|j%dk|qWdS(Nis
hello, world
sfile://localhost%ss	file://%ssfile://%s%sRR6twbsContent-types
text/plainsContent-lengtht13s
Last-modifiedsfile://localhost:80%ssfile:///file_does_not_exist.txtsfile://%s:80%s/%ss,file://somerandomhost.ontheinternet.com%s/%ssfile://ftp.example.com//foo.txts file://ftp.example.com///foo.txtsfile://ftp.example.com/foo.txts"file://somehost//foo/something.txts#file://localhost//foo/something.txttftp(&trfc822RDRtFileHandlerR:RRtTESTFNRRRRRtgethostnametgaierrorRR>twriteRt	file_openRRRSRTtstatt
formatdatetst_mtimetremoveR'tgetcwdR
RRRhtOSErrort
assertTrueR;ttype(RRRDR&RRRttowriteturlst	localaddrRRRRR<RQtrespurltstatstmodifiedRR;((s-/usr/local/lib/python2.7/test/test_urllib2.pyt	test_files	

				cCs!tj}t}|_d}xGddgD]9\}}t||idd6}d|_|jddt}|j	||}|j
|j|j|j
|j|jd	kd
f|j}	|	j|	j|j|j
||j|jd|j|jd|j|j||j|jd
|j|jdddg|j|j|q/Wt|_|jtj|j	||dg|_x}dD]u}td|}td	d
id}|j|}
|dkr|j d|j!|j d|j!n.|j|j!dd|j|j!dd|j|j!dd|j|j!dd|jdd|jdd|jdd|jdd|j|}
|j|j!dd|j|j!dd|j|j!dd|j|j!ddqWdS(Nshttp://example.com/tGETtPOSTRRtFootSpamteggsiRxsexample.comiRt
ConnectionRR6sContent-lengthsContent-typet0s!application/x-www-form-urlencodedtHostRtbaz(RN(RR(RR(RR(RR(RR(R6N("RRR:RRCRR=tadd_unredirected_headerRfRRRHRSRTRORPRthas_keyR'RkRlRsRtRgR<RRiR
RRBRLtdo_request_tassertNotIntunredirected_hdrs(RR&RRRRsR<R;RRthdrstnewreq((s-/usr/local/lib/python2.7/test/test_urllib2.pyt	test_http	sd		
	
c	Cstj}t}|_d}ddddg}xy|D]q}t||}|j|}|j|jdd|jdd|j|}|j|jddq;WdS(	NR6s#http://example.com/foo/bar/baz.htmls$http://example.com//foo/bar/baz.htmls$http://example.com/foo//bar/baz.htmls$http://example.com/foo/bar//baz.htmlRsexample.comssomeproxy:3128(
RRR:RRR!R'R#t	set_proxyRC(	RR&RR<tds_urlstds_urltds_reqt	np_ds_reqtp_ds_req((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_http_doubleslashGs	
cCstj}t}|_d}t|}|j|}|j|jd|j|jdd}t|}|j|}|j|jd|j|jddS(Nshttp://www.python.org?getspamswww.python.orgs	/?getspamshttp://www.python.orgR6(	RRR:RRR!R'tget_hosttget_selector(RR&Rt	weird_urlR;R%turl_without_path((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_fixpath_in_weirdurlsascCstj}t}|_d}t|}tddid|}|j||}|j||k|jt|dtddid|}|j||}|j||k|jt|dtdd	id|}|j||}|j||k|jt|dtd
did|}|j|j||dk|j
|jd|j
|j||d
difdS(
Nshttp://example.com/iRxR6R?itAcceptedisPartial contentisBad gatewayR(
RtHTTPErrorProcessorR:RRRLRR
RRCR'R?R@(RR&RRRR;Rtnewr((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_errorsts(cCst}tj|}t}|_td}tddid}|j|}|j|j	|kox|kn|j
|jd|j|j|j
||}|j|j|k|j|j|ko|kndS(Nshttp://example.com/iRxR6sexample.com(RURtHTTPCookieProcessorR:RRRLRR
RVR'tget_origin_req_hosttis_unverifiableRRYRZ(RtcjR&RR;RR%R5((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_cookiess	&c
Cs%d}d}tj}t}|_xdD]}xdD]}t|d|}t||}|jd	d
tj	|_
|dk	r|jdtt|n|j
dd
y*||t|dti|d6Wn1tjk
r|j|d|j|nX|j|jj|y|j|jjdWn(tk
ry|j|jjnXg|jjD]}	|	j^q}
|jd|
|jd|
|j|jjd	d
|jd|jj|jd|jjq<Wq/Wt|}tj	|_
|d}t|dd}d}tj	|_
y%x|||d|d}q[WWn*tjk
r|j|tjjnXt|dd}d}tj	|_
y)x"|||d||d}qWWn*tjk
r |j|tjjnXdS(Nshttp://example.com/a.htmlshttp://example.com/b.htmli-i.i/i3s
blah
blah
s
http_error_%stNonsensesviking=withholdsContent-LengthRtspamtBlahtlocationRscontent-lengthscontent-typec	Ss-|j|tddti|d6dS(Ni.R>R?(RRFRI(R&R;RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyRstorigin_req_hostsexample.comishttp://example.com/ishttp://example.com/%d(i-i.i/i3(Ns
blah
blah
(RtHTTPRedirectHandlerR:RRCtgetattrRt
add_headerRDRER=tstrR}RRFRIt	HTTPErrorR'tassertIsNotNoneR;Rt
get_methodtAttributeErrorR
thas_dataRQtlowerR"R#tmax_repeatstmax_redirections(
Rtfrom_urltto_urlR&RROR<RsR;txRQRRG((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_redirectsj


%	cCsd}dddg}dddg}d}tj}t}|_t|}tj|_xQ|D]I}|d	|}	|jtj	|j
|td
dti|	d6qeWx^|D]V}|d	|}
|j
|td
d
ti|
d6|j
|jj|
qWdS(Nshttp://example.com/a.htmlRthttpsRtfiletimaptldapsexample.com/b.htmls://i.sSecurity LoopholeR?sThat's fine(RRAR:RRRDRER=R
RERRFRIR'R;R(RRMt
valid_schemestinvalid_schemestschemeless_urlR&RR;Rtinvalid_urlt	valid_url((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_invalid_redirects$

c	Csddlm}ddlm}|}||ddtdd}tj}tj}tj|}t	||||}|j
d|j|jj
ddS(	Ni(t	CookieJar(tinteract_netscapeshttp://www.example.com/s	spam=eggsi.s%Location: http://www.cracker.com/

tCookie(t	cookielibR[ttest.test_cookielibR\RRtHTTPDefaultErrorHandlerRAR7RR>R
R;t
has_header(	RR[R\R:thhthdehthrhtcpR((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_cookie_redirects	
cCsrd}tdd|}tj}tj}t|||}|jd}|j|j|jdS(Ns(http://www.example.com/index.html#OK

i.s
Location: shttp://www.example.com(	RRR`RARR>R'RTtstrip(Rtredirected_urlRbRcRdRRc((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_redirect_fragmentscstjd}tj|t_jttdtdfd}|tj_tj	d}j
|jddS(	Ns(HTTP/1.1 302 Found
Location: ?query

tHTTPConnections/paths/path?querycs?j|tj|||||d|j_dS(NsHTTP/1.1 200 OK

Hello!(R'tnextRWRtfakedata(tconnRsRRtpostkw(t
real_classRR(s-/usr/local/lib/python2.7/test/test_urllib2.pyRWsshttp://python.org/pathshttp://python.org/path?query(s/paths/path?query(RRjRtfakehttpt
addCleanupR~titerRWRR
R'RT(Rt	response1RWRc((RpRRs-/usr/local/lib/python2.7/test/test_urllib2.pyttest_redirect_no_paths	cCst}tjtdd}|j|d	gg}t||}td}|j|jd|j	|}|j|jd|j|ddfgg|j
D]}|dd!^qdS(
NRsproxy.example.com:3128Rsreturn responseshttp://acme.example.com/sacme.example.comii(Rsreturn response(RRtProxyHandlertdictRRRR'R.R>R(RRtphRRR;Rttup((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_proxy$s	
cCsdtjd<t}tjtdd}|j|td}|j|j	d|j
|}|j|j	dtd}|j|j	d|j
|}|j|j	dtjd=dS(	Ns
python.orgtno_proxyRsproxy.example.comshttp://www.perl.org/swww.perl.orgshttp://www.python.orgswww.python.org(RtenvironRRRvRwRRR'R.R>(RRRxR;R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_proxy_no_proxy5s
	
cCst}tjtdd}|j|d	gg}t||}td}|j|jd|j	|}|j|jd|j|ddfgg|j
D]}|dd!^qdS(
NRQsproxy.example.com:3128Rsreturn responseshttps://www.example.com/swww.example.comii(Rsreturn response(RRRvRwRRRR'R.R>R(RRRxRRR;RRy((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_proxy_httpsEs	
cCst}tjtdd}|j|t}|j|td}|jdd|jdd|j|j	d|j
|j|j|}|j
d
|jj|jd|jj|j|j|j|j	d|j|jd	ddS(NRQsproxy.example.com:3128shttps://www.example.com/sProxy-AuthorizationtFooBars
User-AgenttGrailswww.example.comsProxy-authorization(sProxy-AuthorizationR(s
User-AgentR(RRRvRwRRRRCR'R.tassertIsNoneRnR>R"RRgtassertInRFt
get_header(RRRxt
https_handlerR;R((s-/usr/local/lib/python2.7/test/test_urllib2.pyt$test_proxy_https_proxy_authorizationTs$	
	
	
	
t"c	Cst}t}tj|}d}tdd|||f}|j||j||j||d|||dddS(NsACME Widget Storeis(WWW-Authenticate: Basic realm=%s%s%s

t
Authorizations!http://acme.example.com/protected(RRRtHTTPBasicAuthHandlerRRt_test_basic_auth(Rt
quote_charRtpassword_managertauth_handlerRthttp_handler((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_basic_authks		

	cCs|jdddS(NRt'(R(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyt(test_basic_auth_with_single_quoted_realm{sc
Cst}t}tj|}d}tdd|}|j||j|d}tj|tf'|j	||d|||ddWdQXdS(NsACME Widget Storeis$WWW-Authenticate: Basic realm=%s

sBasic Auth Realm was unquotedRs!http://acme.example.com/protected(
RRRRRRRtcheck_warningstUserWarningR(RRRRRRRP((s-/usr/local/lib/python2.7/test/test_urllib2.pyt#test_basic_auth_with_unquoted_realm~s		

	c	Cst}tjtdd}|j|t}tj|}d}tdd|}|j||j||j||d|||dddS(NRsproxy.example.com:3128s
ACME Networksis(Proxy-Authenticate: Basic realm="%s"

sProxy-authorizations&http://acme.example.com:3128/protected(	RRRvRwRRtProxyBasicAuthHandlerRR(RRRxRRRR((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_proxy_basic_auths	
	

	c
	CsdtfdY}dtjfdY}dtjfdY}|}t}||}||}d}tdd	|}	|j||j||j|	|j||d
||	|dd|j|j	dd
gddS(NtRecordingOpenerDirectorcBseZdZdZRS(cSstj|g|_dS(N(RRNtrecorded(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRNs
cSs|jj|dS(N(RR(RRS((s-/usr/local/lib/python2.7/test/test_urllib2.pytrecords(R1R2RNR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs	tTestDigestAuthHandlercBseZdZRS(c_s*|jjdtjj|||dS(Ntdigest(RRRtHTTPDigestAuthHandlerthttp_error_401(RR@R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs(R1R2R(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRstTestBasicAuthHandlercBseZdZRS(c_s*|jjdtjj|||dS(Ntbasic(RRRRR(RR@R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs(R1R2R(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRss
ACME Networksis&WWW-Authenticate: Basic realm="%s"

Rs!http://acme.example.com/protectedRRi(
RRRRRRRRR'R(
RRRRRRtdigest_handlert
basic_handlerRR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt#test_basic_and_digest_auth_handlerss$			


	c	Csddl}	d	\}
}|j|||
||j||j|j||j|j|
|j|j||j|j|}|j|j||j|j	||jt
|jd|j|jdj
|d|
|f}
d|	j|
j}|j|jdj|||j|jdj||d|_|_|j|j|}|jt
|jd|j|jdj
|dS(
Nitwiletcoyoteiis%s:%ssBasic i(RR(tbase64RR'RRRRRR>RRR}RtassertFalseRatencodestringRgRR#RCR(RRRtauth_headerRRRtrequest_urlt
protected_urlRRRRtuserpasstauth_hdr_value((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs.
(R1R2RRR&R-R2R6R;RPRZRfRiRuRzR}R~RRRRRRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRps,	:	]	>					I													/t	MiscTestscBsteZdZdZdZejeddZejeddZ	ejeddZ
RS(cCsdtjfdY}dtjfdY}dtjfdY}tj}|||}|j|||j|||||}|j|||j||||}|j|||}|j|tj|tj}|j|tj|tj}|j|tjdtjfdY}|||}|j|||j||dS(	Nt
MyHTTPHandlercBseZRS((R1R2(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRst
FooHandlercBseZdZRS(cSsdS(N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pytfoo_openR6(R1R2R(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRst
BarHandlercBseZdZRS(cSsdS(N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pytbar_openR6(R1R2R(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRstMyOtherHTTPHandlercBseZRS((R1R2(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs(RtHTTPHandlertBaseHandlertbuild_openertopener_has_handler(RRRRRRR((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_build_openers,		cCs8x1|jD]}|j|kr
Pq
q
W|jtdS(N(RRR
Rh(RRt
handler_classR&((s-/usr/local/lib/python2.7/test/test_urllib2.pyRscCsKt}|jt}|jdWdQX|jt|jddS(Ntinvalids5Unsupported digest authentication algorithm 'invalid'(RR
Rtget_algorithm_implsR'RDt	exception(RRtexc((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_unsupported_algorithm"s	sssl module requiredc	CsxtddtddD]}t|}d|}|jdzt|jdd}tj}|j|d	|tj	d
|WdQX|j|d	|tj	d|WdQXWd|j
XqWdS(Nii!iis//localhost:7777/test%s/sHTTP/1.1 200 OK

Hello.s\s\\scontain control.*shttp:shttps:(trangetchrRqtreprRRt
InvalidURLtassertRaisesRegexpRR
t
unfakehttp(Rtchar_notcharRWtescaped_char_reprR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt(test_url_path_with_control_char_rejected+s#

	cCs|jdd}d|d}zktj}|j|dtjdj|WdQX|j|dtjdj|WdQXWd|jXdS(	NsHTTP/1.1 200 OK

Hello.s:localhost:7777?a=1 HTTP/1.1
X-injected: header
TEST: 123s//s:8080/test/?test=as*contain control.*\\r.*(found at least . .)shttp:{}scontain control.*\\nshttps:{}(RqRRRRR
tformatR(RRkRWR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt4test_url_path_with_newline_header_injection_rejectedCs
		
	
 c	CsxttdddgD]}t|}dj|}|jdzt|jdd}tj}|j	|dj|t
jd	j|WdQX|j	|dj|t
jd
j|WdQXWd|jXqWdS(Nii!is//localhost{}/test/sHTTP/1.1 200 OK

Hello.s\s\\scontain control.*{}shttp:{}shttps:{}(
R*RRRRqRRRRRRR
R(RRRRWRR((s-/usr/local/lib/python2.7/test/test_urllib2.pyt(test_url_host_with_control_char_rejectedYs#
			 (R1R2RRRR3R4R.RRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRs	%			tRequestTestscBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZRS(cCs8tjd|_tjdddidd6|_dS(Nshttp://www.python.org/~jeremy/R<RQttestsX-Test(RRRtpost(R((s-/usr/local/lib/python2.7/test/test_urllib2.pytsetUpns	cCs6|jd|jj|jd|jjdS(NRR(R'RRGR(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_methodtscCss|j|jj|jd|jj|jjd|j|jj|jd|jjdS(NRR=R(R
RRIR'RGtadd_data(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_add_dataxs
cCs|jd|jjdS(Nshttp://www.python.org/~jeremy/(R'RR(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_get_full_urls	cCsB|jd|jjtjd}|jd|jdS(Ns	/~jeremy/shttp://www.python.org/R(R'RR/RR(RR;((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_selectorscCs|jd|jjdS(NR(R'Rtget_type(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_get_typescCs|jd|jjdS(Nswww.python.org(R'RR.(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyt
test_get_hostscCs)tjd}|jd|jdS(Nshttp://www.%70ython.org/swww.python.org(RRR'R.(RR;((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_get_host_unquotescCsv|j|jj|jjdd|j|jj|jd|jj|jd|jjdS(Nswww.perl.orgRswww.python.org(R
Rt	has_proxyR'R'R8R.(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyRzs
cCs&td}|jd|jdS(Ns<URL:http://www.python.org>swww.python.org(RR'R.(RR;((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_wrapped_urlscCsptd}|jd|jtd}|jd|jd}t|}|j|j|dS(Ns-http://www.python.org/?qs=query#fragment=trues
/?qs=queryshttp://www.python.org/#fun=trueRs.http://docs.python.org/library/urllib2.html#OK(RR'R/R(RR;RR((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_url_fragmentscCs6|jt|jd|jt|jddS(Nt_Request__r_xxxt_Request__r_method(RRR(R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_private_attributesscCsdS(sc
        Issue 13211 reveals that HTTPError didn't implement the URLError
        interface even though HTTPError is a subclass of URLError.

        >>> err = urllib2.HTTPError(msg='something bad happened', url=None, code=None, hdrs=None, fp=None)
        >>> assert hasattr(err, 'reason')
        >>> err.reason
        'something bad happened'
        N((R((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_HTTPError_interfaceR6cCstjdddddddddd}|jt|dt|dsUtt|d	sjtt|jsty|jWntk
r|j	d
nX|j
|jddS(s]
        Issue 15701= - HTTPError interface has info method available from URLError.
        RPssomething bad happenedRRROR$sContent-Length:42RcReRSserr.info() failedN(RRERCR
RRtcallableRSRHtfailR'(Rterr((s-/usr/local/lib/python2.7/test/test_urllib2.pyttest_HTTPError_interface_calls
(R1R2RRRRRRRRRzRRRRR(((s-/usr/local/lib/python2.7/test/test_urllib2.pyRls													cCsVddlm}tj||tjt|ttttt	f}tj
|dS(Ni(ttest_urllib2(RRRtrun_doctestRRRRRRtrun_unittest(tverboseRR)((s-/usr/local/lib/python2.7/test/test_urllib2.pyt	test_mains	t__main__R(0R3RRRRRDRMRRRRRR.tImportErrorRCttest.test_urllibRtTestCaseRR5R7R8R9R:RFRwRIRLRUR]RbRfRzRRRRRRRRRRRRRR1R(((s-/usr/local/lib/python2.7/test/test_urllib2.pyt<module>sT

+		!	A	/		),			x\

Zerion Mini Shell 1.0