Catch AttributeError less often
I always get tripped up when I'm editing code that catches AttributeError and does something with it. I'll type "req.emthod" or something, and next thing I know I'm getting 405s in all my unit tests. This diff removes some places where we catch AttributeError (sometimes, having deliberately thrown it only one line before) so that typos can crash the way Guido intended. Change-Id: I2f7586f96b41a97e6ae254efc83218b3b5c6cc9e
This commit is contained in:
parent
6c9a1899a1
commit
3944d82038
@ -262,14 +262,10 @@ class AccountController(BaseStorageServer):
|
||||
else:
|
||||
try:
|
||||
# disallow methods which are not publicly accessible
|
||||
try:
|
||||
if req.method not in self.allowed_methods:
|
||||
raise AttributeError('Not allowed method.')
|
||||
except AttributeError:
|
||||
if req.method not in self.allowed_methods:
|
||||
res = HTTPMethodNotAllowed()
|
||||
else:
|
||||
method = getattr(self, req.method)
|
||||
res = method(req)
|
||||
res = getattr(self, req.method)(req)
|
||||
except HTTPException as error_response:
|
||||
res = error_response
|
||||
except (Exception, Timeout):
|
||||
|
@ -378,9 +378,8 @@ class Manager(object):
|
||||
|
||||
"""
|
||||
cmd = cmd.lower().replace('-', '_')
|
||||
try:
|
||||
f = getattr(self, cmd)
|
||||
except AttributeError:
|
||||
f = getattr(self, cmd, None)
|
||||
if f is None:
|
||||
raise UnknownCommandError(cmd)
|
||||
if not hasattr(f, 'publicly_accessible'):
|
||||
raise UnknownCommandError(cmd)
|
||||
|
@ -594,14 +594,10 @@ class ContainerController(BaseStorageServer):
|
||||
else:
|
||||
try:
|
||||
# disallow methods which have not been marked 'public'
|
||||
try:
|
||||
if req.method not in self.allowed_methods:
|
||||
raise AttributeError('Not allowed method.')
|
||||
except AttributeError:
|
||||
if req.method not in self.allowed_methods:
|
||||
res = HTTPMethodNotAllowed()
|
||||
else:
|
||||
method = getattr(self, req.method)
|
||||
res = method(req)
|
||||
res = getattr(self, req.method)(req)
|
||||
except HTTPException as error_response:
|
||||
res = error_response
|
||||
except (Exception, Timeout):
|
||||
|
@ -1031,10 +1031,7 @@ class ObjectController(BaseStorageServer):
|
||||
else:
|
||||
try:
|
||||
# disallow methods which have not been marked 'public'
|
||||
try:
|
||||
if req.method not in self.allowed_methods:
|
||||
raise AttributeError('Not allowed method.')
|
||||
except AttributeError:
|
||||
if req.method not in self.allowed_methods:
|
||||
res = HTTPMethodNotAllowed()
|
||||
else:
|
||||
method = getattr(self, req.method)
|
||||
|
@ -382,10 +382,9 @@ class Application(object):
|
||||
req.headers['x-trans-id'] = req.environ['swift.trans_id']
|
||||
controller.trans_id = req.environ['swift.trans_id']
|
||||
self.logger.client_ip = get_remote_client(req)
|
||||
try:
|
||||
handler = getattr(controller, req.method)
|
||||
getattr(handler, 'publicly_accessible')
|
||||
except AttributeError:
|
||||
|
||||
handler = getattr(controller, req.method, None)
|
||||
if not getattr(handler, 'publicly_accessible', False):
|
||||
allowed_methods = getattr(controller, 'allowed_methods', set())
|
||||
return HTTPMethodNotAllowed(
|
||||
request=req, headers={'Allow': ', '.join(allowed_methods)})
|
||||
|
Loading…
Reference in New Issue
Block a user