From e73a417feb6576451d2d0a643c50beb16d62835f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Sun, 15 Feb 2004 21:18:47 +0000 Subject: Patch #711838: Allow non-anonymous ftp urls in urllib2. --- Lib/urllib2.py | 21 +++++++++++++++------ Misc/NEWS | 1 + 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 51ab155..8c164d6 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -114,7 +114,7 @@ except ImportError: # not sure how many of these need to be gotten rid of from urllib import unwrap, unquote, splittype, splithost, \ addinfourl, splitport, splitgophertype, splitquery, \ - splitattr, ftpwrapper, noheaders + splitattr, ftpwrapper, noheaders, splituser, splitpasswd # support for FileHandler, proxies via environment variables from urllib import localhost, url2pathname, getproxies @@ -1012,21 +1012,30 @@ class FTPHandler(BaseHandler): host = req.get_host() if not host: raise IOError, ('ftp error', 'no host given') - # XXX handle custom username & password + host, port = splitport(host) + if port is None: + port = ftplib.FTP_PORT + + # username/password handling + user, host = splituser(host) + if user: + user, passwd = splitpasswd(user) + else: + passwd = None + host = unquote(host) + user = unquote(user or '') + passwd = unquote(passwd or '') + try: host = socket.gethostbyname(host) except socket.error, msg: raise URLError(msg) - host, port = splitport(host) - if port is None: - port = ftplib.FTP_PORT path, attrs = splitattr(req.get_selector()) dirs = path.split('/') dirs = map(unquote, dirs) dirs, file = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] - user = passwd = '' # XXX try: fw = self.connect_ftp(user, passwd, host, port, dirs) type = file and 'I' or 'D' diff --git a/Misc/NEWS b/Misc/NEWS index 14e4984..52b6788 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -36,6 +36,7 @@ Library - Patch 817379: Allow absolute ftp paths in urllib2. +- Patch 711838: Support non-anonymous ftp URLs in urllib2. What's New in Python 2.3.3 (final)? =================================== -- cgit v0.12