[Zope3-checkins] SVN: Zope3/trunk/src/ Massive style cleanup: Move
to new raise exception style; for motivation, see:
Martijn Pieters
mj at zopatista.com
Tue Aug 30 18:22:24 EDT 2005
Log message for revision 38187:
Massive style cleanup: Move to new raise exception style; for motivation, see:
http://permalink.gmane.org/gmane.comp.web.zope.zope3/13884
Changed:
U Zope3/trunk/src/bugtracker/batching/__init__.py
U Zope3/trunk/src/bugtracker/exportimport.py
U Zope3/trunk/src/bugtracker/vocabulary.py
U Zope3/trunk/src/bugtracker/xmlrpc.py
U Zope3/trunk/src/optionstorage/__init__.py
U Zope3/trunk/src/pytz/__init__.py
U Zope3/trunk/src/pytz/tzinfo.py
U Zope3/trunk/src/z3checkins/tests/test_browser.py
U Zope3/trunk/src/zodbcode/class_.py
U Zope3/trunk/src/zodbcode/function.py
U Zope3/trunk/src/zodbcode/module.py
U Zope3/trunk/src/zwiki/diff.py
U Zope3/trunk/src/zwiki/traversal.py
U Zope3/trunk/src/zwiki/wikipage.py
-=-
Modified: Zope3/trunk/src/bugtracker/batching/__init__.py
===================================================================
--- Zope3/trunk/src/bugtracker/batching/__init__.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/bugtracker/batching/__init__.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -27,7 +27,7 @@
if len(list) == 0:
self.start = -1
elif start >= len(list):
- raise IndexError, 'start index key out of range'
+ raise IndexError('start index key out of range')
self.size = size
self.trueSize = size
if start+size >= len(list):
@@ -39,7 +39,7 @@
def __getitem__(self, key):
if key >= self.trueSize:
- raise IndexError, 'batch index out of range'
+ raise IndexError('batch index out of range')
return self.list[self.start+key]
def __iter__(self):
Modified: Zope3/trunk/src/bugtracker/exportimport.py
===================================================================
--- Zope3/trunk/src/bugtracker/exportimport.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/bugtracker/exportimport.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -243,7 +243,7 @@
def startElement(self, name, attrs):
handler = getattr(self, 'start' + name.title().replace('-', ''), None)
if not handler:
- raise ValueError, 'Unknown element %s' % name
+ raise ValueError('Unknown element %s' % name)
handler(attrs)
Modified: Zope3/trunk/src/bugtracker/vocabulary.py
===================================================================
--- Zope3/trunk/src/bugtracker/vocabulary.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/bugtracker/vocabulary.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -100,7 +100,7 @@
if value == self.default.value:
error_msg = _("Cannot delete default value '${value}'.")
error_msg.mapping = {'value': value}
- raise ValueError, error_msg
+ raise ValueError(error_msg)
del self.annotations[self.key][value]
def _getRealContext(self, context):
@@ -124,7 +124,7 @@
error_msg = _("The value '${value}' was not found in the "
"vocabulary")
error_msg.mapping = {'value': value}
- raise ValueError, error_msg
+ raise ValueError(error_msg)
self.annotations[self.key+'/default'] = value
default = property(getDefault, setDefault)
@@ -246,9 +246,8 @@
try:
vocab = registry.get(instance, self._vocab_name)
if value not in vocab:
- raise ValueError, \
- "The value '%s' was not found in vocabulary '%s'" %(
- value, self._vocab_name)
+ raise ValueError("The value '%s' was not found in vocabulary "
+ "'%s'" % (value, self._vocab_name))
except TypeError:
# We cannot assume that the bug will always have a context to
# find the vocabulary data. In these cases, we just skip the
Modified: Zope3/trunk/src/bugtracker/xmlrpc.py
===================================================================
--- Zope3/trunk/src/bugtracker/xmlrpc.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/bugtracker/xmlrpc.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -169,7 +169,7 @@
if encoding == 'base64':
attach.data = base64.decodestring(data)
else:
- raise UnknownEncoding, 'The encoding is not known: %s' %encoding
+ raise UnknownEncoding('The encoding is not known: %s' % encoding)
attach = contained(attach, self.context, name=name)
self.context[name] = attach
return zapi.name(attach)
@@ -201,7 +201,7 @@
if encoding == 'base64':
return base64.encodestring(self.context.data)
else:
- raise UnknownEncoding, 'The encoding is not known: %s' %encoding
+ raise UnknownEncoding('The encoding is not known: %s' % encoding)
def setData(self, data, encoding='base64'):
"""Set the data of the attachment converting from the specified
@@ -209,4 +209,4 @@
if encoding == 'base64':
self.context.data = base64.decodestring(data)
else:
- raise UnknownEncoding, 'The encoding is not known: %s' %encoding
+ raise UnknownEncoding('The encoding is not known: %s' % encoding)
Modified: Zope3/trunk/src/optionstorage/__init__.py
===================================================================
--- Zope3/trunk/src/optionstorage/__init__.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/optionstorage/__init__.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -76,7 +76,7 @@
marker = object()
cell = self.queryCell(rowkey, colkey, marker)
if cell is marker:
- raise KeyError, "Invalid row/column pair"
+ raise KeyError("Invalid row/column pair")
return cell
def getRow(self, rowkey):
@@ -197,7 +197,7 @@
def __set__(self, object, value):
if self._readonly:
- raise AttributeError, "Attribute '%s' is read-only" % self._name
+ raise AttributeError("Attribute '%s' is read-only" % self._name)
if type(value) is not list:
values = [value]
else:
@@ -207,8 +207,8 @@
keys = dict.getKeys()
invalid = [x for x in values if x not in keys]
if invalid:
- raise ValueError, "Invalid values: %s" % \
- ", ".join(map(repr, invalid))
+ raise ValueError("Invalid values: %s" % ", ".join(
+ map(repr, invalid)))
if self._islist:
value = values
setattr(object, self._name, value)
Modified: Zope3/trunk/src/pytz/__init__.py
===================================================================
--- Zope3/trunk/src/pytz/__init__.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/pytz/__init__.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -54,7 +54,7 @@
try:
module = __import__(module_name, globals(), locals())
except ImportError:
- raise KeyError, zone
+ raise KeyError(zone)
rv = module
for bit in zone_bits[1:]:
rv = getattr(rv, bit)
@@ -102,13 +102,13 @@
def localize(self, dt, is_dst=False):
'''Convert naive time to local time'''
if dt.tzinfo is not None:
- raise ValueError, 'Not naive datetime (tzinfo is already set)'
+ raise ValueError('Not naive datetime (tzinfo is already set)')
return dt.replace(tzinfo=self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime'''
if dt.tzinfo is None:
- raise ValueError, 'Naive time - no tzinfo set'
+ raise ValueError('Naive time - no tzinfo set')
return dt.replace(tzinfo=self)
def __repr__(self):
Modified: Zope3/trunk/src/pytz/tzinfo.py
===================================================================
--- Zope3/trunk/src/pytz/tzinfo.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/pytz/tzinfo.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -84,13 +84,13 @@
def localize(self, dt, is_dst=False):
'''Convert naive time to local time'''
if dt.tzinfo is not None:
- raise ValueError, 'Not naive datetime (tzinfo is already set)'
+ raise ValueError('Not naive datetime (tzinfo is already set)')
return dt.replace(tzinfo=self)
def normalize(self, dt, is_dst=False):
'''Correct the timezone information on the given datetime'''
if dt.tzinfo is None:
- raise ValueError, 'Naive time - no tzinfo set'
+ raise ValueError('Naive time - no tzinfo set')
return dt.replace(tzinfo=self)
def __repr__(self):
@@ -177,7 +177,7 @@
'''
if dt.tzinfo is None:
- raise ValueError, 'Naive time - no tzinfo set'
+ raise ValueError('Naive time - no tzinfo set')
# Convert dt in localtime to UTC
offset = dt.tzinfo._utcoffset
@@ -229,7 +229,7 @@
'''
if dt.tzinfo is not None:
- raise ValueError, 'Not naive datetime (tzinfo is already set)'
+ raise ValueError('Not naive datetime (tzinfo is already set)')
# Find the possibly correct timezones. We probably just have one,
# but we might end up with two if we are in the end-of-DST
Modified: Zope3/trunk/src/z3checkins/tests/test_browser.py
===================================================================
--- Zope3/trunk/src/z3checkins/tests/test_browser.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/z3checkins/tests/test_browser.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -733,7 +733,7 @@
elif tag == 'equal':
dump(' ', a, alo, ahi)
else:
- raise ValueError, 'unknown tag ' + `tag`
+ raise ValueError('unknown tag ' + `tag`)
return "\n".join(diff)
Modified: Zope3/trunk/src/zodbcode/class_.py
===================================================================
--- Zope3/trunk/src/zodbcode/class_.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/zodbcode/class_.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -71,12 +71,12 @@
self.clsset(val)
else:
if self.instdescr is None:
- raise AttributeError, self.name
+ raise AttributeError(self.name)
return self.instdescr.__set__(obj, val)
def __delete__(self, obj):
if self.instdescr is None:
- raise AttributeError, self.name
+ raise AttributeError(self.name)
return self.instdescr.__delete__(obj)
# subclass should override
Modified: Zope3/trunk/src/zodbcode/function.py
===================================================================
--- Zope3/trunk/src/zodbcode/function.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/zodbcode/function.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -90,7 +90,7 @@
# principle this code be fixed with C code, but it should be
# done in Python, not Zope.
if func.func_code.co_freevars:
- raise TypeError, "persistent function can not have free variables"
+ raise TypeError("persistent function can not have free variables")
def __repr__(self):
return "<PersistentFunction %s.%s>" % (self._pf_module.__name__,
@@ -104,7 +104,7 @@
# If it wasn't found in __dict__, then it must be a function
# attribute.
if attr == '_pf_func':
- raise AttributeError, attr
+ raise AttributeError(attr)
return getattr(self._pf_func, attr)
def __setattr__(self, attr, value):
Modified: Zope3/trunk/src/zodbcode/module.py
===================================================================
--- Zope3/trunk/src/zodbcode/module.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/zodbcode/module.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -131,7 +131,7 @@
def new(self, name, source):
"""Return a new module from a name and source text."""
if self._module is not None:
- raise ValueError, "module already exists"
+ raise ValueError("module already exists")
if "." in name:
parent = self._new_package(name)
else:
@@ -179,7 +179,7 @@
parent = None
for i in range(len(parts)):
if parts[i] == "__init__":
- raise ValueError, "__init__ can not be a package"
+ raise ValueError("__init__ can not be a package")
pname = ".".join(parts[:i+1])
package = self._registry.findModule(pname)
if package is None:
@@ -188,7 +188,7 @@
if parent is not None:
setattr(parent, parts[i], package)
elif not isinstance(package, PersistentPackage):
- raise ValueError, "%s is module" % pname
+ raise ValueError("%s is module" % pname)
parent = package
return parent
@@ -302,7 +302,7 @@
if name in self._modules:
# The name is already in use.
# XXX should raise a better error
- raise ValueError, name
+ raise ValueError(name)
self._p_changed = True
self._modules[name] = module
Modified: Zope3/trunk/src/zwiki/diff.py
===================================================================
--- Zope3/trunk/src/zwiki/diff.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/zwiki/diff.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -58,7 +58,7 @@
elif tag == 'equal':
pass
else:
- raise ValueError, 'unknown tag ' + `tag`
+ raise ValueError('unknown tag ' + `tag`)
return '\n' + join(r, '\n')
Modified: Zope3/trunk/src/zwiki/traversal.py
===================================================================
--- Zope3/trunk/src/zwiki/traversal.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/zwiki/traversal.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -77,6 +77,6 @@
if subobj is _marker:
subobj = getattr(self._page, name, _marker)
if subobj is _marker:
- raise TraversalError, name
+ raise TraversalError(name)
return subobj
Modified: Zope3/trunk/src/zwiki/wikipage.py
===================================================================
--- Zope3/trunk/src/zwiki/wikipage.py 2005-08-30 22:10:10 UTC (rev 38186)
+++ Zope3/trunk/src/zwiki/wikipage.py 2005-08-30 22:22:23 UTC (rev 38187)
@@ -188,7 +188,7 @@
def __getitem__(self, key):
v = self.get(key, self)
if v is self:
- raise KeyError, key
+ raise KeyError(key)
return v
def values(self):
More information about the Zope3-Checkins
mailing list