Merge "Replace map/filter lambda with comprehensions"

This commit is contained in:
Jenkins
2017-08-08 00:39:51 +00:00
committed by Gerrit Code Review
2 changed files with 9 additions and 12 deletions

View File

@@ -52,8 +52,8 @@ class AuthTokenMiddleware(auth_token.AuthProtocol):
# The information whether the API call is being performed against the # The information whether the API call is being performed against the
# public API is required for some other components. Saving it to the # public API is required for some other components. Saving it to the
# WSGI environment is reasonable thereby. # WSGI environment is reasonable thereby.
env['is_public_api'] = any(map(lambda pattern: re.match(pattern, path), env['is_public_api'] = any(re.match(pattern, path)
self.public_api_routes)) for pattern in self.public_api_routes)
if env['is_public_api']: if env['is_public_api']:
return self._app(env, start_response) return self._app(env, start_response)

View File

@@ -40,9 +40,8 @@ class CinderHelper(object):
def get_storage_node_by_name(self, name): def get_storage_node_by_name(self, name):
"""Get storage node by name(host@backendname)""" """Get storage node by name(host@backendname)"""
try: try:
storages = list(filter(lambda storage: storages = [storage for storage in self.get_storage_node_list()
storage.host == name, if storage.host == name]
self.get_storage_node_list()))
if len(storages) != 1: if len(storages) != 1:
raise exception.StorageNodeNotFound(name=name) raise exception.StorageNodeNotFound(name=name)
return storages[0] return storages[0]
@@ -56,9 +55,8 @@ class CinderHelper(object):
def get_storage_pool_by_name(self, name): def get_storage_pool_by_name(self, name):
"""Get pool by name(host@backend#poolname)""" """Get pool by name(host@backend#poolname)"""
try: try:
pools = list(filter(lambda pool: pools = [pool for pool in self.get_storage_pool_list()
pool.name == name, if pool.name == name]
self.get_storage_pool_list()))
if len(pools) != 1: if len(pools) != 1:
raise exception.PoolNotFound(name=name) raise exception.PoolNotFound(name=name)
return pools[0] return pools[0]
@@ -75,10 +73,9 @@ class CinderHelper(object):
def get_volume_type_by_backendname(self, backendname): def get_volume_type_by_backendname(self, backendname):
volume_type_list = self.get_volume_type_list() volume_type_list = self.get_volume_type_list()
volume_type = list(filter( volume_type = [volume_type for volume_type in volume_type_list
lambda volume_type: if volume_type.extra_specs.get(
volume_type.extra_specs.get( 'volume_backend_name') == backendname]
'volume_backend_name') == backendname, volume_type_list))
if volume_type: if volume_type:
return volume_type[0].name return volume_type[0].name
else: else: