diff --git a/swift/account/server.py b/swift/account/server.py index 8795844afc..3bfe3fbf49 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -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): diff --git a/swift/common/manager.py b/swift/common/manager.py index 123f27d10f..2cc764493c 100644 --- a/swift/common/manager.py +++ b/swift/common/manager.py @@ -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) diff --git a/swift/container/server.py b/swift/container/server.py index a77dadcd22..898ef36ea1 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -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): diff --git a/swift/obj/server.py b/swift/obj/server.py index c3fde72525..b9c8616124 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -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) diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 4993c90735..99b99afd54 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -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)})