From fca1400e405456aff47519cb70440869fbe7a0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nov=C3=BD?= Date: Sun, 15 Nov 2015 22:34:27 +0100 Subject: [PATCH] Use ValueError instead of Exception when appropriate Change-Id: I7f9f72b4efcca01170b7e311057e4ed6bae73179 --- bin/swauth-add-account | 4 ++-- bin/swauth-add-user | 4 ++-- bin/swauth-delete-account | 4 ++-- bin/swauth-delete-user | 4 ++-- bin/swauth-list | 4 ++-- bin/swauth-prep | 4 ++-- bin/swauth-set-account-service | 4 ++-- swauth/middleware.py | 12 ++++++------ test_swauth/unit/test_middleware.py | 2 +- tox.ini | 3 +-- 10 files changed, 22 insertions(+), 23 deletions(-) diff --git a/bin/swauth-add-account b/bin/swauth-add-account index cda3eef..033b6cb 100755 --- a/bin/swauth-add-account +++ b/bin/swauth-add-account @@ -52,8 +52,8 @@ if __name__ == '__main__': account = args[0] parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/bin/swauth-add-user b/bin/swauth-add-user index 1d9193f..51b08bf 100755 --- a/bin/swauth-add-user +++ b/bin/swauth-add-user @@ -62,8 +62,8 @@ if __name__ == '__main__': account, user, password = args parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/bin/swauth-delete-account b/bin/swauth-delete-account index fe41a3d..a3c68eb 100755 --- a/bin/swauth-delete-account +++ b/bin/swauth-delete-account @@ -46,8 +46,8 @@ if __name__ == '__main__': account = args[0] parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/bin/swauth-delete-user b/bin/swauth-delete-user index 713a48d..b8fbcbb 100755 --- a/bin/swauth-delete-user +++ b/bin/swauth-delete-user @@ -46,8 +46,8 @@ if __name__ == '__main__': account, user = args parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/bin/swauth-list b/bin/swauth-list index 0c9ed37..ba3ed69 100755 --- a/bin/swauth-list +++ b/bin/swauth-list @@ -65,8 +65,8 @@ If the [user] is '.groups', the active groups for the account will be listed. options.admin_key = getpass() parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/bin/swauth-prep b/bin/swauth-prep index cd790a5..61aeba0 100755 --- a/bin/swauth-prep +++ b/bin/swauth-prep @@ -45,8 +45,8 @@ if __name__ == '__main__': options.admin_key = getpass() parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/bin/swauth-set-account-service b/bin/swauth-set-account-service index 710b0eb..b43c8e3 100755 --- a/bin/swauth-set-account-service +++ b/bin/swauth-set-account-service @@ -56,8 +56,8 @@ Example: %prog -K swauthkey test storage local http://127.0.0.1:8080/v1/AUTH_018 account, service, name, url = args parsed = urlparse(options.admin_url) if parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (parsed.scheme, repr(options.admin_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (parsed.scheme, repr(options.admin_url))) parsed_path = parsed.path if not parsed_path: parsed_path = '/' diff --git a/swauth/middleware.py b/swauth/middleware.py index 90c0a81..be4346b 100644 --- a/swauth/middleware.py +++ b/swauth/middleware.py @@ -126,15 +126,15 @@ class Swauth(object): elif len(cluster_parts) == 2: self.dsc_url = self.dsc_url2 = cluster_parts[1].rstrip('/') else: - raise Exception('Invalid cluster format') + raise ValueError('Invalid cluster format') self.dsc_parsed = urlparse(self.dsc_url) if self.dsc_parsed.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (self.dsc_parsed.scheme, repr(self.dsc_url))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (self.dsc_parsed.scheme, repr(self.dsc_url))) self.dsc_parsed2 = urlparse(self.dsc_url2) if self.dsc_parsed2.scheme not in ('http', 'https'): - raise Exception('Cannot handle protocol scheme %s for url %s' % - (self.dsc_parsed2.scheme, repr(self.dsc_url2))) + raise ValueError('Cannot handle protocol scheme %s for url %s' % + (self.dsc_parsed2.scheme, repr(self.dsc_url2))) self.super_admin_key = conf.get('super_admin_key') if not self.super_admin_key and not self.swauth_remote: msg = _('No super_admin_key set in conf file; Swauth ' @@ -156,7 +156,7 @@ class Swauth(object): self.auth_type = conf.get('auth_type', 'Plaintext').title() self.auth_encoder = getattr(swauth.authtypes, self.auth_type, None) if self.auth_encoder is None: - raise Exception('Invalid auth_type in config file: %s' + raise ValueError('Invalid auth_type in config file: %s' % self.auth_type) self.allow_overrides = \ conf.get('allow_overrides', 't').lower() in TRUE_VALUES diff --git a/test_swauth/unit/test_middleware.py b/test_swauth/unit/test_middleware.py index 733e9fd..5b6a0af 100644 --- a/test_swauth/unit/test_middleware.py +++ b/test_swauth/unit/test_middleware.py @@ -179,7 +179,7 @@ class TestAuth(unittest.TestCase): def test_default_swift_cluster_init(self): app = FakeApp() - self.assertRaises(Exception, auth.filter_factory({ + self.assertRaises(ValueError, auth.filter_factory({ 'super_admin_key': 'supertest', 'default_swift_cluster': 'local#badscheme://host/path'}), app) ath = auth.filter_factory({'super_admin_key': 'supertest'})(app) diff --git a/tox.ini b/tox.ini index 2d877b4..4536443 100644 --- a/tox.ini +++ b/tox.ini @@ -35,9 +35,8 @@ commands = python setup.py build_sphinx # E128 continuation line under-indented for visual indent # E131 continuation line unaligned for hanging indent # E121 continuation line under-indented for hanging indent -# H202 assertRaises Exception too broad show-source = True -ignore = E123,H405,E127,E128,E131,E121,H202 +ignore = E123,H405,E127,E128,E131,E121 builtins = _ exclude=.venv,.git,.tox,dist,doc,*egg,build