[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Ramchandra Apte maniandra...@gmail.com added the comment: Bump. -- nosy: +ramchandra.apte ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Changes by Senthil Kumaran orsent...@gmail.com: -- assignee: facundobatista - orsenthil nosy: -BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Mark Lawrence breamore...@yahoo.co.uk added the comment: @Senthil should this be assigned to your good self? -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Changes by Terry J. Reedy tjre...@udel.edu: -- versions: +Python 3.2 -Python 2.6, Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Changes by Skip Montanaro s...@pobox.com: -- nosy: -skip.montanaro ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Ned Deily n...@acm.org added the comment: Note also Issue5625 - any work for IPv6 should keep in mind that local hosts may have more than one IP address. -- nosy: +nad ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Derek Morr derekm...@psu.edu added the comment: Senthil, I don't think your gethost_addrinfo() function will work. On a v6- enabled machine, it will only return v6 or v4 names. Shouldn't it return both (since a machine could have both v4 and v6 addresses)? For example, on my machine, I have the following addresses for localhost: ::1, fe80::1%lo0, 127.0.0.1. Also, why is the AI_CANONNAME flag set? The canonname field isn't used. And you only appear to take the last IP address returned (sa[0]). Shouldn't you return all the addresses? -- nosy: +dmorr ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Derek Morr derekm...@psu.edu added the comment: Question: Why does FTPHandler.ftp_open() try to resolve the hostname()? The hostname will be passed into connect_ftp(), then into urllib.ftpwrapper(), and eventually into ftplib.FTP.connect(), which is IPv6-aware. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Senthil orsent...@gmail.com added the comment: Derek, This patch was along the lines that when IPv6 address is present, return the first address,which I assumed to be active address and would make the urllib2 work. I am not sure, if returning all the addresses would help and how would we define which address to use? AI_CANONNAME flag, I don't accurately remember it now. But I had encountered issues when testing on IPv-4 systems without it. I am having different opinion on this issue now. First is, taking from Facundo's comment on having this functionality in gethostbyname() and implementing it in C. Second is, the wrapper function and suitable way needs to be defined. I am sorry, I fail to understand the question on why ftp_open does hostname resolution. You mean to say without it, if we pass it to ftplib.FTP.connect() it would work for IPv6 address? ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Derek Morr derekm...@psu.edu added the comment: My understanding is that the FileHandler checks if the file:// URL contains the hostname or localhost IP of the local machine (isn't that what FileHandler.names is for?). So, shouldn't the following URLs all open the same file: file:///foo.txt file://localhost/foo.txt file://127.0.0.1/foo.txt file://[::1]/foo.txt If that is the case, then doesn't FileHandler.names need to have all of those values in it? I am a little confused by this though. It looks like FileHandler.file_open() checks if there is a hostname in the URL, and if so, uses FTPHandler instead. So why does FileHandler.open_local_file check the hostname value? For your other points, gethostbyname() in libc can only handle IPv4 addresses. The IETF defined the getaddrinfo() interface as an IP version neutral replacement. I would recommend using getaddrinfo(). Yes, FTPHandler creates an urllib.FTPWrapper object. That object calls into ftplib, which is already IPv6-capable. So, I don't think we need to do hostname resolution in FTPHandler. ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Senthil orsent...@gmail.com added the comment: I am a little confused by this though. It looks like FileHandler.file_open() checks if there is a hostname in the URL, and if so, uses FTPHandler instead. So why does FileHandler.open_local_file check the hostname value? You are right. Even I had observed this, but did not dispute it. Let me try to look into the history to see why it so. Perhaps it needs to change. For your other points, gethostbyname() in libc can only handle IPv4 addresses. The IETF defined the getaddrinfo() interface as an IP version neutral replacement. I would recommend using getaddrinfo(). Yes, FTPHandler creates an urllib.FTPWrapper object. That object calls into ftplib, which is already IPv6-capable. So, I don't think we need to do hostname resolution in FTPHandler. Thanks for the info. I shall look into both in revision of the path. 1) using getaddrinfo() for IP version neutral call. 2) passing the hostname directly to ftplib. ( I am not sure of consequences, need to investigate). ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Facundo Batista [EMAIL PROTECTED] added the comment: What I don't understand here is... if gethostbyname() lacks of IPv6 support, instead of creating a new function why not to add the functionality to that same function? Right now gethostbyname() is implemented in C, which would be the drawback of making it a Python function? -- assignee: - facundobatista nosy: +facundobatista ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Changes by Senthil [EMAIL PROTECTED]: -- type: - feature request ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue1675455 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Changes by Christian Heimes: -- versions: +Python 2.6, Python 3.0 _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1675455 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Senthil added the comment: Hi, The patch attached required a complete rewrite. I am attaching the modified patch, which will just substitute socket.gethostbyname with a function gethost_addrinfo which internally uses getaddrinfo and takes care of the IPv4 or IPv6 addresses translation. jjlee, skip: let me know your comments on this. One note we have to keep in mind is, testing on IPv6 address. For eg. on my system /etc/hosts 10.98.1.6 goofy.goofy.com #fe80::219:5bff:fefd:6270 localhost 127.0.0.1 localhost test_urllib2 will PASS for the above. But if I uncomment the IPv6 address, opening the local file fails. I am not sure how local file access is done with IPv6 and should urllib2 (local file opening function) itself needs to be modified. Shall check into that, with next version. -- nosy: +orsenthil _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1675455 _--- urllib2.py 2007-09-25 09:05:46.346939560 +0530 +++ urllib2-getaddrinfo.py 2007-09-25 09:04:59.019134480 +0530 @@ -1193,6 +1193,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): @@ -1208,10 +1226,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 @@ -1232,7 +1250,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: @@ -1264,7 +1282,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()) ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1675455] Use getaddrinfo() in urllib2.py for IPv6 support
Changes by Skip Montanaro: -- nosy: +skip.montanaro _ Tracker [EMAIL PROTECTED] http://bugs.python.org/issue1675455 _ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com