Commit ecc18276 authored by Hanno Schlichting's avatar Hanno Schlichting

Avoid bare except's.

parent ca5312b4
......@@ -35,7 +35,7 @@ class FuncCode:
try:
return cmp((self.co_argcount, self.co_varnames),
(other.co_argcount, other.co_varnames))
except:
except Exception:
return 1
......@@ -182,7 +182,7 @@ def getObject(module, name, reload=0,
else:
try:
execsrc = open(path)
except:
except Exception:
raise NotFound("The specified module, '%s', "
"couldn't be opened." % module)
module_dict = {}
......
......@@ -107,7 +107,7 @@ class ImageFile(Explicit):
# of the way they parse it).
try:
mod_since = int(DateTime(header).timeTime())
except:
except Exception:
mod_since = None
if mod_since is not None:
if getattr(self, 'lmt', None):
......
......@@ -146,7 +146,7 @@ def addDTMLDocument(self, id, title='', file='', REQUEST=None, submit=None):
if REQUEST is not None:
try:
u = self.DestinationURL()
except:
except Exception:
u = REQUEST['URL1']
if submit == " Add and Edit ":
u = "%s/%s" % (u, quote(id))
......
......@@ -306,7 +306,7 @@ def addDTMLMethod(self, id, title='', file='', REQUEST=None, submit=None):
if REQUEST is not None:
try:
u = self.DestinationURL()
except:
except Exception:
u = REQUEST['URL1']
if submit == " Add and Edit ":
u = "%s/%s" % (u, quote(id))
......
......@@ -118,7 +118,7 @@ class LockableItem(EtagSupport):
try:
locks = self.wl_lockmapping()
locks.clear()
except:
except Exception:
# The locks may be totally messed up, so we'll just delete
# and replace.
if hasattr(self, '_dav_writelocks'):
......
......@@ -396,7 +396,7 @@ class ObjectManager(CopyContainer,
# on Broken objects.
try:
ob._v__object_deleted__ = 1
except:
except Exception:
pass
if not suppress_events:
......@@ -524,7 +524,7 @@ class ObjectManager(CopyContainer,
raise BadRequest('No items specified')
try:
p = self._reserved_names
except:
except Exception:
p = ()
for n in ids:
if n in p:
......@@ -645,7 +645,7 @@ class ObjectManager(CopyContainer,
# the error.
try:
stat = marshal.loads(v.manage_FTPstat(REQUEST))
except:
except Exception:
LOG.error("Failed to stat file '%s'" % k,
exc_info=sys.exc_info())
stat = None
......
......@@ -202,7 +202,7 @@ class Item(Base,
if not error_message:
try:
s = ustr(error_value)
except:
except Exception:
s = error_value
try:
match = tagSearch(s)
......@@ -236,14 +236,14 @@ class Item(Base,
v = s(**kwargs)
else:
v = HTML.__call__(s, client, REQUEST, **kwargs)
except:
except Exception:
logger.error(
'Exception while rendering an error message',
exc_info=True
)
try:
strv = repr(error_value) # quotes tainted strings
except:
except Exception:
strv = ('<unprintable %s object>' %
str(type(error_value).__name__))
v = strv + (
......@@ -360,7 +360,7 @@ class Item(Base,
"""
try:
path = '/'.join(self.getPhysicalPath())
except:
except Exception:
return Base.__repr__(self)
context_path = None
context = aq_parent(self)
......@@ -368,7 +368,7 @@ class Item(Base,
if aq_base(context) is not aq_base(container):
try:
context_path = '/'.join(context.getPhysicalPath())
except:
except Exception:
context_path = None
res = '<%s' % self.__class__.__name__
res += ' at %s' % path
......
......@@ -346,7 +346,7 @@ class Traversable:
except ConflictError:
raise
except:
except Exception:
if default is not _marker:
return default
else:
......
......@@ -118,7 +118,7 @@ class RoleManager(BaseRoleManager):
if not have('acquire_%s' % permission_hash):
roles = tuple(roles)
p.setRoles(roles)
except:
except Exception:
fails.append(name)
if fails:
......@@ -196,7 +196,7 @@ class RoleManager(BaseRoleManager):
for role in roles:
try:
data.remove(role)
except:
except Exception:
pass
self.__ac_roles__ = tuple(data)
if REQUEST is not None:
......
......@@ -163,7 +163,7 @@ def callManageBeforeDelete(ob, item, container):
raise
except ConflictError:
raise
except:
except Exception:
LOG.error('_delObject() threw', exc_info=True)
# In debug mode when non-Manager, let exceptions propagate.
if getConfiguration().debug_mode:
......
......@@ -80,7 +80,7 @@ class TestGetAttr(unittest.TestCase):
self.folder._setObject('denied', DeniedItem())
self.folder._setObject('protected', ProtectedItem())
except:
except Exception:
self.tearDown()
raise
......
......@@ -76,7 +76,7 @@ class CopySupportTestBase(unittest.TestCase):
# has one. We use a subtransaction, which means we can rollback
# later and pretend we didn't touch the ZODB.
transaction.commit()
except:
except Exception:
self.connection.close()
raise
transaction.begin()
......
......@@ -84,7 +84,7 @@ class EventTest(unittest.TestCase):
uf._doAddUser('manager', 'secret', ['Manager'], [])
user = uf.getUserById('manager').__of__(uf)
newSecurityManager(None, user)
except:
except Exception:
self.tearDown()
raise
......
......@@ -94,7 +94,7 @@ class HookTest(unittest.TestCase):
uf._doAddUser('manager', 'secret', ['Manager'], [])
user = uf.getUserById('manager').__of__(uf)
newSecurityManager(None, user)
except:
except Exception:
self.tearDown()
raise
......
......@@ -24,11 +24,7 @@ from zope.component import adapter
from zope.lifecycleevent.interfaces import IObjectModifiedEvent
from zope.lifecycleevent.interfaces import IObjectCreatedEvent
try:
here = os.path.dirname(os.path.abspath(__file__))
except:
here = os.path.dirname(os.path.abspath(sys.argv[0]))
here = os.path.dirname(os.path.abspath(__file__))
imagedata = os.path.join(here, 'test.gif')
filedata = os.path.join(here, 'test.gif')
......@@ -107,7 +103,7 @@ class FileTests(unittest.TestCase):
# Hack, we need a _p_mtime for the file, so we make sure that it
# has one.
transaction.commit()
except:
except Exception:
self.connection.close()
raise
transaction.begin()
......
......@@ -78,7 +78,7 @@ class TestRequestRange(unittest.TestCase):
# has one. We use a subtransaction, which means we can rollback
# later and pretend we didn't touch the ZODB.
transaction.commit()
except:
except Exception:
self.connection.close()
raise
......
......@@ -111,7 +111,7 @@ class TestSimpleItem(unittest.TestCase):
try:
raise BadRequest("1")
except:
except Exception:
item.raise_standardErrorMessage(client=item,
REQUEST=REQUEST())
......
......@@ -241,7 +241,7 @@ class BasicUserFolder(Navigation, Tabs, Item, RoleManager,
if item is self:
try:
del container.__allow_groups__
except:
except Exception:
pass
def manage_afterAdd(self, item, container):
......@@ -290,7 +290,7 @@ class UserFolder(accesscontrol_userfolder.UserFolder, BasicUserFolder):
cfg = App.config.getConfiguration()
try:
os.remove(os.path.join(cfg.instancehome, 'inituser'))
except:
except Exception:
pass
InitializeClass(UserFolder)
......
......@@ -278,7 +278,7 @@ class view(zope.browserpage.metaconfigure.view):
try:
cname = str(name)
except:
except Exception:
cname = "GeneratedClass"
cdict['__name__'] = name
......
......@@ -92,7 +92,7 @@ class PageTemplate(ExtensionClass.Base,
return err
try:
self.pt_render(source=True, extra_context=namespace)
except:
except Exception:
return ('Macro expansion failed', '%s: %s' % sys.exc_info()[:2])
def __call__(self, *args, **kwargs):
......@@ -107,7 +107,7 @@ class PageTemplate(ExtensionClass.Base,
return self._text
try:
return self.pt_render(source=True)
except:
except Exception:
return ('%s\n Macro expansion failed\n %s\n-->\n%s' %
(self._error_start, "%s: %s" % sys.exc_info()[:2],
self._text))
......
......@@ -154,7 +154,7 @@ class PageTemplateFile(SimpleItem, Script, PageTemplate, Traversable):
f = open(self.filename, "rb")
try:
text = f.read(XML_PREFIX_MAX_LENGTH)
except:
except Exception:
f.close()
raise
t = sniff_type(text)
......
......@@ -328,7 +328,7 @@ class ZopePageTemplate(Script, PageTemplate, Cacheable,
"""Returns a file name to be compiled into the TAL code."""
try:
return '/'.join(self.getPhysicalPath())
except:
except Exception:
# This page template is being compiled without an
# acquisition context, so we don't know where it is. :-(
return None
......
......@@ -29,7 +29,7 @@ default_encoding = sys.getdefaultencoding()
class DefaultUnicodeEncodingConflictResolver(object):
""" This resolver implements the old-style behavior and will
raise an exception in case of the string 'text' can't be converted
propertly to unicode.
properly to unicode.
"""
implements(IUnicodeEncodingConflictResolver)
......
......@@ -59,7 +59,7 @@ class PortalTestCase(base.TestCase):
self.portal = self._portal()
self._setup()
self.afterSetUp()
except:
except Exception:
self._clear()
raise
......
......@@ -85,7 +85,7 @@ class ZopeTestCase(base.TestCase):
try:
if connections.contains(self.app):
self.app._delObject(folder_name)
except:
except Exception:
pass
base.TestCase._clear(self, call_close_hook)
......
......@@ -90,7 +90,7 @@ class TestCase(unittest.TestCase, object):
self.app = self._app()
self._setup()
self.afterSetUp()
except:
except Exception:
self._clear()
raise
......@@ -101,7 +101,7 @@ class TestCase(unittest.TestCase, object):
try:
self.beforeTearDown()
self._clear(1)
except:
except Exception:
self._clear()
raise
......
......@@ -191,7 +191,7 @@ class TestTestCase(HookTest):
class TestSetUpRaises(HookTest):
class Error:
class Error(Exception):
pass
def setUp(self):
......@@ -212,7 +212,7 @@ class TestSetUpRaises(HookTest):
class TestTearDownRaises(HookTest):
class Error:
class Error(Exception):
pass
def tearDown(self):
......
......@@ -493,7 +493,7 @@ class HookTest(ZopeTestCase.PortalTestCase):
class TestSetUpRaises(HookTest):
class Error:
class Error(Exception):
pass
def getPortal(self):
......
......@@ -678,7 +678,7 @@ class HTTPRequest(BaseRequest):
if not is_tainted:
tainted = None
except:
except Exception:
if (not item and not (flags & DEFAULT) and
key in defaults):
item = defaults[key]
......@@ -1605,7 +1605,7 @@ def sane_environment(env):
dict['HTTP_AUTHORIZATION'] = dict['HTTP_CGI_AUTHORIZATION']
try:
del dict['HTTP_CGI_AUTHORIZATION']
except:
except Exception:
pass
return dict
......
......@@ -876,7 +876,7 @@ class HTTPResponse(HTTPBaseResponse):
b = str(b)
except UnicodeEncodeError:
b = self._encode_unicode(unicode(b))
except:
except Exception:
b = '<unprintable %s object>' % type(b).__name__
if fatal and t is SystemExit and v.code == 0:
......
......@@ -18,5 +18,5 @@ def ClassFactory(jar, module, name, _silly=('__doc__',), _globals={}):
try:
m = __import__(module, _globals, _globals, _silly)
return getattr(m, name)
except:
except Exception:
return OFS.Uninstalled.Broken(jar, None, (module, name))
......@@ -87,7 +87,7 @@ def startup():
# Try to use custom storage
try:
m = imp.find_module('custom_zodb', [configuration.testinghome])
except:
except Exception:
m = imp.find_module('custom_zodb', [configuration.instancehome])
except Exception:
# if there is no custom_zodb, use the config file specified databases
......
......@@ -61,7 +61,7 @@ class WSGIStarter(object):
if locale_id is not None:
try:
import locale
except:
except Exception:
raise ConfigurationError(
'The locale module could not be imported.\n'
'To use localization options, you must ensure\n'
......@@ -69,7 +69,7 @@ class WSGIStarter(object):
'Python installation.')
try:
locale.setlocale(locale.LC_ALL, locale_id)
except:
except Exception:
raise ConfigurationError(
'The specified locale "%s" is not supported by your'
'system.\nSee your operating system documentation for '
......
......@@ -110,7 +110,7 @@ def main():
sys.exit(2)
try:
uid = int(arg)
except:
except Exception:
try:
import pwd
uid = pwd.getpwnam(arg)[2]
......@@ -135,7 +135,7 @@ def main():
sys.exit(2)
try:
gid = int(arg)
except:
except Exception:
try:
import pwd
gid = pwd.getpwnam(arg)[3]
......
......@@ -186,10 +186,7 @@ def get_inituser():
def write_inituser(fn, user, password):
import binascii
try:
from hashlib import sha1 as sha
except:
from sha import new as sha
from hashlib import sha1 as sha
fp = open(fn, "w")
pw = binascii.b2a_base64(sha(password).digest())[:-1]
fp.write('%s:{SHA}%s\n' % (user, pw))
......
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