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