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: ...@@ -45,24 +45,30 @@ class CatalogAware:
def manage_afterAdd(self, item, container): def manage_afterAdd(self, item, container):
self.index_object() self.index_object()
for object in self.objectValues(): for object in self.objectValues():
try: s=object._p_changed try:
except: s=0 s = object._p_changed
except Exception:
s = 0
object.manage_afterAdd(item, container) object.manage_afterAdd(item, container)
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
def manage_afterClone(self, item): def manage_afterClone(self, item):
self.index_object() self.index_object()
for object in self.objectValues(): for object in self.objectValues():
try: s=object._p_changed try:
except: s=0 s = object._p_changed
except Exception:
s = 0
object.manage_afterClone(item) object.manage_afterClone(item)
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
def manage_beforeDelete(self, item, container): def manage_beforeDelete(self, item, container):
self.unindex_object() self.unindex_object()
for object in self.objectValues(): for object in self.objectValues():
try: s=object._p_changed try:
except: s=0 s = object._p_changed
except Exception:
s = 0
object.manage_beforeDelete(item, container) object.manage_beforeDelete(item, container)
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
......
...@@ -43,13 +43,6 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit): ...@@ -43,13 +43,6 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
def getURL(self, relative=0): def getURL(self, relative=0):
"""Generate a URL for this record""" """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) return self.REQUEST.physicalPathToURL(self.getPath(), relative)
def _unrestrictedGetObject(self): def _unrestrictedGetObject(self):
...@@ -61,7 +54,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit): ...@@ -61,7 +54,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
return self.aq_parent.unrestrictedTraverse(self.getPath()) return self.aq_parent.unrestrictedTraverse(self.getPath())
except ConflictError: except ConflictError:
raise raise
except: except Exception:
if GETOBJECT_RAISES: if GETOBJECT_RAISES:
raise raise
return None return None
...@@ -86,7 +79,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit): ...@@ -86,7 +79,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
parent = parent.unrestrictedTraverse(path[:-1]) parent = parent.unrestrictedTraverse(path[:-1])
except ConflictError: except ConflictError:
raise raise
except: except Exception:
if GETOBJECT_RAISES: if GETOBJECT_RAISES:
raise raise
return None return None
...@@ -95,7 +88,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit): ...@@ -95,7 +88,7 @@ class AbstractCatalogBrain(Record.Record, Acquisition.Implicit):
target = parent.restrictedTraverse(path[-1]) target = parent.restrictedTraverse(path[-1])
except ConflictError: except ConflictError:
raise raise
except: except Exception:
if GETOBJECT_RAISES: if GETOBJECT_RAISES:
raise raise
return None return None
......
...@@ -41,24 +41,30 @@ class CatalogAware: ...@@ -41,24 +41,30 @@ class CatalogAware:
def manage_afterAdd(self, item, container): def manage_afterAdd(self, item, container):
self.index_object() self.index_object()
for object in self.objectValues(): for object in self.objectValues():
try: s=object._p_changed try:
except: s=0 s = object._p_changed
except Exception:
s = 0
object.manage_afterAdd(item, container) object.manage_afterAdd(item, container)
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
def manage_afterClone(self, item): def manage_afterClone(self, item):
self.index_object() self.index_object()
for object in self.objectValues(): for object in self.objectValues():
try: s=object._p_changed try:
except: s=0 s = object._p_changed
except Exception:
s = 0
object.manage_afterClone(item) object.manage_afterClone(item)
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
def manage_beforeDelete(self, item, container): def manage_beforeDelete(self, item, container):
self.unindex_object() self.unindex_object()
for object in self.objectValues(): for object in self.objectValues():
try: s=object._p_changed try:
except: s=0 s = object._p_changed
except Exception:
s = 0
object.manage_beforeDelete(item, container) object.manage_beforeDelete(item, container)
if s is None: object._p_deactivate() if s is None: object._p_deactivate()
......
...@@ -31,7 +31,7 @@ class Lazy(object): ...@@ -31,7 +31,7 @@ class Lazy(object):
try: try:
self[l] self[l]
l = l + 1 l = l + 1
except: except Exception:
self._len = l self._len = l
return l return l
...@@ -99,7 +99,7 @@ class LazyCat(Lazy): ...@@ -99,7 +99,7 @@ class LazyCat(Lazy):
sindex = self._sindex sindex = self._sindex
try: try:
s = seq[sindex] s = seq[sindex]
except: except Exception:
raise IndexError(index) raise IndexError(index)
eindex = self._eindex eindex = self._eindex
while i > ind: while i > ind:
......
...@@ -299,7 +299,7 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -299,7 +299,7 @@ class ZCatalog(Folder, Persistent, Implicit):
self.catalog_object(obj, p, pghandler=pghandler) self.catalog_object(obj, p, pghandler=pghandler)
except ConflictError: except ConflictError:
raise raise
except: except Exception:
LOG.error('Recataloging object at %s failed' % p, LOG.error('Recataloging object at %s failed' % p,
exc_info=sys.exc_info()) exc_info=sys.exc_info())
...@@ -732,12 +732,15 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -732,12 +732,15 @@ class ZCatalog(Folder, Persistent, Implicit):
if not hasattr(base, 'objectItems'): if not hasattr(base, 'objectItems'):
return result return result
try: items=obj.objectItems() try:
except: return result items = obj.objectItems()
except Exception:
return result
try: add_result=result.append try:
except: add_result = result.append
raise AttributeError, `result` except Exception:
raise AttributeError(repr(result))
for id, ob in items: for id, ob in items:
if pre: p="%s/%s" % (pre, id) if pre: p="%s/%s" % (pre, id)
...@@ -800,8 +803,10 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -800,8 +803,10 @@ class ZCatalog(Folder, Persistent, Implicit):
script=REQUEST.script script=REQUEST.script
if path.find(script) != 0: if path.find(script) != 0:
path='%s/%s' % (script, path) path='%s/%s' % (script, path)
try: return REQUEST.resolve_url(path) try:
except: pass return REQUEST.resolve_url(path)
except Exception:
pass
def resolve_path(self, path): def resolve_path(self, path):
""" """
...@@ -810,8 +815,10 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -810,8 +815,10 @@ class ZCatalog(Folder, Persistent, Implicit):
style url. If no object is found, None is returned. style url. If no object is found, None is returned.
No exceptions are raised. No exceptions are raised.
""" """
try: return self.unrestrictedTraverse(path) try:
except: pass return self.unrestrictedTraverse(path)
except Exception:
pass
def manage_normalize_paths(self, REQUEST): def manage_normalize_paths(self, REQUEST):
"""Ensure that all catalog paths are full physical paths """Ensure that all catalog paths are full physical paths
......
...@@ -442,7 +442,7 @@ class TestCatalogObject(unittest.TestCase): ...@@ -442,7 +442,7 @@ class TestCatalogObject(unittest.TestCase):
def testBadUncatalog(self): def testBadUncatalog(self):
try: try:
self._catalog.uncatalogObject('asdasdasd') self._catalog.uncatalogObject('asdasdasd')
except: except Exception:
self.fail('uncatalogObject raised exception on bad uid') self.fail('uncatalogObject raised exception on bad uid')
def testUniqueValuesForLength(self): 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