summaryrefslogtreecommitdiffstats
path: root/Lib/urllib2.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-02-15 21:19:18 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-02-15 21:19:18 (GMT)
commita79449e7a2c34daa622c01b66b8a8bd681089176 (patch)
treeaec26cbbd54544dcc17d9098cc647a8a94d28a3d /Lib/urllib2.py
parentd3f4a1a00a0c40a57a0a6054dd822271d114c557 (diff)
downloadcpython-a79449e7a2c34daa622c01b66b8a8bd681089176.zip
cpython-a79449e7a2c34daa622c01b66b8a8bd681089176.tar.gz
cpython-a79449e7a2c34daa622c01b66b8a8bd681089176.tar.bz2
Patch #711838: Allow non-anonymous ftp urls in urllib2.
Backported to 2.3.
Diffstat (limited to 'Lib/urllib2.py')
-rw-r--r--Lib/urllib2.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 0980ce2..9f6dc63 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -115,7 +115,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
@@ -1090,21 +1090,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'