Modernize 'except' clauses

The 'as' syntax works from Python 2 on, and Python 3 will
drop the "comma" syntax.

Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
Petr Viktorin
2015-07-30 16:49:29 +02:00
committed by Tomas Babej
parent a651be3eec
commit 27dabb4528
118 changed files with 661 additions and 661 deletions

View File

@@ -415,7 +415,7 @@ def validate_file(file_path, validation_mode, reference_pot=None):
try:
po = polib.pofile(file_path)
except Exception, e:
except Exception as e:
error_lines.append(entry_seperator)
error_lines.append('Unable to parse file "%s": %s' % (file_path, e))
n_errors += 1
@@ -528,7 +528,7 @@ def create_po(pot_file, po_file, mo_file):
return 1
try:
po = polib.pofile(pot_file)
except Exception, e:
except Exception as e:
print >>sys.stderr, 'Unable to parse file "%s": %s' % (pot_file, e)
return 1
@@ -619,7 +619,7 @@ def po_file_iterate(po_file, get_msgstr, get_msgstr_plural):
return 1
try:
po = polib.pofile(po_file)
except Exception, e:
except Exception as e:
print >>sys.stderr, 'Unable to parse file "%s": %s' % (po_file, e)
return 1
@@ -638,7 +638,7 @@ def po_file_iterate(po_file, get_msgstr, get_msgstr_plural):
n_translations += 1
validate_unicode_edit(msgid, msgstr)
n_valid += 1
except Exception, e:
except Exception as e:
n_fail += 1
if print_traceback:
traceback.print_exc()
@@ -648,7 +648,7 @@ def po_file_iterate(po_file, get_msgstr, get_msgstr_plural):
n_translations += 1
validate_unicode_edit(msgid_plural, msgstr_plural)
n_valid += 1
except Exception, e:
except Exception as e:
n_fail += 1
if print_traceback:
traceback.print_exc()
@@ -663,7 +663,7 @@ def po_file_iterate(po_file, get_msgstr, get_msgstr_plural):
n_translations += 1
validate_unicode_edit(msgid, msgstr)
n_valid += 1
except Exception, e:
except Exception as e:
n_fail += 1
if print_traceback:
traceback.print_exc()
@@ -671,7 +671,7 @@ def po_file_iterate(po_file, get_msgstr, get_msgstr_plural):
n_entries += 1
except Exception, e:
except Exception as e:
if print_traceback:
traceback.print_exc()
print >> sys.stderr, "ERROR: %s" % e

View File

@@ -287,7 +287,7 @@ class TaskRunner(object):
try:
return args.func(args)
except Exception, e:
except Exception as e:
if args.with_beakerlib:
beakerlib_process.log_exception()
beakerlib_process.run_beakerlib_command(

View File

@@ -42,7 +42,7 @@ try:
server_available = True
except errors.DatabaseError:
server_available = False
except Exception, e:
except Exception as e:
server_available = False
class cmdline_test(XMLRPC_test):

View File

@@ -48,7 +48,7 @@ def use_keytab(principal, keytab):
conn = ldap2(api)
conn.connect(ccache=ccache)
conn.disconnect()
except krbV.Krb5Error, e:
except krbV.Krb5Error as e:
raise StandardError('Unable to bind to LDAP. Error initializing principal %s in %s: %s' % (principal.name, keytab, str(e)))
finally:
del os.environ['KRB5CCNAME']
@@ -111,7 +111,7 @@ class test_ipagetkeytab(cmdline_test):
expected = 'Keytab successfully retrieved and stored in: %s\n' % (
self.keytabname)
assert expected in err, 'Success message not in output:\n%s' % err
except ipautil.CalledProcessError, e:
except ipautil.CalledProcessError as e:
assert (False)
def test_3_use(self):
@@ -141,7 +141,7 @@ class test_ipagetkeytab(cmdline_test):
"""
try:
use_keytab(self.service_princ, self.keytabname)
except StandardError, errmsg:
except StandardError as errmsg:
assert('Unable to bind to LDAP. Error initializing principal' in str(errmsg))
def test_9_cleanup(self):

View File

@@ -274,7 +274,7 @@ class test_xml_introspection(object):
def test_list_methods_many_params(self):
try:
result = api.Backend.xmlclient.conn.system.listMethods('foo')
except Fault, f:
except Fault as f:
print f
assert f.faultCode == 3003
assert f.faultString == (
@@ -294,7 +294,7 @@ class test_xml_introspection(object):
def test_signature_no_params(self):
try:
result = api.Backend.xmlclient.conn.system.methodSignature()
except Fault, f:
except Fault as f:
print f
assert f.faultCode == 3007
assert f.faultString == "'method name' is required"
@@ -304,7 +304,7 @@ class test_xml_introspection(object):
def test_signature_many_params(self):
try:
result = api.Backend.xmlclient.conn.system.methodSignature('a', 'b')
except Fault, f:
except Fault as f:
print f
assert f.faultCode == 3004
assert f.faultString == (
@@ -315,7 +315,7 @@ class test_xml_introspection(object):
def test_help_no_params(self):
try:
result = api.Backend.xmlclient.conn.system.methodHelp()
except Fault, f:
except Fault as f:
print f
assert f.faultCode == 3007
assert f.faultString == "'method name' is required"
@@ -325,7 +325,7 @@ class test_xml_introspection(object):
def test_help_many_params(self):
try:
result = api.Backend.xmlclient.conn.system.methodHelp('a', 'b')
except Fault, f:
except Fault as f:
print f
assert f.faultCode == 3004
assert f.faultString == (

View File

@@ -59,7 +59,7 @@ class test_keyring(object):
# Make sure it is gone
try:
result = kernel_keyring.read_key(TEST_KEY)
except ValueError, e:
except ValueError as e:
assert e.message == 'key %s not found' % TEST_KEY
def test_02(self):

View File

@@ -30,7 +30,7 @@ def make_public_key_checker(pk, out):
try:
parsed = ssh.SSHPublicKey(pk)
assert parsed.openssh() == out
except Exception, e:
except Exception as e:
assert type(e) is out
check_public_key.description = "Test SSH public key parsing (%s)" % repr(pk)
return check_public_key

View File

@@ -37,7 +37,7 @@ class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
try:
api.Command['user_add'](uid=testuser, givenname=u'Test', sn=u'User')
api.Command['passwd'](testuser, password=u'old_password')
except errors.ExecutionError, e:
except errors.ExecutionError as e:
raise nose.SkipTest(
'Cannot set up test user: %s' % e
)

View File

@@ -111,7 +111,7 @@ class test_update(object):
try:
request = pkcs10.load_certificate_request(csr)
except NSPRError, nsprerr:
except NSPRError as nsprerr:
# (SEC_ERROR_BAD_DER) security library: improperly formatted DER-encoded message.
assert(nsprerr. errno== -8183)
@@ -122,5 +122,5 @@ class test_update(object):
csr = self.read_file("test4.csr")
try:
request = pkcs10.load_certificate_request(csr)
except TypeError, typeerr:
except TypeError as typeerr:
assert(str(typeerr) == 'Incorrect padding')

View File

@@ -144,9 +144,9 @@ class UI_driver(object):
try:
with open(path, 'r') as conf:
self.config = yaml.load(conf)
except yaml.YAMLError, e:
except yaml.YAMLError as e:
raise nose.SkipTest("Invalid Web UI config.\n%s" % e)
except IOError, e:
except IOError as e:
raise nose.SkipTest("Can't load Web UI test config: %s" % e)
else:
self.config = {}
@@ -198,9 +198,9 @@ class UI_driver(object):
driver = webdriver.Remote(
command_executor='http://%s:%d/wd/hub' % (host, port),
desired_capabilities=capabilities)
except URLError, e:
except URLError as e:
raise nose.SkipTest('Error connecting to selenium server: %s' % e)
except RuntimeError, e:
except RuntimeError as e:
raise nose.SkipTest('Error while establishing webdriver: %s' % e)
else:
try:
@@ -213,9 +213,9 @@ class UI_driver(object):
if "ff_profile" in self.config:
fp = webdriver.FirefoxProfile(self.config["ff_profile"])
driver = webdriver.Firefox(fp)
except URLError, e:
except URLError as e:
raise nose.SkipTest('Error connecting to selenium server: %s' % e)
except RuntimeError, e:
except RuntimeError as e:
raise nose.SkipTest('Error while establishing webdriver: %s' % e)
return driver

View File

@@ -494,7 +494,7 @@ class test_sudorule(XMLRPC_test):
self.rule_name,
addattr='externalhost=%s' % self.test_invalid_host
)
except errors.ValidationError, e:
except errors.ValidationError as e:
assert unicode(e) == ("invalid 'externalhost': only letters, " +
"numbers, '_', '-' are allowed. " +
"DNS label may not start or end with '-'")

View File

@@ -311,7 +311,7 @@ class Declarative(XMLRPC_test):
name = klass.__name__
try:
output = api.Command[cmd](*args, **options)
except StandardError, e:
except StandardError as e:
pass
else:
raise AssertionError(
@@ -334,7 +334,7 @@ class Declarative(XMLRPC_test):
e = None
try:
output = api.Command[cmd](*args, **options)
except StandardError, e:
except StandardError as e:
pass
if not expected(e, output):
raise AssertionError(

View File

@@ -361,7 +361,7 @@ def raises(exception, callback, *args, **kw):
raised = False
try:
callback(*args, **kw)
except exception, e:
except exception as e:
raised = True
if not raised:
raise ExceptionNotRaised(exception)