Permalink
Browse files

Use the new, less ambiguous exception handling syntax.

  • Loading branch information...
1 parent 94516f8 commit 52b3124e2015cef662eab5c2267c1a50bae97326 @andrewshadura andrewshadura committed Jul 10, 2014
View
@@ -14,7 +14,7 @@ class UHTTPConnection (httplib.HTTPConnection):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
sock.connect(self.path)
- except socket.error, e:
+ except socket.error as e:
if e.errno == 13:
sys.stderr.write('Permission denied\n')
sys.exit(4)
View
@@ -66,7 +66,7 @@ if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], 'hc:dv', ['help', 'config=', 'daemon', 'set-platform='])
- except getopt.GetoptError, e:
+ except getopt.GetoptError as e:
print str(e)
usage()
sys.exit(2)
@@ -123,7 +123,7 @@ if __name__ == '__main__':
from ajenti import core
try:
core.run()
- except Exception, e:
+ except Exception as e:
core.handle_crash(e)
else:
logging.info('Ajenti starting in foreground')
@@ -132,7 +132,7 @@ if __name__ == '__main__':
core.run()
except KeyboardInterrupt:
pass
- except Exception, e:
+ except Exception as e:
from ajenti import core
core.handle_crash(e)
View
@@ -65,7 +65,7 @@ def ipc_application(environment, start_response):
else:
start_response('200 OK', [])
return result
- except Exception, e:
+ except Exception as e:
traceback.print_exc()
start_response('500 Error', [])
return str(e)
@@ -275,7 +275,7 @@ def load_recursive(self, name):
while True:
try:
return self.load(name)
- except PluginDependency.Unsatisfied, e:
+ except PluginDependency.Unsatisfied as e:
if e.dependency.plugin_name in manager.get_all():
if manager.get_all()[e.dependency.plugin_name].crash:
manager.get_all()[name].crash = e
@@ -303,7 +303,7 @@ def load(self, name):
raise PluginFormatError()
except PluginFormatError:
raise
- except Exception, e:
+ except Exception as e:
# TOTAL CRASH
from ajenti.api import PluginInfo
info = PluginInfo(name=name, crash=e)
@@ -326,26 +326,26 @@ def load(self, name):
try:
info.init()
- except Exception, e:
+ except Exception as e:
raise PluginCrashed(e)
if name in self.__order:
self.__order.remove(name)
self.__order.append(name)
return True
- except PluginDependency.Unsatisfied, e:
+ except PluginDependency.Unsatisfied as e:
raise
- except PluginFormatError, e:
+ except PluginFormatError as e:
logging.warn(' *** [%s] Plugin error: %s' % (name, e))
- except PluginCrashed, e:
+ except PluginCrashed as e:
logging.warn(' *** [%s] Plugin crashed: %s' % (name, e))
print e.traceback
info.crash = e
- except Dependency.Unsatisfied, e:
+ except Dependency.Unsatisfied as e:
logging.warn(' *** [%s] skipping due to %s' % (name, e))
info.crash = e
- except PluginLoadError, e:
+ except PluginLoadError as e:
logging.warn(' *** [%s] Plugin failed to load: %s' % (name, e))
info.crash = e
@@ -84,7 +84,7 @@ def worker(self):
})
self.last_report = datetime.now()
self.last_error = None
- except Exception, e:
+ except Exception as e:
self.last_error = e
@@ -41,7 +41,7 @@ def on_install(self):
try:
self.mgr.write_license(self.find('license-key').value)
self.mgr.activate()
- except Exception, e:
+ except Exception as e:
self.context.notify('error', _('Error: "%s"') % str(e))
self.refresh()
@@ -50,6 +50,6 @@ def on_remove(self):
try:
self.mgr.deactivate()
self.mgr.remove_license()
- except Exception, e:
+ except Exception as e:
self.context.notify('error', _('Error: "%s"') % str(e))
self.refresh()
@@ -62,5 +62,5 @@ def on_save(self):
try:
CronManager.get().save_tab(self.current_user, self.config)
self.refresh()
- except Exception, e:
+ except Exception as e:
self.context.notify('error', e.message)
@@ -82,7 +82,7 @@ def save(self):
try:
self.backend.test_config()
self.context.notify('info', _('Self-test OK'))
- except Exception, e:
+ except Exception as e:
self.context.notify('error', str(e))
@@ -125,7 +125,7 @@ def refresh(self):
index=widget['index'],
config=widget['config'],
)
- except Exception, e:
+ except Exception as e:
traceback.print_exc()
instance = CrashedWidget.new(
self.ui,
@@ -43,7 +43,7 @@ def on_sql_run(self):
try:
result = self.query_sql(self.find('sql-db').value, self.find('sql-input').value)
self.context.notify('info', _('Query finished'))
- except Exception, e:
+ except Exception as e:
self.context.notify('error', str(e))
return
@@ -77,7 +77,7 @@ def refresh(self):
try:
self.databases = self.query_databases()
self.users = self.query_users()
- except Exception, e:
+ except Exception as e:
import traceback; traceback.print_exc();
self.context.notify('error', str(e))
if hasattr(self, 'config_class'):
@@ -93,7 +93,7 @@ def refresh(self):
def on_db_name_dialog_submit(self, value=None):
try:
self.query_create(value)
- except Exception, e:
+ except Exception as e:
self.context.notify('error', str(e))
return
self.refresh()
@@ -109,7 +109,7 @@ def on_add_user_dialog(self, button=None):
u.password = d.find('password').value
try:
self.query_create_user(u)
- except Exception, e:
+ except Exception as e:
self.context.notify('error', str(e))
return
@@ -92,7 +92,7 @@ def on_new_file(self):
try:
open(path, 'w').close()
self._chown_new(path)
- except OSError, e:
+ except OSError as e:
self.context.notify('error', str(e))
self.refresh()
@@ -106,7 +106,7 @@ def on_new_directory(self):
os.mkdir(path)
os.chmod(path, 0755)
self._chown_new(path)
- except OSError, e:
+ except OSError as e:
self.context.notify('error', str(e))
self.refresh()
@@ -135,7 +135,7 @@ def upload(self, name, file):
gevent.sleep(0)
output.write(data)
output.close()
- except OSError, e:
+ except OSError as e:
self.context.notify('error', str(e))
self.refresh()
@@ -261,7 +261,7 @@ def on_close_dialog(self, button):
self.binder_d.update()
try:
self.item.write()
- except Exception, e:
+ except Exception as e:
self.context.notify('error', str(e))
self.refresh()
@@ -15,7 +15,7 @@ class LMSensors (BasePlugin):
def get(self):
try:
lines = subprocess.check_output(['sensors']).splitlines()
- except subprocess.CalledProcessError, e:
+ except subprocess.CalledProcessError as e:
return {} # sensors not configured
r = {}
for l in lines:
@@ -167,9 +167,9 @@ def handle_message(self, message):
profile_end('Total')
if ajenti.debug:
self.send_debug()
- except SecurityError, e:
+ except SecurityError as e:
self.send_security_error()
- except Exception, e:
+ except Exception as e:
catcher.backup(e)
traceback.print_exc()
e.traceback = traceback.format_exc(e)
@@ -350,7 +350,7 @@ def init(self):
self.is_empty = False
except SecurityError:
pass
- except Exception, e:
+ except Exception as e:
catcher.backup(e)
traceback.print_exc()
e.traceback = traceback.format_exc(e)
@@ -38,10 +38,10 @@ def refresh(self):
self.munin_client.reset()
try:
self.munin_client.fetch_domains()
- except requests.ConnectionError, e:
+ except requests.ConnectionError as e:
self.find_type('tabs').active = 1
self.context.notify('error', _('Couldn\'t connect to Munin: %s') % e.message)
- except Exception, e:
+ except Exception as e:
self.find_type('tabs').active = 1
if e.message == 'auth':
self.context.notify('error', _('Munin HTTP authentication failed'))
@@ -22,7 +22,7 @@ def rescan(self):
f = open('/etc/network/interfaces')
ss = f.read().splitlines()
f.close()
- except IOError, e:
+ except IOError as e:
return
auto = []
@@ -162,7 +162,7 @@ def open(self, path):
content = ''
try:
content = open(path).read().decode('utf-8')
- except Exception, e:
+ except Exception as e:
self.context.notify('error', str(e))
self.files[id]['content'] = content
self.files[id]['mime'] = mimetypes.guess_type(path, strict=False)[0]
@@ -44,7 +44,7 @@ def setup(self):
self._m = manager.manager(path=addr, password=password)
# Test connection
self.getpid()
- except Exception, e:
+ except Exception as e:
raise Exception(str(e))
def _execute(self, func, *args):
@@ -33,7 +33,7 @@ def disconnect(u, c):
try:
self.backend.killbyaddr(u.raddress)
time.sleep(1)
- except Exception, e:
+ except Exception as e:
self.context.notify('error', e.message)
self.refresh()
@@ -58,7 +58,7 @@ def on_soft_restart(self):
def refresh(self):
try:
self.backend.setup()
- except Exception, e:
+ except Exception as e:
self.context.notify('error', e.message)
self.context.launch('configure-plugin', plugin=self.backend)
return
@@ -80,7 +80,7 @@ def refresh(self):
m.timestamp, m.flags, m.text = d[:3]
self.state.messages.append(m)
- except Exception, e:
+ except Exception as e:
self.context.notify('error', e.message)
self.binder.setup(self.state).populate()
@@ -90,5 +90,5 @@ def command(self, cmd):
p = subprocess.Popen([self.script, cmd], close_fds=True)
gevent.sleep(0)
p.wait()
- except OSError, e:
+ except OSError as e:
logging.warn('service script failed: %s - %s' % (self.script, e))
@@ -61,10 +61,10 @@ def _run(self):
try:
self.run(**self.params)
self.result.result = TaskResult.SUCCESS
- except TaskError, e:
+ except TaskError as e:
self.result.result = TaskResult.ERROR
self.result.output = e.message
- except Exception, e:
+ except Exception as e:
traceback.print_exc()
self.result.result = TaskResult.CRASH
self.result.output = str(e)
@@ -113,7 +113,7 @@ def change_password(self, user, ui):
self.mgr.change_password(user, new_password)
self.context.notify('info', _('Password for %s was changed') % user.name)
ui.find('new-password').value = ''
- except Exception, e:
+ except Exception as e:
self.context.notify('error', _('Error: "%s"') % e.message)
else:
self.context.notify('error', _('Password shouldn\'t be empty'))
View
@@ -53,7 +53,7 @@ def handle(self, context):
for instance in self.context.http_handlers:
try:
output = instance.handle(context)
- except Exception, e:
+ except Exception as e:
return [self.respond_error(context, e)]
if output is not None:
return output
@@ -66,7 +66,7 @@ def inflate(self, ui, layout):
plugin, path = layout.split(':')
try:
file = open(os.path.join(manager.resolve_path(plugin), 'layout', path + '.xml'), 'r')
- except IOError, e:
+ except IOError as e:
raise TemplateNotFoundError(e)
data = file.read()
data = """<xml xmlns:bind="bind" xmlns:binder="binder">%s</xml>""" % data
@@ -56,7 +56,7 @@ def check_password(self, username, password):
l = self.__get_ldap()
try:
return bool(l.bind_s('%s\\%s' % (self.classconfig['domain'], username), password))
- except Exception, e:
+ except Exception as e:
print e
return False
@@ -53,7 +53,7 @@ def check_password(self, username, password):
l = self.__get_ldap()
try:
return bool(l.bind_s('cn=%s,' % username + self.classconfig['auth_dn'], password))
- except Exception, e:
+ except Exception as e:
print e
return False
@@ -23,7 +23,7 @@
def check_output(*args, **kwargs):
try:
return subprocess.check_output(*args, **kwargs)
- except Exception, e:
+ except Exception as e:
logging.error('Call failed')
logging.error(' '.join(args[0]))
logging.error(str(e))
View
@@ -11,7 +11,7 @@
def check_call(*args):
try:
subprocess.call(*args)
- except Exception, e:
+ except Exception as e:
logging.error('Call failed')
logging.error(' '.join(args[0]))
logging.error(str(e))

0 comments on commit 52b3124

Please sign in to comment.