Fix: "map" issue for Python 2/3 compatible code

Replace map(func, data) with [func(item) for item in data]

Story: 2003433
Task:28377

Change-Id: I0a41561dd6ac7c30c2c5c9eb127946d0a49586bc
Signed-off-by: Sun Austin <austin.sun@intel.com>
This commit is contained in:
Sun Austin 2018-12-11 16:31:19 +08:00
parent 92f3f4a823
commit 6c3bf61663
10 changed files with 14 additions and 16 deletions

View File

@ -109,8 +109,7 @@ def get_backup_databases(cinder_config=False):
# mentioned in BACKUP_DATABASES. We explicitly list
# skip tables in DB_TABLE_SKIP_MAPPING
BACKUP_DB_SKIP_TABLES = dict(
map(lambda x: [x, DB_TABLE_SKIP_MAPPING.get(x, ())],
BACKUP_DATABASES))
[[x, DB_TABLE_SKIP_MAPPING.get(x, ())] for x in BACKUP_DATABASES])
return BACKUP_DATABASES, BACKUP_DB_SKIP_TABLES

View File

@ -152,7 +152,7 @@ def _list_opts(obj):
if is_opt(attr_obj):
opts.append(attr_obj)
elif (isinstance(attr_obj, list) and
all(map(lambda x: is_opt(x), attr_obj))):
all([is_opt(x) for x in attr_obj])):
opts.extend(attr_obj)
ret = {}

View File

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

View File

@ -180,7 +180,7 @@ def execute(*cmd, **kwargs):
if run_as_root and os.geteuid() != 0:
cmd = ['sudo', 'sysinv-rootwrap', CONF.rootwrap_config] + list(cmd)
cmd = map(str, cmd)
cmd = [str(c) for c in cmd]
while attempts > 0:
attempts -= 1

View File

@ -152,7 +152,7 @@ def _list_opts(obj):
if is_opt(attr_obj):
opts.append(attr_obj)
elif (isinstance(attr_obj, list) and
all(map(lambda x: is_opt(x), attr_obj))):
all([is_opt(x) for x in attr_obj])):
opts.extend(attr_obj)
ret = {}

View File

@ -134,7 +134,7 @@ def execute(*cmd, **kwargs):
'helper.'))
cmd = shlex.split(root_helper) + list(cmd)
cmd = map(str, cmd)
cmd = [str(c) for c in cmd]
while attempts > 0:
attempts -= 1

View File

@ -510,7 +510,7 @@ def deserialize_msg(msg):
return msg
base_envelope_keys = (_VERSION_KEY, _MESSAGE_KEY)
if not all(map(lambda key: key in msg, base_envelope_keys)):
if not all([key in msg for key in base_envelope_keys]):
# See #1.b above.
return msg

View File

@ -153,7 +153,7 @@ class ZmqSocket(object):
"""Get socket type as string."""
t_enum = ('PUSH', 'PULL', 'PUB', 'SUB', 'REP', 'REQ', 'ROUTER',
'DEALER')
return dict(map(lambda t: (getattr(zmq, t), t), t_enum))[self.type]
return dict([(getattr(zmq, t), t) for t in t_enum])[self.type]
def subscribe(self, msg_filter):
"""Subscribe."""
@ -222,14 +222,14 @@ class ZmqClient(object):
msg_id = msg_id or 0
if not envelope:
self.outq.send(map(bytes,
(msg_id, topic, 'cast', _serialize(data))))
self.outq.send([bytes(x) for x in
(msg_id, topic, 'cast', _serialize(data))])
return
rpc_envelope = rpc_common.serialize_msg(data[1], envelope)
zmq_msg = reduce(lambda x, y: x + y, rpc_envelope.items())
self.outq.send(map(bytes,
(msg_id, topic, 'impl_zmq_v2', data[0]) + zmq_msg))
self.outq.send([bytes(x) for x in
((msg_id, topic, 'impl_zmq_v2', data[0]) + zmq_msg)])
def close(self):
self.outq.close()

View File

@ -100,7 +100,7 @@ class FanoutRingExchange(RingExchange):
"see ringfile") % (nkey, )
)
return []
return map(lambda x: (key + '.' + x, x), self.ring[nkey])
return [(key + '.' + x, x) for x in self.ring[nkey]]
class MatchMakerRing(mm.MatchMakerBase):

View File

@ -25,7 +25,7 @@ class StubGlanceClient(object):
def __init__(self, images=None):
self._images = []
_images = images or []
map(lambda image: self.create(**image), _images)
[self.create(**image) for image in _images]
# NOTE(bcwaldon): HACK to get client.images.* to work
self.images = lambda: None