]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #711838: Allow non-anonymous ftp urls in urllib2.
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 15 Feb 2004 21:18:47 +0000 (21:18 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 15 Feb 2004 21:18:47 +0000 (21:18 +0000)
Lib/urllib2.py
Misc/NEWS

index 51ab15584c5c225a9aed4cb5801f7c9b6c5a86d9..8c164d63a53c025bec7761a963acce6f7518d3ff 100644 (file)
@@ -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'
index 14e4984e59c333dd79b13fab7576266c0a7fd984..52b6788a49960a301b05d928f5f16100abe923bd 100644 (file)
--- 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)?
 ===================================