From febb15487a47669374810622481ead399728d861 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Tue, 29 Dec 2015 01:11:19 -0600 Subject: [PATCH] Use Python 3 compatible "except ... as e" syntax Signed-off-by: Rob Browning Tested-by: Rob Browning --- cmd/cat-file-cmd.py | 2 +- cmd/daemon-cmd.py | 4 ++-- cmd/fsck-cmd.py | 4 ++-- cmd/ftp-cmd.py | 12 ++++++------ cmd/help-cmd.py | 2 +- cmd/index-cmd.py | 6 +++--- cmd/init-cmd.py | 2 +- cmd/join-cmd.py | 2 +- cmd/list-idx-cmd.py | 2 +- cmd/memtest-cmd.py | 2 +- cmd/midx-cmd.py | 2 +- cmd/on-cmd.py | 4 ++-- cmd/restore-cmd.py | 4 ++-- cmd/save-cmd.py | 14 +++++++------- cmd/server-cmd.py | 2 +- cmd/split-cmd.py | 2 +- cmd/tag-cmd.py | 4 ++-- cmd/web-cmd.py | 4 ++-- cmd/xstat-cmd.py | 4 ++-- lib/bup/client.py | 8 ++++---- lib/bup/drecurse.py | 8 ++++---- lib/bup/git.py | 14 +++++++------- lib/bup/helpers.py | 18 +++++++++--------- lib/bup/hlinkdb.py | 4 ++-- lib/bup/index.py | 6 +++--- lib/bup/ls.py | 2 +- lib/bup/metadata.py | 34 +++++++++++++++++----------------- lib/bup/options.py | 2 +- lib/bup/t/tbloom.py | 2 +- lib/bup/t/tgit.py | 4 ++-- lib/bup/t/thelpers.py | 4 ++-- lib/bup/t/tmetadata.py | 4 ++-- lib/bup/xstat.py | 6 +++--- main.py | 4 ++-- wvtest.py | 4 ++-- 35 files changed, 101 insertions(+), 101 deletions(-) diff --git a/cmd/cat-file-cmd.py b/cmd/cat-file-cmd.py index 735a239..d8a3dc5 100755 --- a/cmd/cat-file-cmd.py +++ b/cmd/cat-file-cmd.py @@ -37,7 +37,7 @@ if not re.match(r'/*[^/]+/[^/]+', target): try: n = top.lresolve(target) -except vfs.NodeError, e: +except vfs.NodeError as e: o.fatal(e) if isinstance(n, vfs.FakeSymlink): diff --git a/cmd/daemon-cmd.py b/cmd/daemon-cmd.py index 5149c16..8386fc0 100755 --- a/cmd/daemon-cmd.py +++ b/cmd/daemon-cmd.py @@ -30,7 +30,7 @@ for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, af, socktype, proto, canonname, sa = res try: s = socket.socket(af, socktype, proto) - except socket.error, e: + except socket.error as e: continue try: if af == socket.AF_INET6: @@ -41,7 +41,7 @@ for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, s.bind(sa) s.listen(1) fcntl.fcntl(s.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC) - except socket.error, e: + except socket.error as e: s.close() continue socks.append(s) diff --git a/cmd/fsck-cmd.py b/cmd/fsck-cmd.py index a5ab754..94eeb89 100755 --- a/cmd/fsck-cmd.py +++ b/cmd/fsck-cmd.py @@ -76,7 +76,7 @@ def git_verify(base): if opt.quick: try: quick_verify(base) - except Exception, e: + except Exception as e: debug('error: %s\n' % e) return 1 return 0 @@ -201,7 +201,7 @@ for name in extra: else: # child try: sys.exit(do_pack(base, last, par2_exists)) - except Exception, e: + except Exception as e: log('exception: %r\n' % e) sys.exit(99) diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py index 1935266..908932b 100755 --- a/cmd/ftp-cmd.py +++ b/cmd/ftp-cmd.py @@ -19,7 +19,7 @@ class OptionError(Exception): def do_ls(cmd_args): try: ls.do_ls(cmd_args, pwd, onabort=OptionError) - except OptionError, e: + except OptionError as e: return @@ -49,7 +49,7 @@ def _completer_get_subs(line): n = pwd.resolve(dir) subs = list(filter(lambda x: x.name.startswith(name), n.subs())) - except vfs.NoSuchFile, e: + except vfs.NoSuchFile as e: subs = [] return (dir, name, qtype, lastword, subs) @@ -115,12 +115,12 @@ def completer(text, state): ret = shquote.what_to_add(qtype, lastword, fullname, terminate=True) + ' ' return text + ret - except Exception, e: + except Exception as e: log('\n') try: import traceback traceback.print_tb(sys.exc_traceback) - except Exception, e2: + except Exception as e2: log('Error printing traceback: %s\n' % e2) log('\nError in completion: %s\n' % e) @@ -198,7 +198,7 @@ for line in lines: outf = open(n.name, 'wb') write_to_file(inf, outf) outf.close() - except Exception, e: + except Exception as e: rv = 1 log(' error: %s\n' % e) elif cmd == 'help' or cmd == '?': @@ -208,7 +208,7 @@ for line in lines: else: rv = 1 raise Exception('no such command %r' % cmd) - except Exception, e: + except Exception as e: rv = 1 log('error: %s\n' % e) #raise diff --git a/cmd/help-cmd.py b/cmd/help-cmd.py index 2efc729..95155b6 100755 --- a/cmd/help-cmd.py +++ b/cmd/help-cmd.py @@ -26,7 +26,7 @@ elif len(extra) == 1: os.execvp('man', ['man', '-l', g[0]]) else: os.execvp('man', ['man', docname]) - except OSError, e: + except OSError as e: sys.stderr.write('Unable to run man command: %s\n' % e) sys.exit(1) else: diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index e416ac5..73ef558 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -62,7 +62,7 @@ def clear_index(indexfile): os.remove(path) if opt.verbose: log('clear: removed %s\n' % path) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise @@ -111,7 +111,7 @@ def update_index(top, excluded_paths, exclude_rxs): if rig.cur and rig.cur.name == path: # paths that already existed try: meta = metadata.from_path(path, statinfo=pst) - except (OSError, IOError), e: + except (OSError, IOError) as e: add_error(e) rig.next() continue @@ -146,7 +146,7 @@ def update_index(top, excluded_paths, exclude_rxs): else: # new paths try: meta = metadata.from_path(path, statinfo=pst) - except (OSError, IOError), e: + except (OSError, IOError) as e: add_error(e) continue # See same assignment to 0, above, for rationale. diff --git a/cmd/init-cmd.py b/cmd/init-cmd.py index e6cc6b5..fabd98c 100755 --- a/cmd/init-cmd.py +++ b/cmd/init-cmd.py @@ -24,7 +24,7 @@ if extra: try: git.init_repo() # local repo -except git.GitError, e: +except git.GitError as e: log("bup: error: could not init repository: %s" % e) sys.exit(1) diff --git a/cmd/join-cmd.py b/cmd/join-cmd.py index 347206d..8ad322d 100755 --- a/cmd/join-cmd.py +++ b/cmd/join-cmd.py @@ -41,7 +41,7 @@ for id in extra: try: for blob in cat(id): outfile.write(blob) - except KeyError, e: + except KeyError as e: outfile.flush() log('error: %s\n' % e) ret = 1 diff --git a/cmd/list-idx-cmd.py b/cmd/list-idx-cmd.py index 9eb92c1..3bab6b3 100755 --- a/cmd/list-idx-cmd.py +++ b/cmd/list-idx-cmd.py @@ -40,7 +40,7 @@ count = 0 for name in extra: try: ix = git.open_idx(name) - except git.GitError, e: + except git.GitError as e: add_error('%s: %s' % (name, e)) continue if len(opt.find) == 40: diff --git a/cmd/memtest-cmd.py b/cmd/memtest-cmd.py index 65778b7..245bfc9 100755 --- a/cmd/memtest-cmd.py +++ b/cmd/memtest-cmd.py @@ -17,7 +17,7 @@ def linux_memstat(): d = {} try: f = open('/proc/self/status') - except IOError, e: + except IOError as e: if not _linux_warned: log('Warning: %s\n' % e) _linux_warned = 1 diff --git a/cmd/midx-cmd.py b/cmd/midx-cmd.py index eb558f8..d867ad6 100755 --- a/cmd/midx-cmd.py +++ b/cmd/midx-cmd.py @@ -46,7 +46,7 @@ def check_midx(name): log('Checking %s.\n' % nicename) try: ix = git.open_idx(name) - except git.GitError, e: + except git.GitError as e: add_error('%s: %s' % (name, e)) return for count,subname in enumerate(ix.idxnames): diff --git a/cmd/on-cmd.py b/cmd/on-cmd.py index df0fdb3..f76ad3e 100755 --- a/cmd/on-cmd.py +++ b/cmd/on-cmd.py @@ -63,11 +63,11 @@ try: if sp: sp.wait() break - except SigException, e: + except SigException as e: log('\nbup on: %s\n' % e) os.kill(p.pid, e.signum) ret = 84 -except SigException, e: +except SigException as e: if ret == 0: ret = 99 log('\nbup on: %s\n' % e) diff --git a/cmd/restore-cmd.py b/cmd/restore-cmd.py index 49f5176..afcc3a4 100755 --- a/cmd/restore-cmd.py +++ b/cmd/restore-cmd.py @@ -151,7 +151,7 @@ def hardlink_if_possible(fullname, node, meta): try: os.link(target_path, fullname) return True - except OSError, e: + except OSError as e: if e.errno != errno.EXDEV: raise else: @@ -319,7 +319,7 @@ for d in extra: path,name = os.path.split(d) try: n = top.lresolve(d) - except vfs.NodeError, e: + except vfs.NodeError as e: add_error(e) continue isdir = stat.S_ISDIR(n.mode) diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py index 664b580..e48170a 100755 --- a/cmd/save-cmd.py +++ b/cmd/save-cmd.py @@ -81,7 +81,7 @@ refname = opt.name and 'refs/heads/%s' % opt.name or None if opt.remote or is_reverse: try: cli = client.Client(opt.remote) - except client.ClientError, e: + except client.ClientError as e: log('error: %s' % e) sys.exit(1) oldref = refname and cli.read_ref(refname) or None @@ -213,7 +213,7 @@ indexfile = opt.indexfile or git.repo('bupindex') r = index.Reader(indexfile) try: msr = index.MetaStoreReader(indexfile + '.meta') -except IOError, ex: +except IOError as ex: if ex.errno != EACCES: raise log('error: cannot access %r; have you run bup index?' % indexfile) @@ -342,7 +342,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during): # Not indexed, so just grab the FS metadata or use empty metadata. try: meta = metadata.from_path(fs_path) if fs_path else metadata.Metadata() - except (OSError, IOError), e: + except (OSError, IOError) as e: add_error(e) lastskip_name = dir_name meta = metadata.Metadata() @@ -381,7 +381,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during): if stat.S_ISREG(ent.mode): try: f = hashsplit.open_noatime(ent.name) - except (IOError, OSError), e: + except (IOError, OSError) as e: add_error(e) lastskip_name = ent.name else: @@ -389,7 +389,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during): (mode, id) = hashsplit.split_to_blob_or_tree( w.new_blob, w.new_tree, [f], keep_boundaries=False) - except (IOError, OSError), e: + except (IOError, OSError) as e: add_error('%s: %s' % (ent.name, e)) lastskip_name = ent.name else: @@ -398,7 +398,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during): elif stat.S_ISLNK(ent.mode): try: rl = os.readlink(ent.name) - except (OSError, IOError), e: + except (OSError, IOError) as e: add_error(e) lastskip_name = ent.name else: @@ -419,7 +419,7 @@ for (transname,ent) in r.filter(extra, wantrecurse=wantrecurse_during): hlink = find_hardlink_target(hlink_db, ent) try: meta = metadata.from_path(ent.name, hardlink_target=hlink) - except (OSError, IOError), e: + except (OSError, IOError) as e: add_error(e) lastskip_name = ent.name else: diff --git a/cmd/server-cmd.py b/cmd/server-cmd.py index cf7be26..520ea64 100755 --- a/cmd/server-cmd.py +++ b/cmd/server-cmd.py @@ -158,7 +158,7 @@ def cat(conn, id): for blob in cat_pipe.join(id): conn.write(struct.pack('!I', len(blob))) conn.write(blob) - except KeyError, e: + except KeyError as e: log('server: error: %s\n' % e) conn.write('\0\0\0\0') conn.error(e) diff --git a/cmd/split-cmd.py b/cmd/split-cmd.py index b7c7c86..2ad5721 100755 --- a/cmd/split-cmd.py +++ b/cmd/split-cmd.py @@ -125,7 +125,7 @@ if opt.git_ids: try: it = cp.get(line.strip()) next(it, None) # skip the file type - except KeyError, e: + except KeyError as e: add_error('error: %s' % e) continue yield IterToFile(it) diff --git a/cmd/tag-cmd.py b/cmd/tag-cmd.py index f12ea4e..f065904 100755 --- a/cmd/tag-cmd.py +++ b/cmd/tag-cmd.py @@ -64,7 +64,7 @@ if tag_name.startswith('.'): try: hash = git.rev_parse(commit) -except git.GitError, e: +except git.GitError as e: log("bup: error: %s" % e) sys.exit(2) @@ -80,7 +80,7 @@ if not pL.exists(hash): tag_file = git.repo('refs/tags/%s' % tag_name) try: tag = file(tag_file, 'w') -except OSError, e: +except OSError as e: log("bup: error: could not create tag '%s': %s" % (tag_name, e)) sys.exit(3) diff --git a/cmd/web-cmd.py b/cmd/web-cmd.py index acbbb80..640e4ae 100755 --- a/cmd/web-cmd.py +++ b/cmd/web-cmd.py @@ -110,7 +110,7 @@ class BupRequestHandler(tornado.web.RequestHandler): try: show_hidden = int(self.request.arguments.get('hidden', [0])[-1]) - except ValueError, e: + except ValueError as e: show_hidden = False self.render( @@ -229,7 +229,7 @@ if __name__ == "__main__": try: sock = http_server._socket # tornado < 2.0 - except AttributeError, e: + except AttributeError as e: sock = http_server._sockets.values()[0] print "Serving HTTP on %s:%d..." % sock.getsockname() diff --git a/cmd/xstat-cmd.py b/cmd/xstat-cmd.py index c977d1c..f299cbc 100755 --- a/cmd/xstat-cmd.py +++ b/cmd/xstat-cmd.py @@ -18,7 +18,7 @@ def parse_timestamp_arg(field, value): res = str(value) # Undo autoconversion. try: res = parse_timestamp(res) - except ValueError, ex: + except ValueError as ex: if ex.args: o.fatal('unable to parse %s resolution "%s" (%s)' % (field, value, ex)) @@ -82,7 +82,7 @@ first_path = True for path in remainder: try: m = metadata.from_path(path, archive_path = path) - except (OSError,IOError), e: + except (OSError,IOError) as e: if e.errno == errno.ENOENT: add_error(e) continue diff --git a/lib/bup/client.py b/lib/bup/client.py index 54fe9d5..d819e70 100644 --- a/lib/bup/client.py +++ b/lib/bup/client.py @@ -75,7 +75,7 @@ class Client: self.pout = self.p.stdout self.pin = self.p.stdin self.conn = Conn(self.pout, self.pin) - except OSError, e: + except OSError as e: raise ClientError, 'connect: %s' % e, sys.exc_info()[2] elif self.protocol == 'bup': self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -94,7 +94,7 @@ class Client: def __del__(self): try: self.close() - except IOError, e: + except IOError as e: if e.errno == errno.EPIPE: pass else: @@ -130,7 +130,7 @@ class Client: % rv) try: return self.conn.check_ok() - except Exception, e: + except Exception as e: raise ClientError, e, sys.exc_info()[2] def check_busy(self): @@ -332,7 +332,7 @@ class PackWriter_Remote(git.PackWriter): try: (self._bwcount, self._bwtime) = _raw_write_bwlimit( self.file, outbuf, self._bwcount, self._bwtime) - except IOError, e: + except IOError as e: raise ClientError, e, sys.exc_info()[2] self.outbytes += len(data) self.count += 1 diff --git a/lib/bup/drecurse.py b/lib/bup/drecurse.py index 6be7fa2..de8e5aa 100644 --- a/lib/bup/drecurse.py +++ b/lib/bup/drecurse.py @@ -39,7 +39,7 @@ def _dirlist(): for n in os.listdir('.'): try: st = xstat.lstat(n) - except OSError, e: + except OSError as e: add_error(Exception('%s: %s' % (realpath(n), str(e)))) continue if (st.st_mode & _IFMT) == stat.S_IFDIR: @@ -70,7 +70,7 @@ def _recursive_dirlist(prepend, xdev, bup_dir=None, else: try: OsFile(name).fchdir() - except OSError, e: + except OSError as e: add_error('%s: %s' % (prepend, e)) else: for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev, @@ -93,12 +93,12 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None, if stat.S_ISLNK(pst.st_mode): yield (path, pst) continue - except OSError, e: + except OSError as e: add_error('recursive_dirlist: %s' % e) continue try: pfile = OsFile(path) - except OSError, e: + except OSError as e: add_error(e) continue pst = pfile.stat() diff --git a/lib/bup/git.py b/lib/bup/git.py index dbbcbff..a79b9bd 100644 --- a/lib/bup/git.py +++ b/lib/bup/git.py @@ -129,7 +129,7 @@ def auto_midx(objdir): args = [path.exe(), 'midx', '--auto', '--dir', objdir] try: rv = subprocess.call(args, stdout=open('/dev/null', 'w')) - except OSError, e: + except OSError as e: # make sure 'args' gets printed to help with debugging add_error('%r: exception: %s' % (args, e)) raise @@ -139,7 +139,7 @@ def auto_midx(objdir): args = [path.exe(), 'bloom', '--dir', objdir] try: rv = subprocess.call(args, stdout=open('/dev/null', 'w')) - except OSError, e: + except OSError as e: # make sure 'args' gets printed to help with debugging add_error('%r: exception: %s' % (args, e)) raise @@ -502,7 +502,7 @@ class PackIdxList: if not d.get(full): try: ix = open_idx(full) - except GitError, e: + except GitError as e: add_error(e) continue d[full] = ix @@ -594,7 +594,7 @@ class PackWriter: oneblob = ''.join(datalist) try: f.write(oneblob) - except IOError, e: + except IOError as e: raise GitError, e, sys.exc_info()[2] nw = len(oneblob) crc = zlib.crc32(oneblob) & 0xffffffff @@ -953,7 +953,7 @@ def check_repo_or_die(path=None): guess_repo(path) try: os.stat(repo('objects/pack/.')) - except OSError, e: + except OSError as e: if e.errno == errno.ENOENT: log('error: %r is not a bup repository; run "bup init"\n' % repo()) @@ -1015,7 +1015,7 @@ class _AbortableIter: def next(self): try: return self.it.next() - except StopIteration, e: + except StopIteration as e: self.done = True raise except: @@ -1100,7 +1100,7 @@ class CatPipe: readline_result = self.p.stdout.readline() assert(readline_result == '\n') self.inprogress = None - except Exception, e: + except Exception as e: it.abort() raise diff --git a/lib/bup/helpers.py b/lib/bup/helpers.py index 3c4cdb2..5bae5de 100644 --- a/lib/bup/helpers.py +++ b/lib/bup/helpers.py @@ -59,7 +59,7 @@ def _hard_write(fd, buf): raise IOError('select(fd) returned without being writable') try: sz = os.write(fd, buf) - except OSError, e: + except OSError as e: if e.errno != errno.EAGAIN: raise assert(sz >= 0) @@ -129,7 +129,7 @@ def mkdirp(d, mode=None): os.makedirs(d, mode) else: os.makedirs(d) - except OSError, e: + except OSError as e: if e.errno == errno.EEXIST: pass else: @@ -193,7 +193,7 @@ def unlink(f): """ try: os.unlink(f) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise @@ -753,7 +753,7 @@ if _mincore: msize = min(_fmincore_chunk_size, st.st_size - pos) try: m = mmap.mmap(fd, msize, mmap.MAP_PRIVATE, 0, 0, pos) - except mmap.error, ex: + except mmap.error as ex: if ex.errno == errno.EINVAL or ex.errno == errno.ENODEV: # Perhaps the file was a pipe, i.e. "... | bup split ..." return None @@ -878,7 +878,7 @@ def parse_date_or_fatal(str, fatal): For now we expect a string that contains a float.""" try: date = float(str) - except ValueError, e: + except ValueError as e: raise fatal('invalid date format (should be a float): %r' % e) else: return date @@ -895,7 +895,7 @@ def parse_excludes(options, fatal): elif option == '--exclude-from': try: f = open(realpath(parameter)) - except IOError, e: + except IOError as e: raise fatal("couldn't read %s" % parameter) for exclude_path in f.readlines(): # FIXME: perhaps this should be rstrip('\n') @@ -915,12 +915,12 @@ def parse_rx_excludes(options, fatal): if option == '--exclude-rx': try: excluded_patterns.append(re.compile(parameter)) - except re.error, ex: + except re.error as ex: fatal('invalid --exclude-rx pattern (%s): %s' % (parameter, ex)) elif option == '--exclude-rx-from': try: f = open(realpath(parameter)) - except IOError, e: + except IOError as e: raise fatal("couldn't read %s" % parameter) for pattern in f.readlines(): spattern = pattern.rstrip('\n') @@ -928,7 +928,7 @@ def parse_rx_excludes(options, fatal): continue try: excluded_patterns.append(re.compile(spattern)) - except re.error, ex: + except re.error as ex: fatal('invalid --exclude-rx pattern (%s): %s' % (spattern, ex)) return excluded_patterns diff --git a/lib/bup/hlinkdb.py b/lib/bup/hlinkdb.py index 5edb0a6..70f3213 100644 --- a/lib/bup/hlinkdb.py +++ b/lib/bup/hlinkdb.py @@ -15,7 +15,7 @@ class HLinkDB: f = None try: f = open(filename, 'r') - except IOError, e: + except IOError as e: if e.errno == errno.ENOENT: pass else: @@ -67,7 +67,7 @@ class HLinkDB: else: # No data -- delete _filename if it exists. try: os.unlink(self._filename) - except OSError, e: + except OSError as e: if e.errno == errno.ENOENT: pass else: diff --git a/lib/bup/index.py b/lib/bup/index.py index 31f6c11..fdf3043 100644 --- a/lib/bup/index.py +++ b/lib/bup/index.py @@ -174,7 +174,7 @@ class Entry: self.gitmode, self.sha, self.flags, self.children_ofs, self.children_n, self.meta_ofs) - except (DeprecationWarning, struct.error), e: + except (DeprecationWarning, struct.error) as e: log('pack error: %s (%r)\n' % (e, self)) raise @@ -353,7 +353,7 @@ class Reader: f = None try: f = open(filename, 'r+') - except IOError, e: + except IOError as e: if e.errno == errno.ENOENT: pass else: @@ -536,7 +536,7 @@ def reduce_paths(paths): rp = slashappend(rp) p = slashappend(p) xpaths.append((rp, p)) - except OSError, e: + except OSError as e: add_error('reduce_paths: %s' % e) xpaths.sort() diff --git a/lib/bup/ls.py b/lib/bup/ls.py index 72f8b9b..df299e5 100644 --- a/lib/bup/ls.py +++ b/lib/bup/ls.py @@ -120,7 +120,7 @@ def do_ls(args, pwd, default='.', onabort=None, spec_prefix=''): output_node_info(sub, name) else: output_node_info(n, os.path.normpath(path)) - except vfs.NodeError, e: + except vfs.NodeError as e: log('error: %s\n' % e) ret = 1 diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py index 0466345..2243936 100644 --- a/lib/bup/metadata.py +++ b/lib/bup/metadata.py @@ -306,14 +306,14 @@ class Metadata: st = None try: st = xstat.lstat(path) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise if st: if stat.S_ISDIR(st.st_mode): try: os.rmdir(path) - except OSError, e: + except OSError as e: if e.errno in (errno.ENOTEMPTY, errno.EEXIST): msg = 'refusing to overwrite non-empty dir ' + path raise Exception(msg) @@ -340,7 +340,7 @@ class Metadata: elif stat.S_ISSOCK(self.mode): try: os.mknod(path, 0o600 | stat.S_IFSOCK) - except OSError, e: + except OSError as e: if e.errno in (errno.EINVAL, errno.EPERM): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.bind(path) @@ -372,7 +372,7 @@ class Metadata: if lutime and stat.S_ISLNK(self.mode): try: lutime(path, (self.atime, self.mtime)) - except OSError, e: + except OSError as e: if e.errno == errno.EACCES: raise ApplyError('lutime: %s' % e) else: @@ -380,7 +380,7 @@ class Metadata: else: try: utime(path, (self.atime, self.mtime)) - except OSError, e: + except OSError as e: if e.errno == errno.EACCES: raise ApplyError('utime: %s' % e) else: @@ -414,7 +414,7 @@ class Metadata: if uid != -1 or gid != -1: try: os.lchown(path, uid, gid) - except OSError, e: + except OSError as e: if e.errno == errno.EPERM: add_error('lchown: %s' % e) elif sys.platform.startswith('cygwin') \ @@ -451,7 +451,7 @@ class Metadata: try: if stat.S_ISLNK(st.st_mode): self.symlink_target = os.readlink(path) - except OSError, e: + except OSError as e: add_error('readlink: %s' % e) def _encode_symlink_target(self): @@ -498,7 +498,7 @@ class Metadata: if stat.S_ISDIR(st.st_mode): def_acl = posix1e.ACL(filedef=path) def_acls = [def_acl, def_acl] - except EnvironmentError, e: + except EnvironmentError as e: if e.errno not in (errno.EOPNOTSUPP, errno.ENOSYS): raise if acls: @@ -535,7 +535,7 @@ class Metadata: def apply_acl(acl_rep, kind): try: acl = posix1e.ACL(text = acl_rep) - except IOError, e: + except IOError as e: if e.errno == 0: # pylibacl appears to return an IOError with errno # set to 0 if a group referred to by the ACL rep @@ -546,7 +546,7 @@ class Metadata: raise try: acl.applyto(path, kind) - except IOError, e: + except IOError as e: if e.errno == errno.EPERM or e.errno == errno.EOPNOTSUPP: raise ApplyError('POSIX1e ACL applyto: %s' % e) else: @@ -580,7 +580,7 @@ class Metadata: attr = get_linux_file_attr(path) if attr != 0: self.linux_attr = attr - except OSError, e: + except OSError as e: if e.errno == errno.EACCES: add_error('read Linux attr: %s' % e) elif e.errno in (errno.ENOTTY, errno.ENOSYS, errno.EOPNOTSUPP): @@ -612,7 +612,7 @@ class Metadata: return try: set_linux_file_attr(path, self.linux_attr) - except OSError, e: + except OSError as e: if e.errno in (errno.ENOTTY, errno.EOPNOTSUPP, errno.ENOSYS, errno.EACCES): raise ApplyError('Linux chattr: %s (0x%s)' @@ -627,7 +627,7 @@ class Metadata: if not xattr: return try: self.linux_xattr = xattr.get_all(path, nofollow=True) - except EnvironmentError, e: + except EnvironmentError as e: if e.errno != errno.EOPNOTSUPP: raise @@ -664,7 +664,7 @@ class Metadata: return try: existing_xattrs = set(xattr.list(path, nofollow=True)) - except IOError, e: + except IOError as e: if e.errno == errno.EACCES: raise ApplyError('xattr.set %r: %s' % (path, e)) else: @@ -674,7 +674,7 @@ class Metadata: or v != xattr.get(path, k, nofollow=True): try: xattr.set(path, k, v, nofollow=True) - except IOError, e: + except IOError as e: if e.errno == errno.EPERM \ or e.errno == errno.EOPNOTSUPP: raise ApplyError('xattr.set %r: %s' % (path, e)) @@ -684,7 +684,7 @@ class Metadata: for k in existing_xattrs: try: xattr.remove(path, k, nofollow=True) - except IOError, e: + except IOError as e: if e.errno == errno.EPERM: raise ApplyError('xattr.remove %r: %s' % (path, e)) else: @@ -810,7 +810,7 @@ class Metadata: self._apply_linux_xattr_rec): try: apply_metadata(path, restore_numeric_ids=num_ids) - except ApplyError, e: + except ApplyError as e: add_error(e) def same_file(self, other): diff --git a/lib/bup/options.py b/lib/bup/options.py index a15220a..d73aac2 100644 --- a/lib/bup/options.py +++ b/lib/bup/options.py @@ -247,7 +247,7 @@ class Options: """ try: (flags,extra) = self.optfunc(args, self._shortopts, self._longopts) - except getopt.GetoptError, e: + except getopt.GetoptError as e: self.fatal(e) opt = OptDict(aliases=self._aliases) diff --git a/lib/bup/t/tbloom.py b/lib/bup/t/tbloom.py index 467a1cc..25ef661 100644 --- a/lib/bup/t/tbloom.py +++ b/lib/bup/t/tbloom.py @@ -45,7 +45,7 @@ def test_bloom(): skip_test = False try: b = bloom.create('bup.bloom', f=tf, expected=2**28, delaywrite=False) - except EnvironmentError, ex: + except EnvironmentError as ex: (ptr_width, linkage) = platform.architecture() if ptr_width == '32bit' and ex.errno == errno.ENOMEM: WVMSG('skipping large bloom filter test (mmap probably failed) ' diff --git a/lib/bup/t/tgit.py b/lib/bup/t/tgit.py index 79010b4..c57e8cd 100644 --- a/lib/bup/t/tgit.py +++ b/lib/bup/t/tgit.py @@ -193,7 +193,7 @@ def test_check_repo_or_die(): open(bupdir + '/objects/pack', 'w').close() try: git.check_repo_or_die() - except SystemExit, e: + except SystemExit as e: WVPASSEQ(e.code, 14) else: WVFAIL() @@ -202,7 +202,7 @@ def test_check_repo_or_die(): try: git.check_repo_or_die('nonexistantbup.tmp') - except SystemExit, e: + except SystemExit as e: WVPASSEQ(e.code, 15) else: WVFAIL() diff --git a/lib/bup/t/thelpers.py b/lib/bup/t/thelpers.py index 10ebce1..ee8df51 100644 --- a/lib/bup/t/thelpers.py +++ b/lib/bup/t/thelpers.py @@ -121,7 +121,7 @@ def test_readpipe(): WVPASSEQ(x, '42\n') try: readpipe(['bash', '-c', 'exit 42']) - except Exception, ex: + except Exception as ex: WVPASSEQ(str(ex), "subprocess 'bash -c exit 42' failed with status 42") @@ -135,7 +135,7 @@ def test_batchpipe(): WVPASSEQ(out, '42\n') try: batchpipe(['bash', '-c'], ['exit 42']) - except Exception, ex: + except Exception as ex: WVPASSEQ(str(ex), "subprocess 'bash -c exit 42' failed with status 42") args = [str(x) for x in range(6)] # Force batchpipe to break the args into batches of 3. This diff --git a/lib/bup/t/tmetadata.py b/lib/bup/t/tmetadata.py index dbd5fe2..4aa87cc 100644 --- a/lib/bup/t/tmetadata.py +++ b/lib/bup/t/tmetadata.py @@ -23,7 +23,7 @@ def ex(*cmd): elif rc > 0: print >> sys.stderr, 'returned exit status', rc sys.exit(1) - except OSError, e: + except OSError as e: print >> sys.stderr, 'subprocess call failed:', e sys.exit(1) @@ -187,7 +187,7 @@ def _linux_attr_supported(path): return False try: metadata.get_linux_file_attr(path) - except OSError, e: + except OSError as e: if e.errno in (errno.ENOTTY, errno.ENOSYS, errno.EOPNOTSUPP): return False else: diff --git a/lib/bup/xstat.py b/lib/bup/xstat.py index 7408414..37f90be 100644 --- a/lib/bup/xstat.py +++ b/lib/bup/xstat.py @@ -5,17 +5,17 @@ from bup import _helpers try: _bup_utimensat = _helpers.bup_utimensat -except AttributeError, e: +except AttributeError as e: _bup_utimensat = False try: _bup_utimes = _helpers.bup_utimes -except AttributeError, e: +except AttributeError as e: _bup_utimes = False try: _bup_lutimes = _helpers.bup_lutimes -except AttributeError, e: +except AttributeError as e: _bup_lutimes = False diff --git a/main.py b/main.py index ef22957..b149bba 100755 --- a/main.py +++ b/main.py @@ -80,7 +80,7 @@ if len(argv) < 2: try: optspec = ['help', 'version', 'debug', 'profile', 'bup-dir='] global_args, subcmd = getopt.getopt(argv[1:], '?VDd:', optspec) -except getopt.GetoptError, ex: +except getopt.GetoptError as ex: usage('error: %s' % ex.msg) help_requested = None @@ -195,7 +195,7 @@ try: ret = p.wait() forward_signals = False break - except OSError, e: + except OSError as e: log('%s: %s\n' % (subcmd[0], e)) ret = 98 finally: diff --git a/wvtest.py b/wvtest.py index ef03381..fdb4822 100755 --- a/wvtest.py +++ b/wvtest.py @@ -122,7 +122,7 @@ if __name__ != '__main__': # we're imported as a module ''' try: func(*args, **kwargs) - except etype, e: + except etype as e: return _check(True, 'EXCEPT(%s)' % _code()) except: _check(False, 'EXCEPT(%s)' % _code()) @@ -186,7 +186,7 @@ def _runtest(fname, f): sys.stdout.flush() try: _run_in_chdir(os.path.split(mod.__file__)[0], f) - except Exception, e: + except Exception as e: print print traceback.format_exc() tb = sys.exc_info()[2] -- 2.39.2