Commit 88d8a4bf authored by Hanno Schlichting's avatar Hanno Schlichting

Avoid bare except's and catch Exception instead - this won't catch system...

Avoid bare except's and catch Exception instead - this won't catch system exceptions like KeyboardInterrupt, MemoryError and similar things
parent e4c3b60f
......@@ -45,24 +45,30 @@ class CatalogAware:
def manage_afterAdd(self, item, container):
self.index_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
try:
s = object._p_changed
except Exception:
s = 0
object.manage_afterAdd(item, container)
if s is None: object._p_deactivate()
def manage_afterClone(self, item):
self.index_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
try:
s = object._p_changed
except Exception:
s = 0
object.manage_afterClone(item)
if s is None: object._p_deactivate()
def manage_beforeDelete(self, item, container):
self.unindex_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
try:
s = object._p_changed
except Exception:
s = 0
object.manage_beforeDelete(item, container)
if s is None: object._p_deactivate()
......
......@@ -43,13 +43,6 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
def getURL(self, relative=0):
"""Generate a URL for this record"""
# XXX The previous implementation attempted to eat errors coming from
# REQUEST.physicalPathToURL. Unfortunately it also ate
# ConflictErrors (from getPath), which is bad. Staring at the
# relevent code in HTTPRequest.py it's unclear to me what could be
# raised by it so I'm removing the exception handling here all
# together. If undesired exceptions get raised somehow we should
# avoid bare except band-aids and find a real solution.
return self.REQUEST.physicalPathToURL(self.getPath(), relative)
def _unrestrictedGetObject(self):
......@@ -61,7 +54,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
return self.aq_parent.unrestrictedTraverse(self.getPath())
except ConflictError:
raise
except:
except Exception:
if GETOBJECT_RAISES:
raise
return None
......@@ -86,7 +79,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
parent = parent.unrestrictedTraverse(path[:-1])
except ConflictError:
raise
except:
except Exception:
if GETOBJECT_RAISES:
raise
return None
......@@ -95,7 +88,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
target = parent.restrictedTraverse(path[-1])
except ConflictError:
raise
except:
except Exception:
if GETOBJECT_RAISES:
raise
return None
......
......@@ -41,24 +41,30 @@ class CatalogAware:
def manage_afterAdd(self, item, container):
self.index_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
try:
s = object._p_changed
except Exception:
s = 0
object.manage_afterAdd(item, container)
if s is None: object._p_deactivate()
def manage_afterClone(self, item):
self.index_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
try:
s = object._p_changed
except Exception:
s = 0
object.manage_afterClone(item)
if s is None: object._p_deactivate()
def manage_beforeDelete(self, item, container):
self.unindex_object()
for object in self.objectValues():
try: s=object._p_changed
except: s=0
try:
s = object._p_changed
except Exception:
s = 0
object.manage_beforeDelete(item, container)
if s is None: object._p_deactivate()
......
......@@ -31,7 +31,7 @@ class Lazy(object):
try:
self[l]
l = l + 1
except:
except Exception:
self._len = l
return l
......@@ -99,7 +99,7 @@ class LazyCat(Lazy):
sindex = self._sindex
try:
s = seq[sindex]
except:
except Exception:
raise IndexError(index)
eindex = self._eindex
while i > ind:
......
......@@ -299,7 +299,7 @@ class ZCatalog(Folder, Persistent, Implicit):
self.catalog_object(obj, p, pghandler=pghandler)
except ConflictError:
raise
except:
except Exception:
LOG.error('Recataloging object at %s failed' % p,
exc_info=sys.exc_info())
......@@ -732,12 +732,15 @@ class ZCatalog(Folder, Persistent, Implicit):
if not hasattr(base, 'objectItems'):
return result
try: items=obj.objectItems()
except: return result
try:
items = obj.objectItems()
except Exception:
return result
try: add_result=result.append
except:
raise AttributeError, `result`
try:
add_result = result.append
except Exception:
raise AttributeError(repr(result))
for id, ob in items:
if pre: p="%s/%s" % (pre, id)
......@@ -800,8 +803,10 @@ class ZCatalog(Folder, Persistent, Implicit):
script=REQUEST.script
if path.find(script) != 0:
path='%s/%s' % (script, path)
try: return REQUEST.resolve_url(path)
except: pass
try:
return REQUEST.resolve_url(path)
except Exception:
pass
def resolve_path(self, path):
"""
......@@ -810,8 +815,10 @@ class ZCatalog(Folder, Persistent, Implicit):
style url. If no object is found, None is returned.
No exceptions are raised.
"""
try: return self.unrestrictedTraverse(path)
except: pass
try:
return self.unrestrictedTraverse(path)
except Exception:
pass
def manage_normalize_paths(self, REQUEST):
"""Ensure that all catalog paths are full physical paths
......
......@@ -442,7 +442,7 @@ class TestCatalogObject(unittest.TestCase):
def testBadUncatalog(self):
try:
self._catalog.uncatalogObject('asdasdasd')
except:
except Exception:
self.fail('uncatalogObject raised exception on bad uid')
def testUniqueValuesForLength(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment