Fix typos and code style check

In neutron/api/extensions.py, there are some typos, no needed blank
lines and docstrings can be improved (according to HACKING.rst).

Closes-Bug: #1213541

Change-Id: I01087d133e1b2a7e69f0bcc2ae359a3a2042b1dc
This commit is contained in:
ZhiQiang Fan 2013-08-18 11:58:41 +08:00
parent fc3ab14658
commit e52b5e8e98

View File

@ -1,4 +1,3 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2011 OpenStack Foundation.
@ -34,7 +33,7 @@ from neutron.openstack.common import log as logging
from neutron import wsgi
LOG = logging.getLogger('neutron.api.extensions')
LOG = logging.getLogger(__name__)
class PluginInterface(object):
@ -63,14 +62,12 @@ class ExtensionDescriptor(object):
Note that you don't have to derive from this class to have a valid
extension; it is purely a convenience.
"""
def get_name(self):
"""The name of the extension.
e.g. 'Fox In Socks'
"""
raise NotImplementedError()
@ -78,7 +75,6 @@ class ExtensionDescriptor(object):
"""The alias for the extension.
e.g. 'FOXNSOX'
"""
raise NotImplementedError()
@ -86,7 +82,6 @@ class ExtensionDescriptor(object):
"""Friendly description for the extension.
e.g. 'The Fox In Socks Extension'
"""
raise NotImplementedError()
@ -94,7 +89,6 @@ class ExtensionDescriptor(object):
"""The XML namespace for the extension.
e.g. 'http://www.fox.in.socks/api/ext/pie/v1.0'
"""
raise NotImplementedError()
@ -102,7 +96,6 @@ class ExtensionDescriptor(object):
"""The timestamp when the extension was last updated.
e.g. '2011-01-22T13:25:27-06:00'
"""
# NOTE(justinsb): Not sure of the purpose of this is, vs the XML NS
raise NotImplementedError()
@ -111,7 +104,6 @@ class ExtensionDescriptor(object):
"""List of extensions.ResourceExtension extension objects.
Resources define new nouns, and are accessible through URLs.
"""
resources = []
return resources
@ -120,7 +112,6 @@ class ExtensionDescriptor(object):
"""List of extensions.ActionExtension extension objects.
Actions are verbs callable from the API.
"""
actions = []
return actions
@ -129,7 +120,6 @@ class ExtensionDescriptor(object):
"""List of extensions.RequestException extension objects.
Request extensions are used to handle custom request data.
"""
request_exts = []
return request_exts
@ -183,7 +173,6 @@ class ExtensionDescriptor(object):
class ActionExtensionController(wsgi.Controller):
def __init__(self, application):
self.application = application
self.action_handlers = {}
@ -191,7 +180,6 @@ class ActionExtensionController(wsgi.Controller):
self.action_handlers[action_name] = handler
def action(self, request, id):
input_dict = self._deserialize(request.body,
request.get_content_type())
for action_name, handler in self.action_handlers.iteritems():
@ -259,9 +247,9 @@ class ExtensionController(wsgi.Controller):
class ExtensionMiddleware(wsgi.Middleware):
"""Extensions middleware for WSGI."""
def __init__(self, application,
ext_mgr=None):
self.ext_mgr = (ext_mgr
or ExtensionManager(
get_extensions_path()))
@ -372,7 +360,6 @@ class ExtensionMiddleware(wsgi.Middleware):
Returns the routed WSGI app's response or defers to the extended
application.
"""
match = req.environ['wsgiorg.routing_args'][1]
if not match:
@ -394,8 +381,8 @@ class ExtensionManager(object):
See tests/unit/extensions/foxinsocks.py for an
example extension implementation.
"""
def __init__(self, path):
LOG.info(_('Initializing extension manager.'))
self.path = path
@ -487,12 +474,12 @@ class ExtensionManager(object):
# Exit loop as no progress was made
break
if exts_to_process:
# NOTE(salv-orlando): Consider wheter this error should be fatal
# NOTE(salv-orlando): Consider whether this error should be fatal
LOG.error(_("It was impossible to process the following "
"extensions: %s because of missing requirements."),
','.join(exts_to_process.keys()))
"""Extending extensions' attributes map."""
# Extending extensions' attributes map.
for ext in update_exts:
ext.update_attributes_map(attr_map)
@ -518,14 +505,12 @@ class ExtensionManager(object):
def _load_all_extensions(self):
"""Load extensions from the configured path.
Load extensions from the configured path. The extension name is
constructed from the module_name. If your extension module was named
widgets.py the extension class within that module should be
'Widgets'.
See tests/unit/extensions/foxinsocks.py for an example
extension implementation.
The extension name is constructed from the module_name. If your
extension module is named widgets.py, the extension class within that
module should be 'Widgets'.
See tests/unit/extensions/foxinsocks.py for an example extension
implementation.
"""
for path in self.path.split(':'):
if os.path.exists(path):
@ -578,9 +563,7 @@ class PluginAwareExtensionManager(ExtensionManager):
super(PluginAwareExtensionManager, self).__init__(path)
def _check_extension(self, extension):
"""Checks if any of plugins supports extension and implements the
extension contract.
"""
"""Check if an extension is supported by any plugin."""
extension_is_valid = super(PluginAwareExtensionManager,
self)._check_extension(extension)
return (extension_is_valid and
@ -622,8 +605,8 @@ class RequestExtension(object):
Provide a way to add data to responses and handle custom request data
that is sent to core Neutron OpenStack API controllers.
"""
def __init__(self, method, url_route, handler):
self.url_route = url_route
self.handler = handler