python3: Apply "2to3 -f map"

map() has been changed to return an iterator in python3.  Iterators aren't
JSON serializable, and can be used only once for for loops.

Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
IWAMOTO Toshihiro 2015-06-26 18:03:37 +09:00 committed by FUJITA Tomonori
parent 227b8fd984
commit a9b250da75
16 changed files with 23 additions and 26 deletions

View File

@ -380,8 +380,7 @@ class AppManager(object):
while len(app_lists) > 0: while len(app_lists) > 0:
app_cls_name = app_lists.pop(0) app_cls_name = app_lists.pop(0)
context_modules = map(lambda x: x.__module__, context_modules = [x.__module__ for x in self.contexts_cls.values()]
self.contexts_cls.values())
if app_cls_name in context_modules: if app_cls_name in context_modules:
continue continue

View File

@ -92,7 +92,7 @@ class _Base(stringify.StringifyMixin):
continue continue
if isinstance(v, list): if isinstance(v, list):
assert e.is_list assert e.is_list
ele = map(convert, v) ele = list(map(convert, v))
else: else:
assert not e.is_list assert not e.is_list
ele = [convert(v)] ele = [convert(v)]
@ -128,7 +128,7 @@ class _Base(stringify.StringifyMixin):
v = [v] v = [v]
else: else:
assert e.is_list assert e.is_list
v = map(convert, v) v = list(map(convert, v))
k = _pythonify(e.name) k = _pythonify(e.name)
assert k not in kwargs assert k not in kwargs
kwargs[k] = v kwargs[k] = v

View File

@ -808,10 +808,10 @@ class _LabelledAddrPrefix(_AddrPrefix):
def _to_bin(cls, addr): def _to_bin(cls, addr):
labels = addr[0] labels = addr[0]
rest = addr[1:] rest = addr[1:]
labels = map(lambda x: x << 4, labels) labels = [x << 4 for x in labels]
if labels: if labels:
labels[-1] |= 1 # bottom of stack labels[-1] |= 1 # bottom of stack
bin_labels = map(cls._label_to_bin, labels) bin_labels = list(map(cls._label_to_bin, labels))
return bytes(reduce(lambda x, y: x + y, bin_labels, return bytes(reduce(lambda x, y: x + y, bin_labels,
bytearray()) + cls._prefix_to_bin(rest)) bytearray()) + cls._prefix_to_bin(rest))

View File

@ -463,8 +463,7 @@ class vrrpv2(vrrp):
ip_addresses_pack_str = cls._ip_addresses_pack_str(count_ip) ip_addresses_pack_str = cls._ip_addresses_pack_str(count_ip)
ip_addresses_bin = struct.unpack_from(ip_addresses_pack_str, buf, ip_addresses_bin = struct.unpack_from(ip_addresses_pack_str, buf,
offset) offset)
ip_addresses = map(lambda x: addrconv.ipv4.bin_to_text(x), ip_addresses = [addrconv.ipv4.bin_to_text(x) for x in ip_addresses_bin]
ip_addresses_bin)
offset += struct.calcsize(ip_addresses_pack_str) offset += struct.calcsize(ip_addresses_pack_str)
auth_data = struct.unpack_from(cls._AUTH_DATA_PACK_STR, buf, offset) auth_data = struct.unpack_from(cls._AUTH_DATA_PACK_STR, buf, offset)
@ -499,8 +498,7 @@ class vrrpv2(vrrp):
vrrp_.checksum) vrrp_.checksum)
offset += vrrpv2._MIN_LEN offset += vrrpv2._MIN_LEN
struct.pack_into(ip_addresses_pack_str, buf, offset, struct.pack_into(ip_addresses_pack_str, buf, offset,
*map(lambda x: addrconv.ipv4.text_to_bin(x), *[addrconv.ipv4.text_to_bin(x) for x in vrrp_.ip_addresses])
vrrp_.ip_addresses))
offset += ip_addresses_len offset += ip_addresses_len
struct.pack_into(vrrpv2._AUTH_DATA_PACK_STR, buf, offset, struct.pack_into(vrrpv2._AUTH_DATA_PACK_STR, buf, offset,
*vrrp_.auth_data) *vrrp_.auth_data)
@ -590,7 +588,7 @@ class vrrpv3(vrrp):
address_len, count_ip)) address_len, count_ip))
ip_addresses_bin = struct.unpack_from(pack_str, buf, offset) ip_addresses_bin = struct.unpack_from(pack_str, buf, offset)
ip_addresses = map(lambda x: conv(x), ip_addresses_bin) ip_addresses = [conv(x) for x in ip_addresses_bin]
msg = cls(version, type_, vrid, priority, msg = cls(version, type_, vrid, priority,
count_ip, max_adver_int, checksum, ip_addresses) count_ip, max_adver_int, checksum, ip_addresses)
return msg, None, buf[len(msg):] return msg, None, buf[len(msg):]
@ -624,7 +622,7 @@ class vrrpv3(vrrp):
vrrp_.vrid, vrrp_.priority, vrrp_.vrid, vrrp_.priority,
vrrp_.count_ip, vrrp_.max_adver_int, vrrp_.checksum) vrrp_.count_ip, vrrp_.max_adver_int, vrrp_.checksum)
struct.pack_into(ip_addresses_pack_str, buf, vrrpv3._MIN_LEN, struct.pack_into(ip_addresses_pack_str, buf, vrrpv3._MIN_LEN,
*map(lambda x: conv(x), vrrp_.ip_addresses)) *[conv(x) for x in vrrp_.ip_addresses])
if checksum: if checksum:
vrrp_.checksum = packet_utils.checksum_ip(prev, len(buf), buf) vrrp_.checksum = packet_utils.checksum_ip(prev, len(buf), buf)

View File

@ -190,7 +190,7 @@ class StringifyMixin(object):
if isinstance(v, (bytes, six.text_type)): if isinstance(v, (bytes, six.text_type)):
json_value = encode_string(v) json_value = encode_string(v)
elif isinstance(v, list): elif isinstance(v, list):
json_value = map(_encode, v) json_value = list(map(_encode, v))
elif isinstance(v, dict): elif isinstance(v, dict):
json_value = _mapdict(_encode, v) json_value = _mapdict(_encode, v)
# while a python dict key can be any hashable object, # while a python dict key can be any hashable object,
@ -272,7 +272,7 @@ class StringifyMixin(object):
if isinstance(json_value, (bytes, six.text_type)): if isinstance(json_value, (bytes, six.text_type)):
v = decode_string(json_value) v = decode_string(json_value)
elif isinstance(json_value, list): elif isinstance(json_value, list):
v = map(_decode, json_value) v = list(map(_decode, json_value))
elif isinstance(json_value, dict): elif isinstance(json_value, dict):
if cls._is_class(json_value): if cls._is_class(json_value):
v = cls.obj_from_jsondict(json_value, **additional_args) v = cls.obj_from_jsondict(json_value, **additional_args)

View File

@ -1016,7 +1016,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_STATS_PACK_STR, desc = struct.unpack_from(ofproto.OFP_DESC_STATS_PACK_STR,
buf, offset) buf, offset)
desc = list(desc) desc = list(desc)
desc = map(lambda x: x.rstrip('\0'), desc) desc = [x.rstrip('\0') for x in desc]
stats = cls(*desc) stats = cls(*desc)
stats.length = ofproto.OFP_DESC_STATS_SIZE stats.length = ofproto.OFP_DESC_STATS_SIZE
return stats return stats

View File

@ -1985,7 +1985,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_STATS_PACK_STR, desc = struct.unpack_from(ofproto.OFP_DESC_STATS_PACK_STR,
buf, offset) buf, offset)
desc = list(desc) desc = list(desc)
desc = map(lambda x: x.rstrip('\0'), desc) desc = [x.rstrip('\0') for x in desc]
stats = cls(*desc) stats = cls(*desc)
stats.length = ofproto.OFP_DESC_STATS_SIZE stats.length = ofproto.OFP_DESC_STATS_SIZE
return stats return stats

View File

@ -3655,7 +3655,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR, desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR,
buf, offset) buf, offset)
desc = list(desc) desc = list(desc)
desc = map(lambda x: x.rstrip('\0'), desc) desc = [x.rstrip('\0') for x in desc]
stats = cls(*desc) stats = cls(*desc)
stats.length = ofproto.OFP_DESC_SIZE stats.length = ofproto.OFP_DESC_SIZE
return stats return stats

View File

@ -2101,7 +2101,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR, desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR,
buf, offset) buf, offset)
desc = list(desc) desc = list(desc)
desc = map(lambda x: x.rstrip('\0'), desc) desc = [x.rstrip('\0') for x in desc]
stats = cls(*desc) stats = cls(*desc)
stats.length = ofproto.OFP_DESC_SIZE stats.length = ofproto.OFP_DESC_SIZE
return stats return stats

View File

@ -2242,7 +2242,7 @@ class OFPDescStats(ofproto_parser.namedtuple('OFPDescStats', (
desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR, desc = struct.unpack_from(ofproto.OFP_DESC_PACK_STR,
buf, offset) buf, offset)
desc = list(desc) desc = list(desc)
desc = map(lambda x: x.rstrip('\0'), desc) desc = [x.rstrip('\0') for x in desc]
stats = cls(*desc) stats = cls(*desc)
stats.length = ofproto.OFP_DESC_SIZE stats.length = ofproto.OFP_DESC_SIZE
return stats return stats

View File

@ -143,7 +143,7 @@ class OperatorListView(OperatorAbstractView):
def combine_related(self, field_name): def combine_related(self, field_name):
f = self._fields[field_name] f = self._fields[field_name]
return CombinedViewsWrapper(RdyToFlattenList( return CombinedViewsWrapper(RdyToFlattenList(
map(lambda obj: f.retrieve_and_wrap(obj), self.model) [f.retrieve_and_wrap(obj) for obj in self.model]
)) ))
def get_field(self, field_name): def get_field(self, field_name):
@ -175,7 +175,7 @@ class OperatorDictView(OperatorAbstractView):
def combine_related(self, field_name): def combine_related(self, field_name):
f = self._fields[field_name] f = self._fields[field_name]
return CombinedViewsWrapper(RdyToFlattenList( return CombinedViewsWrapper(RdyToFlattenList(
map(lambda obj: f.retrieve_and_wrap(obj), self.model.values())) [f.retrieve_and_wrap(obj) for obj in self.model.values()])
) )
def get_field(self, field_name): def get_field(self, field_name):

View File

@ -31,7 +31,7 @@ def is_valid_ipv4(ipv4):
valid = False valid = False
else: else:
try: try:
a, b, c, d = map(lambda x: int(x), ipv4.split('.')) a, b, c, d = [int(x) for x in ipv4.split('.')]
if (a < 0 or a > 255 or b < 0 or b > 255 or c < 0 or c > 255 or if (a < 0 or a > 255 or b < 0 or b > 255 or c < 0 or c > 255 or
d < 0 or d > 255): d < 0 or d > 255):
valid = False valid = False

View File

@ -156,7 +156,7 @@ class VRRPConfig(object):
def __hash__(self): def __hash__(self):
hash((self.version, self.vrid, self.priority, hash((self.version, self.vrid, self.priority,
map(vrrp.ip_text_to_bin, self.ip_addresses), list(map(vrrp.ip_text_to_bin, self.ip_addresses)),
self.advertisement_interval, self.preempt_mode, self.advertisement_interval, self.preempt_mode,
self.preempt_delay, self.accept_mode, self.is_ipv6)) self.preempt_delay, self.accept_mode, self.is_ipv6))

View File

@ -204,7 +204,7 @@ class Test_Parser(unittest.TestCase):
def _remove(d, names): def _remove(d, names):
f = lambda x: _remove(x, names) f = lambda x: _remove(x, names)
if isinstance(d, list): if isinstance(d, list):
return map(f, d) return list(map(f, d))
if isinstance(d, dict): if isinstance(d, dict):
d2 = {} d2 = {}
for k, v in d.items(): for k, v in d.items():

View File

@ -211,7 +211,7 @@ def _add_tests():
l = itertools.product(l, cls.generate()) l = itertools.product(l, cls.generate())
keys.append(k) keys.append(k)
clss.append(cls) clss.append(cls)
l = map(lambda x: flatten(x)[1:], l) l = [flatten(x)[1:] for x in l]
for domask in [True, False]: for domask in [True, False]:
for values in l: for values in l:
if domask: if domask:

View File

@ -169,7 +169,7 @@ def _add_tests():
l = itertools.product(l, cls.generate()) l = itertools.product(l, cls.generate())
keys.append(k) keys.append(k)
clss.append(cls) clss.append(cls)
l = map(lambda x: flatten(x)[1:], l) l = [flatten(x)[1:] for x in l]
for values in l: for values in l:
d = dict(zip(keys, values)) d = dict(zip(keys, values))
for n, uv in d.items(): for n, uv in d.items():