|
115 | 115 | # not sure how many of these need to be gotten rid of |
116 | 116 | from urllib import unwrap, unquote, splittype, splithost, \ |
117 | 117 | addinfourl, splitport, splitgophertype, splitquery, \ |
118 | | - splitattr, ftpwrapper, noheaders |
| 118 | + splitattr, ftpwrapper, noheaders, splituser, splitpasswd |
119 | 119 |
|
120 | 120 | # support for FileHandler, proxies via environment variables |
121 | 121 | from urllib import localhost, url2pathname, getproxies |
@@ -1090,21 +1090,30 @@ def ftp_open(self, req): |
1090 | 1090 | host = req.get_host() |
1091 | 1091 | if not host: |
1092 | 1092 | raise IOError, ('ftp error', 'no host given') |
1093 | | - # XXX handle custom username & password |
| 1093 | + host, port = splitport(host) |
| 1094 | + if port is None: |
| 1095 | + port = ftplib.FTP_PORT |
| 1096 | + |
| 1097 | + # username/password handling |
| 1098 | + user, host = splituser(host) |
| 1099 | + if user: |
| 1100 | + user, passwd = splitpasswd(user) |
| 1101 | + else: |
| 1102 | + passwd = None |
| 1103 | + host = unquote(host) |
| 1104 | + user = unquote(user or '') |
| 1105 | + passwd = unquote(passwd or '') |
| 1106 | + |
1094 | 1107 | try: |
1095 | 1108 | host = socket.gethostbyname(host) |
1096 | 1109 | except socket.error, msg: |
1097 | 1110 | raise URLError(msg) |
1098 | | - host, port = splitport(host) |
1099 | | - if port is None: |
1100 | | - port = ftplib.FTP_PORT |
1101 | 1111 | path, attrs = splitattr(req.get_selector()) |
1102 | 1112 | dirs = path.split('/') |
1103 | 1113 | dirs = map(unquote, dirs) |
1104 | 1114 | dirs, file = dirs[:-1], dirs[-1] |
1105 | 1115 | if dirs and not dirs[0]: |
1106 | 1116 | dirs = dirs[1:] |
1107 | | - user = passwd = '' # XXX |
1108 | 1117 | try: |
1109 | 1118 | fw = self.connect_ftp(user, passwd, host, port, dirs) |
1110 | 1119 | type = file and 'I' or 'D' |
|
0 commit comments