Skip to content

Commit eccd835

Browse files
committed
Python 3 preparation: "raise" syntax.
Changing "raise Exception, value" to "raise Exception(value)". Tool-assisted patch. Particular cases to check carefully are the one place in frontends/ZRoundup/ZRoundup.py where a string exception needed to be fixed, and the one in roundup/cgi/client.py involving raising an exception with a traceback (requires three-argument form of raise in Python 2, which as I understand it requires exec() to avoid a Python 3 syntax error).
1 parent 8a30b60 commit eccd835

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+245
-249
lines changed

detectors/creator_resolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def creator_resolution(db, cl, nodeid, newvalues):
2424
if assignedto == creator:
2525
if db.getuid() != creator:
2626
name = db.user.get(creator, 'username')
27-
raise Reject, 'Only the creator (%s) may close this issue'%name
27+
raise Reject('Only the creator (%s) may close this issue'%name)
2828
return
2929

3030
# set the assignedto and status

frontends/ZRoundup/ZRoundup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def index_html(self, REQUEST=None):
208208
client.main()
209209
return ''
210210
except client.NotFound:
211-
raise 'NotFound', REQUEST.URL
211+
raise Exception('NotFound ' + REQUEST.URL)
212212
pass
213213
except:
214214
import traceback

frontends/ZRoundup/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
if not os.path.exists(path):
3333
path = os.path.join(here, 'lib', 'python', 'Products', 'ZRoundup')
3434
if not os.path.exists(path):
35-
raise ValueError, "Can't determine where ZRoundup is installed"
35+
raise ValueError("Can't determine where ZRoundup is installed")
3636

3737
# product initialisation
3838
from ZRoundup import ZRoundup, manage_addZRoundupForm, manage_addZRoundup

roundup/backends/back_anydbm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ def __getattr__(self, classname):
241241
"""A convenient way of calling self.getclass(classname)."""
242242
if classname in self.classes:
243243
return self.classes[classname]
244-
raise AttributeError, classname
244+
raise AttributeError(classname)
245245

246246
def addclass(self, cl):
247247
cn = cl.classname
248248
if cn in self.classes:
249-
raise ValueError, cn
249+
raise ValueError(cn)
250250
self.classes[cn] = cl
251251

252252
# add default Edit and View permissions
@@ -1186,10 +1186,10 @@ def set_inner(self, nodeid, **propvalues):
11861186
return propvalues
11871187

11881188
if 'creation' in propvalues or 'activity' in propvalues:
1189-
raise KeyError, '"creation" and "activity" are reserved'
1189+
raise KeyError('"creation" and "activity" are reserved')
11901190

11911191
if 'id' in propvalues:
1192-
raise KeyError, '"id" is reserved'
1192+
raise KeyError('"id" is reserved')
11931193

11941194
if self.db.journaltag is None:
11951195
raise hyperdb.DatabaseError(_('Database open read-only'))

roundup/backends/back_mysql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def open_connection(self):
184184
raise
185185
except MySQLdb.ProgrammingError as message:
186186
if message[0] != ER.NO_SUCH_TABLE:
187-
raise hyperdb.DatabaseError, message
187+
raise hyperdb.DatabaseError(message)
188188
self.init_dbschema()
189189
self.sql("CREATE TABLE `schema` (`schema` TEXT) ENGINE=%s"%
190190
self.mysql_backend)
@@ -660,7 +660,7 @@ def _handle_integrity_error(self, e, propvalues):
660660
# then the snapshot has already been established.
661661
if e[0] == ER.DUP_ENTRY:
662662
key = propvalues[self.key]
663-
raise ValueError, 'node with key "%s" exists' % key
663+
raise ValueError('node with key "%s" exists' % key)
664664
# We don't know what this exception is; reraise it.
665665
raise
666666

roundup/cgi/PageTemplates/Expressions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Unauthorized(BaseException):
5757
def acquisition_security_filter(orig, inst, name, v, real_validate):
5858
if real_validate(orig, inst, name, v):
5959
return 1
60-
raise Unauthorized, name
60+
raise Unauthorized(name)
6161

6262
def call_with_ns(f, ns, arg=1):
6363
if arg==2:
@@ -102,7 +102,7 @@ def __init__(self, path):
102102
self._path = path = path.strip().split('/')
103103
self._base = base = path.pop(0)
104104
if base and not _valid_name(base):
105-
raise CompilerError, 'Invalid variable name "%s"' % base
105+
raise CompilerError('Invalid variable name "%s"' % base)
106106
# Parse path
107107
self._dp = dp = []
108108
for i in range(len(path)):
@@ -220,7 +220,7 @@ def __init__(self, name, expr, engine):
220220
exp = exp[m.end():]
221221
m = _interp.search(exp)
222222
if '$' in exp:
223-
raise CompilerError, (
223+
raise CompilerError(
224224
'$ must be doubled or followed by a simple path')
225225
parts.append(exp)
226226
expr = ''.join(parts)
@@ -308,7 +308,7 @@ def restrictedTraverse(object, path, securityManager,
308308
o = object[name]
309309
# Check access to the item.
310310
if not validate(object, object, name, o):
311-
raise Unauthorized, name
311+
raise Unauthorized(name)
312312
object = o
313313
continue
314314

roundup/cgi/PageTemplates/MultiMapping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ def __getitem__(self, key):
77
for store in self.stores:
88
if store.has_key(key):
99
return store[key]
10-
raise KeyError, key
10+
raise KeyError(key)
1111
_marker = []
1212
def get(self, key, default=_marker):
1313
for store in self.stores:
1414
if store.has_key(key):
1515
return store[key]
1616
if default is self._marker:
17-
raise KeyError, key
17+
raise KeyError(key)
1818
return default
1919
def __len__(self):
2020
return reduce(operator.add, [len(x) for x in self.stores], 0)

roundup/cgi/PageTemplates/PageTemplate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def pt_render(self, source=0, extra_context={}):
8181
__traceback_supplement__ = (PageTemplateTracebackSupplement, self)
8282

8383
if self._v_errors:
84-
raise PTRuntimeError, 'Page Template %s has errors.' % self.id
84+
raise PTRuntimeError('Page Template %s has errors.' % self.id)
8585
output = self.StringIO()
8686
c = self.pt_getContext()
8787
c.update(extra_context)
@@ -119,13 +119,13 @@ def pt_macros(self):
119119
self._cook()
120120
__traceback_supplement__ = (PageTemplateTracebackSupplement, self)
121121
if self._v_errors:
122-
raise PTRuntimeError, 'Page Template %s has errors.' % self.id
122+
raise PTRuntimeError('Page Template %s has errors.' % self.id)
123123
return self._v_macros
124124

125125
def __getattr__(self, name):
126126
if name == 'macros':
127127
return self.pt_macros()
128-
raise AttributeError, name
128+
raise AttributeError(name)
129129

130130
def pt_source_file(self):
131131
return None # Unknown.

roundup/cgi/PageTemplates/PythonExpr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def __init__(self, name, expr, engine):
3434
exec 'def f():\n return %s\n' % expr.strip() in d
3535
self._f = d['f']
3636
except:
37-
raise CompilerError, ('Python expression error:\n'
38-
'%s: %s') % exc_info()[:2]
37+
raise CompilerError(('Python expression error:\n'
38+
'%s: %s') % exc_info()[:2])
3939
self._get_used_names()
4040

4141
def _get_used_names(self):

roundup/cgi/PageTemplates/TALES.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ def __init__(self, Iterator=None):
112112

113113
def registerType(self, name, handler):
114114
if not _valid_name(name):
115-
raise RegistrationError, 'Invalid Expression type "%s".' % name
115+
raise RegistrationError('Invalid Expression type "%s".' % name)
116116
types = self.types
117117
if types.has_key(name):
118-
raise RegistrationError, (
118+
raise RegistrationError(
119119
'Multiple registrations for Expression type "%s".' %
120120
name)
121121
types[name] = handler
@@ -134,7 +134,7 @@ def compile(self, expression):
134134
try:
135135
handler = self.types[type]
136136
except KeyError:
137-
raise CompilerError, (
137+
raise CompilerError(
138138
'Unrecognized expression type "%s".' % type)
139139
return handler(type, expr, self)
140140

0 commit comments

Comments
 (0)