mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
Replace uses of map()
In Python 2, map() returns a list; in Python 3 it returns an iterator. Replace all uses by list comprehensions, generators, or for loops, as required. Reviewed-By: Christian Heimes <cheimes@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
This commit is contained in:
parent
fbacc26a6a
commit
ace63f4ea5
@ -294,7 +294,7 @@ class textui(backend.Backend):
|
||||
for v in value:
|
||||
self.print_indented(format % (attr, self.encode_binary(v)), indent)
|
||||
else:
|
||||
value = map(lambda v: self.encode_binary(v), value)
|
||||
value = [self.encode_binary(v) for v in value]
|
||||
if len(value) > 0 and type(value[0]) in (list, tuple):
|
||||
# This is where we print failed add/remove members
|
||||
for l in value:
|
||||
|
@ -870,7 +870,7 @@ class Command(HasParam):
|
||||
if optional and arg.required:
|
||||
raise ValueError(
|
||||
'%s: required argument after optional in %s arguments %s' % (arg.name,
|
||||
self.name, map(lambda x: x.param_spec, args()))
|
||||
self.name, [x.param_spec for x in args()])
|
||||
)
|
||||
if multivalue:
|
||||
raise ValueError(
|
||||
|
@ -69,7 +69,7 @@ def process_message_arguments(obj, format=None, message=None, **kw):
|
||||
if 'instructions' in kw:
|
||||
def convert_instructions(value):
|
||||
if isinstance(value, list):
|
||||
result = u'\n'.join(map(lambda line: unicode(line), value))
|
||||
result = u'\n'.join(unicode(line) for line in value)
|
||||
return result
|
||||
return value
|
||||
instructions = u'\n'.join((unicode(_('Additional instructions:')),
|
||||
|
@ -300,7 +300,7 @@ def wait_for_value(ldap, dn, attr, value):
|
||||
entry_attrs = ldap.get_entry(dn, ['*'])
|
||||
if attr in entry_attrs:
|
||||
if isinstance(entry_attrs[attr], (list, tuple)):
|
||||
values = map(lambda y:y.lower(), entry_attrs[attr])
|
||||
values = [y.lower() for y in entry_attrs[attr]]
|
||||
if value.lower() in values:
|
||||
break
|
||||
else:
|
||||
@ -627,7 +627,7 @@ class LDAPObject(Object):
|
||||
)
|
||||
|
||||
def has_objectclass(self, classes, objectclass):
|
||||
oc = map(lambda x:x.lower(),classes)
|
||||
oc = [x.lower() for x in classes]
|
||||
return objectclass.lower() in oc
|
||||
|
||||
def convert_attribute_members(self, entry_attrs, *keys, **options):
|
||||
|
@ -292,7 +292,7 @@ class certprofile_del(LDAPDelete):
|
||||
def pre_callback(self, ldap, dn, *keys, **options):
|
||||
ca_enabled_check()
|
||||
|
||||
if keys[0] in map(attrgetter('profile_id'), INCLUDED_PROFILES):
|
||||
if keys[0] in [p.profile_id for p in INCLUDED_PROFILES]:
|
||||
raise errors.ValidationError(name='profile_id',
|
||||
error=_("Predefined profile '%(profile_id)s' cannot be deleted")
|
||||
% {'profile_id': keys[0]}
|
||||
|
@ -3341,7 +3341,7 @@ class dnsrecord(LDAPObject):
|
||||
# during comparison
|
||||
ldap_rrset = dns.rrset.from_text(
|
||||
dns_name, 86400, dns.rdataclass.IN, rdtype,
|
||||
*map(str, value))
|
||||
*[str(v) for v in value])
|
||||
|
||||
# make sure that all names are absolute so RRset
|
||||
# comparison will work
|
||||
|
@ -643,7 +643,7 @@ class host_add(LDAPCreate):
|
||||
# save the password so it can be displayed in post_callback
|
||||
setattr(context, 'randompassword', entry_attrs['userpassword'])
|
||||
certs = options.get('usercertificate', [])
|
||||
certs_der = map(x509.normalize_certificate, certs)
|
||||
certs_der = [x509.normalize_certificate(c) for c in certs]
|
||||
for cert in certs_der:
|
||||
x509.verify_cert_subject(ldap, keys[-1], cert)
|
||||
entry_attrs['usercertificate'] = certs_der
|
||||
@ -846,7 +846,7 @@ class host_mod(LDAPUpdate):
|
||||
|
||||
# verify certificates
|
||||
certs = entry_attrs.get('usercertificate') or []
|
||||
certs_der = map(x509.normalize_certificate, certs)
|
||||
certs_der = [x509.normalize_certificate(c) for c in certs]
|
||||
for cert in certs_der:
|
||||
x509.verify_cert_subject(ldap, keys[-1], cert)
|
||||
|
||||
@ -857,7 +857,7 @@ class host_mod(LDAPUpdate):
|
||||
except errors.NotFound:
|
||||
self.obj.handle_not_found(*keys)
|
||||
old_certs = entry_attrs_old.get('usercertificate', [])
|
||||
old_certs_der = map(x509.normalize_certificate, old_certs)
|
||||
old_certs_der = [x509.normalize_certificate(c) for c in old_certs]
|
||||
removed_certs_der = set(old_certs_der) - set(certs_der)
|
||||
revoke_certs(removed_certs_der, self.log)
|
||||
|
||||
|
@ -97,8 +97,8 @@ class OTPTokenKey(Bytes):
|
||||
|
||||
def _convert_owner(userobj, entry_attrs, options):
|
||||
if 'ipatokenowner' in entry_attrs and not options.get('raw', False):
|
||||
entry_attrs['ipatokenowner'] = map(userobj.get_primary_key_from_dn,
|
||||
entry_attrs['ipatokenowner'])
|
||||
entry_attrs['ipatokenowner'] = [userobj.get_primary_key_from_dn(o)
|
||||
for o in entry_attrs['ipatokenowner']]
|
||||
|
||||
def _normalize_owner(userobj, entry_attrs):
|
||||
owner = entry_attrs.get('ipatokenowner', None)
|
||||
|
@ -167,7 +167,7 @@ class cosentry_add(LDAPCreate):
|
||||
except errors.NotFound:
|
||||
self.api.Object.group.handle_not_found(keys[-1])
|
||||
|
||||
oc = map(lambda x:x.lower(),result['objectclass'])
|
||||
oc = [x.lower() for x in result['objectclass']]
|
||||
if 'mepmanagedentry' in oc:
|
||||
raise errors.ManagedPolicyError()
|
||||
self.obj.check_priority_uniqueness(*keys, **options)
|
||||
|
@ -541,7 +541,7 @@ class service_add(LDAPCreate):
|
||||
self.obj.validate_ipakrbauthzdata(entry_attrs)
|
||||
|
||||
certs = options.get('usercertificate', [])
|
||||
certs_der = map(x509.normalize_certificate, certs)
|
||||
certs_der = [x509.normalize_certificate(c) for c in certs]
|
||||
for dercert in certs_der:
|
||||
x509.verify_cert_subject(ldap, hostname, dercert)
|
||||
entry_attrs['usercertificate'] = certs_der
|
||||
@ -617,7 +617,7 @@ class service_mod(LDAPUpdate):
|
||||
|
||||
# verify certificates
|
||||
certs = entry_attrs.get('usercertificate') or []
|
||||
certs_der = map(x509.normalize_certificate, certs)
|
||||
certs_der = [x509.normalize_certificate(c) for c in certs]
|
||||
for dercert in certs_der:
|
||||
x509.verify_cert_subject(ldap, hostname, dercert)
|
||||
# revoke removed certificates
|
||||
@ -627,7 +627,7 @@ class service_mod(LDAPUpdate):
|
||||
except errors.NotFound:
|
||||
self.obj.handle_not_found(*keys)
|
||||
old_certs = entry_attrs_old.get('usercertificate', [])
|
||||
old_certs_der = map(x509.normalize_certificate, old_certs)
|
||||
old_certs_der = [x509.normalize_certificate(c) for c in old_certs]
|
||||
removed_certs_der = set(old_certs_der) - set(certs_der)
|
||||
revoke_certs(removed_certs_der, self.log)
|
||||
|
||||
|
@ -656,8 +656,8 @@ class sudorule_add_host(LDAPAddMember):
|
||||
if 'hostmask' in options:
|
||||
norm = lambda x: unicode(netaddr.IPNetwork(x).cidr)
|
||||
|
||||
old_masks = set(map(norm, _entry_attrs.get('hostmask', [])))
|
||||
new_masks = set(map(norm, options['hostmask']))
|
||||
old_masks = set(norm(m) for m in _entry_attrs.get('hostmask', []))
|
||||
new_masks = set(norm(m) for m in options['hostmask'])
|
||||
|
||||
num_added = len(new_masks - old_masks)
|
||||
|
||||
@ -699,10 +699,11 @@ class sudorule_remove_host(LDAPRemoveMember):
|
||||
self.obj.handle_not_found(*keys)
|
||||
|
||||
if 'hostmask' in options:
|
||||
norm = lambda x: unicode(netaddr.IPNetwork(x).cidr)
|
||||
def norm(x):
|
||||
return unicode(netaddr.IPNetwork(x).cidr)
|
||||
|
||||
old_masks = set(map(norm, _entry_attrs.get('hostmask', [])))
|
||||
removed_masks = set(map(norm, options['hostmask']))
|
||||
old_masks = set(norm(m) for m in _entry_attrs.get('hostmask', []))
|
||||
removed_masks = set(norm(m) for m in options['hostmask'])
|
||||
|
||||
num_added = len(removed_masks & old_masks)
|
||||
|
||||
|
@ -534,7 +534,7 @@ class trust(LDAPObject):
|
||||
error=_("invalid SID: %(value)s") % dict(value=value))
|
||||
|
||||
def get_dn(self, *keys, **kwargs):
|
||||
sdn = map(lambda x: ('cn', x), keys)
|
||||
sdn = [('cn', x) for x in keys]
|
||||
sdn.reverse()
|
||||
trust_type = kwargs.get('trust_type')
|
||||
if trust_type is None:
|
||||
@ -1233,7 +1233,7 @@ class trust_resolve(Command):
|
||||
if not _nss_idmap_installed:
|
||||
return dict(result=result)
|
||||
try:
|
||||
sids = map(lambda x: str(x), options['sids'])
|
||||
sids = [str(x) for x in options['sids']]
|
||||
xlate = pysss_nss_idmap.getnamebysid(sids)
|
||||
for sid in xlate:
|
||||
entry = dict()
|
||||
@ -1402,7 +1402,7 @@ class trustdomain(LDAPObject):
|
||||
# to the parent object's get_dn() no matter what you pass to it. Make own get_dn()
|
||||
# as we really need all elements to construct proper dn.
|
||||
def get_dn(self, *keys, **kwargs):
|
||||
sdn = map(lambda x: ('cn', x), keys)
|
||||
sdn = [('cn', x) for x in keys]
|
||||
sdn.reverse()
|
||||
trust_type = kwargs.get('trust_type')
|
||||
if not trust_type:
|
||||
|
@ -234,7 +234,8 @@ def validate_domain_name(domain_name, allow_underscore=False, allow_slash=False)
|
||||
domain_name = domain_name.split(".")
|
||||
|
||||
# apply DNS name validator to every name part
|
||||
map(lambda label:validate_dns_label(label, allow_underscore, allow_slash), domain_name)
|
||||
for label in domain_name:
|
||||
validate_dns_label(label, allow_underscore, allow_slash)
|
||||
|
||||
|
||||
def validate_zonemgr(zonemgr):
|
||||
@ -734,7 +735,8 @@ def validate_idna_domain(value):
|
||||
#user should use normalized names to avoid mistakes
|
||||
labels = re.split(u'[.\uff0e\u3002\uff61]', value, flags=re.UNICODE)
|
||||
try:
|
||||
map(lambda label: label.encode("ascii"), labels)
|
||||
for label in labels:
|
||||
label.encode("ascii")
|
||||
except UnicodeError:
|
||||
# IDNA
|
||||
is_nonnorm = any(encodings.idna.nameprep(x) != x for x in labels)
|
||||
|
@ -42,12 +42,12 @@ class ValidationError(Exception):
|
||||
|
||||
|
||||
def fetchAll(element, xpath, conv=lambda x: x):
|
||||
return map(conv, element.xpath(xpath, namespaces={
|
||||
return [conv(e) for e in element.xpath(xpath, namespaces={
|
||||
"pskc": "urn:ietf:params:xml:ns:keyprov:pskc",
|
||||
"xenc11": "http://www.w3.org/2009/xmlenc11#",
|
||||
"xenc": "http://www.w3.org/2001/04/xmlenc#",
|
||||
"ds": "http://www.w3.org/2000/09/xmldsig#",
|
||||
}))
|
||||
})]
|
||||
|
||||
|
||||
def fetch(element, xpath, conv=lambda x: x, default=None):
|
||||
|
@ -54,7 +54,7 @@ class IntegrationTest(object):
|
||||
@classmethod
|
||||
def get_all_hosts(cls):
|
||||
return ([cls.master] + cls.replicas + cls.clients +
|
||||
map(cls.host_by_role, cls.required_extra_roles))
|
||||
[cls.host_by_role(r) for r in cls.required_extra_roles])
|
||||
|
||||
@classmethod
|
||||
def get_domains(cls):
|
||||
|
@ -329,8 +329,7 @@ class test_PublicError(PublicExceptionTester):
|
||||
# this expression checks if each word of instructions
|
||||
# exists in a string as a separate line, with right order
|
||||
regexp = re.compile('(?ims).*' +
|
||||
''.join(map(lambda x: '(%s).*' % (x),
|
||||
instructions)) +
|
||||
''.join('(%s).*' % (x) for x in instructions) +
|
||||
'$')
|
||||
inst = subclass(instructions=instructions, **kw)
|
||||
assert inst.format is subclass.format
|
||||
|
@ -191,7 +191,7 @@ class CertManipCmdTestBase(XMLRPC_test):
|
||||
"""
|
||||
assert_deepequal(
|
||||
dict(
|
||||
usercertificate=map(base64.b64decode, self.certs),
|
||||
usercertificate=[base64.b64decode(c) for c in self.certs],
|
||||
summary=self.cert_add_summary % self.entity_pkey,
|
||||
value=self.entity_pkey,
|
||||
),
|
||||
@ -237,8 +237,8 @@ class CertManipCmdTestBase(XMLRPC_test):
|
||||
"""
|
||||
assert_deepequal(
|
||||
dict(
|
||||
usercertificate=map(base64.b64decode,
|
||||
self.certs_remainder),
|
||||
usercertificate=[base64.b64decode(c)
|
||||
for c in self.certs_remainder],
|
||||
summary=self.cert_del_summary % self.entity_pkey,
|
||||
value=self.entity_pkey,
|
||||
),
|
||||
|
@ -34,7 +34,7 @@ symmetric_vault_name = u'symmetric_test_vault'
|
||||
asymmetric_vault_name = u'asymmetric_test_vault'
|
||||
|
||||
# binary data from \x00 to \xff
|
||||
secret = ''.join(map(chr, xrange(0, 256)))
|
||||
secret = ''.join(chr(c) for c in xrange(0, 256))
|
||||
|
||||
password = u'password'
|
||||
other_password = u'other_password'
|
||||
|
Loading…
Reference in New Issue
Block a user