Back to index

python3.2  3.2.2
Public Member Functions
test.test_urllib2net.CloseSocketTest Class Reference

Disabled at the moment since there is no page under python.org which could be used to HTTP authentication. More...

List of all members.

Public Member Functions

def test_close

Detailed Description

Disabled at the moment since there is no page under python.org which could be used to HTTP authentication.

def test_basic_auth(self): import http.client

test_url = "http://www.python.org/test/test_urllib2/basic_auth" test_hostport = "www.python.org" test_realm = 'Test Realm' test_user = 'test.test_urllib2net' test_password = 'blah'

failure

try: _urlopen_with_retry(test_url) except urllib2.HTTPError, exc: self.assertEqual(exc.code, 401) else: self.fail("urlopen() should have failed with 401")

success

auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(test_realm, test_hostport, test_user, test_password) opener = urllib2.build_opener(auth_handler) f = opener.open('http://localhost/') response = _urlopen_with_retry("http://www.python.org/")

The 'userinfo' URL component is deprecated by RFC 3986 for security

reasons, let's not implement it! (it's already implemented for proxy

specification strings (that is, URLs or authorities specifying a

proxy), so we must keep that)

self.assertRaises(http.client.InvalidURL, urllib2.urlopen, "http://evil:thing@example.com")

Definition at line 81 of file test_urllib2net.py.


Member Function Documentation

Definition at line 83 of file test_urllib2net.py.

00083 
00084     def test_close(self):
00085         # calling .close() on urllib2's response objects should close the
00086         # underlying socket
00087 
00088         response = _urlopen_with_retry("http://www.python.org/")
00089         sock = response.fp
00090         self.assertTrue(not sock.closed)
00091         response.close()
00092         self.assertTrue(sock.closed)

Here is the call graph for this function:


The documentation for this class was generated from the following file: