diff -r d9c98730e2e8 Lib/urllib/request.py --- a/Lib/urllib/request.py Sat Jul 07 13:34:50 2012 +1000 +++ b/Lib/urllib/request.py Sat Jul 07 16:29:00 2012 +0100 @@ -1453,19 +1453,19 @@ raise URLError(msg) path, attrs = splitattr(req.selector) dirs = path.split('/') - dirs = list(map(unquote, dirs)) - dirs, file = dirs[:-1], dirs[-1] + dirs = [unquote(d) for d in dirs] + dirs, filename = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] try: fw = self.connect_ftp(user, passwd, host, port, dirs, req.timeout) - type = file and 'I' or 'D' + filetype = filename and 'I' or 'D' for attr in attrs: attr, value = splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): - type = value.upper() - fp, retrlen = fw.retrfile(file, type) + filetype = value.upper() + fp, retrlen = fw.retrfile(filename, filetype) headers = "" mtype = mimetypes.guess_type(req.full_url)[0] if mtype: @@ -1665,13 +1665,13 @@ def open_unknown(self, fullurl, data=None): """Overridable interface to open unknown URL type.""" - type, url = splittype(fullurl) - raise IOError('url error', 'unknown url type', type) + urltype, url = splittype(fullurl) + raise IOError('url error', 'unknown url type', urltype) def open_unknown_proxy(self, proxy, fullurl, data=None): """Overridable interface to open unknown URL type.""" - type, url = splittype(fullurl) - raise IOError('url error', 'invalid proxy for %s' % type, proxy) + urltype, url = splittype(fullurl) + raise IOError('url error', 'invalid proxy for %s' % urltype, proxy) # External interface def retrieve(self, url, filename=None, reporthook=None, data=None): @@ -1680,8 +1680,8 @@ url = unwrap(to_bytes(url)) if self.tempcache and url in self.tempcache: return self.tempcache[url] - type, url1 = splittype(url) - if filename is None and (not type or type == 'file'): + urltype, url1 = splittype(url) + if filename is None and (not urltype or urltype == 'file'): try: fp = self.open_local_file(url1) hdrs = fp.info() @@ -1931,7 +1931,7 @@ path, attrs = splitattr(path) path = unquote(path) dirs = path.split('/') - dirs, file = dirs[:-1], dirs[-1] + dirs, filename = dirs[:-1], dirs[-1] if dirs and not dirs[0]: dirs = dirs[1:] if dirs and not dirs[0]: dirs[0] = '/' key = user, host, port, '/'.join(dirs) @@ -1947,14 +1947,14 @@ if key not in self.ftpcache: self.ftpcache[key] = \ ftpwrapper(user, passwd, host, port, dirs) - if not file: type = 'D' - else: type = 'I' + if not filename: filetype = 'D' + else: filetype = 'I' for attr in attrs: attr, value = splitvalue(attr) if attr.lower() == 'type' and \ value in ('a', 'A', 'i', 'I', 'd', 'D'): - type = value.upper() - (fp, retrlen) = self.ftpcache[key].retrfile(file, type) + filetype = value.upper() + (fp, retrlen) = self.ftpcache[key].retrfile(filename, filetype) mtype = mimetypes.guess_type("ftp:" + url)[0] headers = "" if mtype: @@ -1978,21 +1978,21 @@ # data := *urlchar # parameter := attribute "=" value try: - [type, data] = url.split(',', 1) + [contenttype, data] = url.split(',', 1) except ValueError: raise IOError('data error', 'bad data URL') - if not type: - type = 'text/plain;charset=US-ASCII' - semi = type.rfind(';') - if semi >= 0 and '=' not in type[semi:]: - encoding = type[semi+1:] - type = type[:semi] + if not contenttype: + contenttype = 'text/plain;charset=US-ASCII' + semi = contenttype.rfind(';') + if semi >= 0 and '=' not in contenttype[semi:]: + encoding = contenttype[semi+1:] + contenttype = contenttype[:semi] else: encoding = '' msg = [] msg.append('Date: %s'%time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(time.time()))) - msg.append('Content-type: %s' % type) + msg.append('Content-type: %s' % contenttype) if encoding == 'base64': # XXX is this encoding/decoding ok? data = base64.decodebytes(data.encode('ascii')).decode('latin-1') @@ -2280,21 +2280,21 @@ for dir in self.dirs: self.ftp.cwd(dir) - def retrfile(self, file, type): + def retrfile(self, filename, filetype): import ftplib self.endtransfer() - if type in ('d', 'D'): cmd = 'TYPE A'; isdir = 1 - else: cmd = 'TYPE ' + type; isdir = 0 + if filetype in ('d', 'D'): cmd = 'TYPE A'; isdir = 1 + else: cmd = 'TYPE ' + filetype; isdir = 0 try: self.ftp.voidcmd(cmd) except ftplib.all_errors: self.init() self.ftp.voidcmd(cmd) conn = None - if file and not isdir: + if filename and not isdir: # Try to retrieve as a file try: - cmd = 'RETR ' + file + cmd = 'RETR ' + filename conn, retrlen = self.ftp.ntransfercmd(cmd) except ftplib.error_perm as reason: if str(reason)[:3] != '550': @@ -2304,16 +2304,16 @@ # Set transfer mode to ASCII! self.ftp.voidcmd('TYPE A') # Try a directory listing. Verify that directory exists. - if file: + if filename: pwd = self.ftp.pwd() try: try: - self.ftp.cwd(file) + self.ftp.cwd(filename) except ftplib.error_perm as reason: raise URLError('ftp error', reason) from reason finally: self.ftp.cwd(pwd) - cmd = 'LIST ' + file + cmd = 'LIST ' + filename else: cmd = 'LIST' conn, retrlen = self.ftp.ntransfercmd(cmd)