[Python-checkins] r58252 - sandbox/trunk/urilib/TODO sandbox/trunk/urilib/test_urllib2.py sandbox/trunk/urilib/urllib2.py
senthil.kumaran
python-checkins at python.org
Tue Sep 25 05:45:54 CEST 2007
Author: senthil.kumaran
Date: Tue Sep 25 05:45:53 2007
New Revision: 58252
Added:
sandbox/trunk/urilib/TODO (contents, props changed)
Modified:
sandbox/trunk/urilib/test_urllib2.py
sandbox/trunk/urilib/urllib2.py
Log:
Issue1675455: use getaddrinfo for IPv6 support
Added: sandbox/trunk/urilib/TODO
==============================================================================
--- (empty file)
+++ sandbox/trunk/urilib/TODO Tue Sep 25 05:45:53 2007
@@ -0,0 +1,20 @@
+Author: O.R.Senthil Kumaran
+Google Summer of Code 2007 Tasks - Cleanup urllib2
+Date: 25 Sep 2007
+
+TODO:
+
+1) urllib unification progress. Complaince with RFC3986 and RFC3987
+ a) urllib2 merge
+ b) proxy-support
+ b) unit-tests.
+ c) Documentation.
+2) Author PEP to discuss about Unified Module inclusion in Python 2.6 and Python 3K.
+3) [ 1675455 ] Use getaddrinfo() in urllib2.py for IPv6 support.
+ * 25 Sep. Done.
+ * Test with IPv6 address.
+4) As in mechanize and urlgrabber,Implement higher level interfaces to url module,which can accomplish most common tasks.
+ a) Handler classes HTTPRefreshProcessor, HTTPEquivProcessor, HTTPRobotRulesProcessor
+ b) HTTPRedirectHandler, HTTPRequestUpgradeProcessor and ResponseUpgradeProcessor
+5) Patch 1462525 - uriparser.
+6) URL Encoding with respect to Unicode.
Modified: sandbox/trunk/urilib/test_urllib2.py
==============================================================================
--- sandbox/trunk/urilib/test_urllib2.py (original)
+++ sandbox/trunk/urilib/test_urllib2.py Tue Sep 25 05:45:53 2007
@@ -540,6 +540,23 @@
# XXX don't ask me about the mac...
return urlpath
+def gethost_addrinfo(hostname):
+ if socket.has_ipv6:
+ try:
+ for res in socket.getaddrinfo(hostname, None, socket.AF_INET6,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME):
+ af, socktype, proto, canonname, sa = res
+ except socket.gaierror:
+ for res in socket.getaddrinfo(hostname, None, socket.AF_INET,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME):
+ af, socktype, proto, canonname, sa = res
+ else:
+ for res in socket.getaddrinfo(hostname, None, socket.AF_INET,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME):
+ af, socktype, proto, canonname, sa = res
+
+ return sa[0]
+
class HandlerTests(unittest.TestCase):
def test_ftp(self):
@@ -579,7 +596,7 @@
r = h.ftp_open(req)
# ftp authentication not yet implemented by FTPHandler
self.assert_(h.user == h.passwd == "")
- self.assertEqual(h.host, socket.gethostbyname(host))
+ self.assertEqual(h.host, gethost_addrinfo(host))
self.assertEqual(h.port, port)
self.assertEqual(h.dirs, dirs)
self.assertEqual(h.ftpwrapper.filename, filename)
@@ -599,10 +616,10 @@
urls = [
"file://localhost%s" % urlpath,
"file://%s" % urlpath,
- "file://%s%s" % (socket.gethostbyname('localhost'), urlpath),
+ "file://%s%s" % (gethost_addrinfo('localhost'), urlpath),
]
try:
- localaddr = socket.gethostbyname(socket.gethostname())
+ localaddr = gethost_addrinfo(socket.gethostname())
except socket.gaierror:
localaddr = ''
if localaddr:
@@ -635,7 +652,7 @@
for url in [
"file://localhost:80%s" % urlpath,
"file:///file_does_not_exist.txt",
- "file://%s:80%s/%s" % (socket.gethostbyname('localhost'),
+ "file://%s:80%s/%s" % (gethost_addrinfo('localhost'),
os.getcwd(), TESTFN),
"file://somerandomhost.ontheinternet.com%s/%s" %
(os.getcwd(), TESTFN),
Modified: sandbox/trunk/urilib/urllib2.py
==============================================================================
--- sandbox/trunk/urilib/urllib2.py (original)
+++ sandbox/trunk/urilib/urllib2.py Tue Sep 25 05:45:53 2007
@@ -1218,6 +1218,24 @@
return [part.strip() for part in res]
+def gethost_addrinfo(hostname):
+ if socket.has_ipv6:
+ try:
+ for res in socket.getaddrinfo(hostname, None, socket.AF_INET6,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME):
+ af, socktype, proto, canonname, sa = res
+ except socket.gaierror:
+ for res in socket.getaddrinfo(hostname, None, socket.AF_INET,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME):
+ af, socktype, proto, canonname, sa = res
+ else:
+ for res in socket.getaddrinfo(hostname, None, socket.AF_INET,
+ socket.SOCK_DGRAM, socket.IPPROTO_IP, socket.AI_CANONNAME):
+ af, socktype, proto, canonname, sa = res
+
+ return sa[0]
+
+
class FileHandler(BaseHandler):
# Use local file or FTP depending on form of URL
def file_open(self, req):
@@ -1233,10 +1251,10 @@
def get_names(self):
if FileHandler.names is None:
try:
- FileHandler.names = (socket.gethostbyname('localhost'),
- socket.gethostbyname(socket.gethostname()))
+ FileHandler.names = (gethost_addrinfo('localhost'),
+ gethost_addrinfo(socket.gethostname()))
except socket.gaierror:
- FileHandler.names = (socket.gethostbyname('localhost'),)
+ FileHandler.names = (gethost_addrinfo('localhost'),)
return FileHandler.names
# not entirely sure what the rules are here
@@ -1257,7 +1275,7 @@
if host:
host, port = splitport(host)
if not host or \
- (not port and socket.gethostbyname(host) in self.get_names()):
+ (not port and gethost_addrinfo(host) in self.get_names()):
return addinfourl(open(localfile, 'rb'),
headers, 'file:'+file)
except OSError, msg:
@@ -1289,7 +1307,7 @@
passwd = unquote(passwd or '')
try:
- host = socket.gethostbyname(host)
+ host = gethost_addrinfo(host)
except socket.error, msg:
raise URLError(msg)
path, attrs = splitattr(req.get_selector())
More information about the Python-checkins
mailing list