From 171206b508a85f9e9fd5cdba18145b18285bc7ef Mon Sep 17 00:00:00 2001 Message-Id: <171206b508a85f9e9fd5cdba18145b18285bc7ef.1715017651.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 27 May 2018 15:59:13 +0100 Subject: [PATCH] (Python): Use more modern `raise' syntax. Organization: Straylight/Edgeware From: Mark Wooding --- keys/tripe-keys.in | 6 +++--- mon/tripemon.in | 4 ++-- peerdb/tripe-newpeers.in | 8 ++++---- py/rmcr.py | 2 +- py/tripe.py.in | 24 ++++++++++++------------ svc/conntrack.in | 2 +- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/keys/tripe-keys.in b/keys/tripe-keys.in index 593f1423..4ec89e90 100644 --- a/keys/tripe-keys.in +++ b/keys/tripe-keys.in @@ -166,7 +166,7 @@ def run(args): SYS.stdout.flush() rc = OS.spawnvp(OS.P_WAIT, args[0], args) if rc != 0: - raise SubprocessError, rc + raise SubprocessError(rc) def hexhyphens(bytes): """ @@ -217,7 +217,7 @@ def conf_read(f): if line[-1] == '\n': line = line[:-1] match = rx_keyval.match(line) if not match: - raise ConfigFileError, "%s:%d: bad line `%s'" % (f, lno, line) + raise ConfigFileError("%s:%d: bad line `%s'" % (f, lno, line)) k, v = match.groups() conf[k] = conf_subst(v) @@ -489,7 +489,7 @@ def cmd_update(args): ## Verify the signature want = C.bytes(rx_nonalpha.sub('', conf['hk-master'])) got = fingerprint('repos/master.pub', 'master-%d' % seq) - if want != got: raise VerifyError + if want != got: raise VerifyError() run('''catsign -krepos/master.pub verify -avC -kmaster-%d -t${sig-fresh} tripe-keys.sig tripe-keys.tar.gz''' % seq) diff --git a/mon/tripemon.in b/mon/tripemon.in index 7f48bd29..24709344 100644 --- a/mon/tripemon.in +++ b/mon/tripemon.in @@ -40,7 +40,7 @@ import re as RX from cStringIO import StringIO try: - if OS.getenv('TRIPEMON_FORCE_GI'): raise ImportError + if OS.getenv('TRIPEMON_FORCE_GI'): raise ImportError() import pygtk pygtk.require('2.0') import gtk as G @@ -773,7 +773,7 @@ class ValidatingEntry (G.Entry): ValidationError. """ if not me.validp: - raise ValidationError + raise ValidationError() return G.Entry.get_text(me) def numericvalidate(min = None, max = None): diff --git a/peerdb/tripe-newpeers.in b/peerdb/tripe-newpeers.in index 700e69d7..f1232551 100644 --- a/peerdb/tripe-newpeers.in +++ b/peerdb/tripe-newpeers.in @@ -92,7 +92,7 @@ class BulkResolver (object): """ addr = me._namemap[host] if addr is None: - raise KeyError, host + raise KeyError(host) return addr def _resolved(me, host, addr): @@ -236,7 +236,7 @@ class MyConfigParser (CP.RawConfigParser): pass else: if threadp: - raise InheritanceCycleError, (key, path) + raise InheritanceCycleError(key, path) ## See whether the answer is ready waiting for us. try: @@ -272,7 +272,7 @@ class MyConfigParser (CP.RawConfigParser): value = v winner = pp elif value != v: - raise AmbiguousOptionError, (key, winner, value, pp, v) + raise AmbiguousOptionError(key, winner, value, pp, v) ## That's the best we could manage. path.pop() @@ -291,7 +291,7 @@ class MyConfigParser (CP.RawConfigParser): else: value, _ = me._get(sec, key) if value is None: - raise MissingKeyException, (sec, key) + raise MissingKeyException(sec, key) ## Expand the value and return it. return me._expand(sec, value, resolvep) diff --git a/py/rmcr.py b/py/rmcr.py index e2c03252..6c846cb8 100644 --- a/py/rmcr.py +++ b/py/rmcr.py @@ -50,7 +50,7 @@ def _switchto(cr, arg = None, exc = None): global active _debug('> _switchto(%s, %s, %s)' % (cr, arg, exc)) if not cr.livep: - raise ValueError, 'coroutine is dead' + raise ValueError('coroutine is dead') cr._arg = arg cr._exc = exc if cr is active: diff --git a/py/tripe.py.in b/py/tripe.py.in index be24cc85..5562d7b3 100644 --- a/py/tripe.py.in +++ b/py/tripe.py.in @@ -109,7 +109,7 @@ import os as OS try: if OS.getenv('TRIPE_FORCE_RMCR') is not None: - raise ImportError + raise ImportError() from py.magic import greenlet as _Coroutine except ImportError: from rmcr import Coroutine as _Coroutine @@ -508,7 +508,7 @@ class TripeCommandIterator (object): """ me.dcr = Coroutine.getcurrent().parent if me.dcr is None: - raise ValueError, 'must invoke from coroutine' + raise ValueError('must invoke from coroutine') me.filter = filter or (lambda x: x) if bg: words = [words[0], '-background', dispatcher.bgtag()] + list(words[1:]) @@ -532,17 +532,17 @@ class TripeCommandIterator (object): if code == 'INFO': return me.filter(rest) elif code == 'OK': - raise StopIteration + raise StopIteration() elif code == 'CONNERR': if rest is None: - raise TripeConnectionError, 'connection terminated by user' + raise TripeConnectionError('connection terminated by user') else: raise rest elif code == 'FAIL': raise TripeError(*rest) else: - raise TripeInternalError \ - ('unexpected tripe response %r' % ([code] + rest)) + raise TripeInternalError('unexpected tripe response %r' % + ([code] + rest)) ### Simple utility functions for the TripeCommandIterator convenience ### methods. @@ -1172,7 +1172,7 @@ class TripeServiceCommand (object): """ if (me.min is not None and len(args) < me.min) or \ (me.max is not None and len(args) > me.max): - raise TripeSyntaxError + raise TripeSyntaxError() me.func(*args) class TripeServiceJob (Coroutine): @@ -1383,12 +1383,12 @@ class OptParse (object): if len(me.args) == 0 or \ len(me.args[0]) < 2 or \ not me.args[0].startswith('-'): - raise StopIteration + raise StopIteration() opt = me.args.pop(0) if opt == '--': - raise StopIteration + raise StopIteration() if opt not in me.allowed: - raise TripeSyntaxError + raise TripeSyntaxError() return opt def arg(me): @@ -1398,7 +1398,7 @@ class OptParse (object): If none is available, raise `TripeSyntaxError'. """ if len(me.args) == 0: - raise TripeSyntaxError + raise TripeSyntaxError() return me.args.pop(0) def rest(me, min = None, max = None): @@ -1410,7 +1410,7 @@ class OptParse (object): """ if (min is not None and len(me.args) < min) or \ (max is not None and len(me.args) > max): - raise TripeSyntaxError + raise TripeSyntaxError() return me.args ###----- That's all, folks -------------------------------------------------- diff --git a/svc/conntrack.in b/svc/conntrack.in index 73793037..3368295a 100644 --- a/svc/conntrack.in +++ b/svc/conntrack.in @@ -211,7 +211,7 @@ def cmd_showgroup(g): pats = p break else: - raise T.TripeJobError, 'unknown-group', g + raise T.TripeJobError('unknown-group', g) for t, p, a, m in pats: T.svcinfo('peer', t, 'target', p or '(default)', -- [mdw]