Use ValueError instead of Exception when appropriate

Change-Id: I7f9f72b4efcca01170b7e311057e4ed6bae73179
This commit is contained in:
Ondřej Nový 2015-11-15 22:34:27 +01:00
parent 04f4000420
commit fca1400e40
10 changed files with 22 additions and 23 deletions

View File

@ -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 = '/'

View File

@ -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 = '/'

View File

@ -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 = '/'

View File

@ -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 = '/'

View File

@ -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 = '/'

View File

@ -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 = '/'

View File

@ -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 = '/'

View File

@ -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

View File

@ -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)

View File

@ -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