diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-08-12 12:25:30 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-09-01 11:42:01 +0200 |
commit | ace63f4ea55643cb99aaa444d216a6bb9ebb1ed3 (patch) | |
tree | 0b5367a1b43369dc0ea20b9e8fde91d44abed1f1 | |
parent | fbacc26a6a8b92f4b3570c411b186ab86cbcc1b1 (diff) | |
download | freeipa-ace63f4ea55643cb99aaa444d216a6bb9ebb1ed3.tar.gz freeipa-ace63f4ea55643cb99aaa444d216a6bb9ebb1ed3.tar.xz freeipa-ace63f4ea55643cb99aaa444d216a6bb9ebb1ed3.zip |
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>
-rw-r--r-- | ipalib/cli.py | 2 | ||||
-rw-r--r-- | ipalib/frontend.py | 2 | ||||
-rw-r--r-- | ipalib/messages.py | 2 | ||||
-rw-r--r-- | ipalib/plugins/baseldap.py | 4 | ||||
-rw-r--r-- | ipalib/plugins/certprofile.py | 2 | ||||
-rw-r--r-- | ipalib/plugins/dns.py | 2 | ||||
-rw-r--r-- | ipalib/plugins/host.py | 6 | ||||
-rw-r--r-- | ipalib/plugins/otptoken.py | 4 | ||||
-rw-r--r-- | ipalib/plugins/pwpolicy.py | 2 | ||||
-rw-r--r-- | ipalib/plugins/service.py | 6 | ||||
-rw-r--r-- | ipalib/plugins/sudorule.py | 11 | ||||
-rw-r--r-- | ipalib/plugins/trust.py | 6 | ||||
-rw-r--r-- | ipalib/util.py | 6 | ||||
-rw-r--r-- | ipaserver/install/ipa_otptoken_import.py | 4 | ||||
-rw-r--r-- | ipatests/test_integration/base.py | 2 | ||||
-rw-r--r-- | ipatests/test_ipalib/test_errors.py | 3 | ||||
-rw-r--r-- | ipatests/test_xmlrpc/test_add_remove_cert_cmd.py | 6 | ||||
-rw-r--r-- | ipatests/test_xmlrpc/test_vault_plugin.py | 2 |
18 files changed, 37 insertions, 35 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index bd0e7fb0a..36360008e 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -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: diff --git a/ipalib/frontend.py b/ipalib/frontend.py index d61df02ba..fbada31a8 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -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( diff --git a/ipalib/messages.py b/ipalib/messages.py index c932b30f7..853979506 100644 --- a/ipalib/messages.py +++ b/ipalib/messages.py @@ -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:')), diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 59d39c403..8a375afba 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -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): diff --git a/ipalib/plugins/certprofile.py b/ipalib/plugins/certprofile.py index a0ffa3860..8e60a4df8 100644 --- a/ipalib/plugins/certprofile.py +++ b/ipalib/plugins/certprofile.py @@ -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]} diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index 6044d3823..7885f029e 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -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 diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py index ec367b8e1..6380962e7 100644 --- a/ipalib/plugins/host.py +++ b/ipalib/plugins/host.py @@ -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) diff --git a/ipalib/plugins/otptoken.py b/ipalib/plugins/otptoken.py index 3c2cb9309..57de5b782 100644 --- a/ipalib/plugins/otptoken.py +++ b/ipalib/plugins/otptoken.py @@ -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) diff --git a/ipalib/plugins/pwpolicy.py b/ipalib/plugins/pwpolicy.py index 4425a921a..866d57475 100644 --- a/ipalib/plugins/pwpolicy.py +++ b/ipalib/plugins/pwpolicy.py @@ -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) diff --git a/ipalib/plugins/service.py b/ipalib/plugins/service.py index d20f52876..39285dd5d 100644 --- a/ipalib/plugins/service.py +++ b/ipalib/plugins/service.py @@ -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) diff --git a/ipalib/plugins/sudorule.py b/ipalib/plugins/sudorule.py index 1bd9042b9..6844343e1 100644 --- a/ipalib/plugins/sudorule.py +++ b/ipalib/plugins/sudorule.py @@ -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) diff --git a/ipalib/plugins/trust.py b/ipalib/plugins/trust.py index 6400a4c54..febe16f1d 100644 --- a/ipalib/plugins/trust.py +++ b/ipalib/plugins/trust.py @@ -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: diff --git a/ipalib/util.py b/ipalib/util.py index 3cd23c96e..5a761fb0f 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -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) diff --git a/ipaserver/install/ipa_otptoken_import.py b/ipaserver/install/ipa_otptoken_import.py index 5f5d21560..4d901d08e 100644 --- a/ipaserver/install/ipa_otptoken_import.py +++ b/ipaserver/install/ipa_otptoken_import.py @@ -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): diff --git a/ipatests/test_integration/base.py b/ipatests/test_integration/base.py index ee41b4142..4f57e9590 100644 --- a/ipatests/test_integration/base.py +++ b/ipatests/test_integration/base.py @@ -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): diff --git a/ipatests/test_ipalib/test_errors.py b/ipatests/test_ipalib/test_errors.py index 938b9fcec..dfe60f283 100644 --- a/ipatests/test_ipalib/test_errors.py +++ b/ipatests/test_ipalib/test_errors.py @@ -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 diff --git a/ipatests/test_xmlrpc/test_add_remove_cert_cmd.py b/ipatests/test_xmlrpc/test_add_remove_cert_cmd.py index c414498a2..e42c1929f 100644 --- a/ipatests/test_xmlrpc/test_add_remove_cert_cmd.py +++ b/ipatests/test_xmlrpc/test_add_remove_cert_cmd.py @@ -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, ), diff --git a/ipatests/test_xmlrpc/test_vault_plugin.py b/ipatests/test_xmlrpc/test_vault_plugin.py index 495512dac..f3b0e0135 100644 --- a/ipatests/test_xmlrpc/test_vault_plugin.py +++ b/ipatests/test_xmlrpc/test_vault_plugin.py @@ -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' |