From 3e935b9da877eebe29b11fd340f3e23d8eabc8ec Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 6 Jul 2020 23:29:18 +0200 Subject: [PATCH] misc: remove all uses of map() (#44878) --- src/authentic2/attributes_ng/sources/function.py | 2 +- src/authentic2/backends/ldap_backend.py | 12 ++++++------ src/authentic2/custom_user/models.py | 2 +- src/authentic2/exponential_retry_timeout.py | 2 +- src/authentic2/idp/saml/saml2_endpoints.py | 2 +- src/authentic2/manager/resources.py | 4 ++-- src/authentic2/manager/user_views.py | 4 ++-- src/authentic2/utils/__init__.py | 2 +- src/authentic2/views.py | 2 +- .../management/commands/oidc-register-issuer.py | 2 +- src/authentic2_idp_oidc/utils.py | 2 +- tests/test_hashers.py | 4 ++-- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/authentic2/attributes_ng/sources/function.py b/src/authentic2/attributes_ng/sources/function.py index ce47d1bb..69c06201 100644 --- a/src/authentic2/attributes_ng/sources/function.py +++ b/src/authentic2/attributes_ng/sources/function.py @@ -51,7 +51,7 @@ def get_instances(ctx): config_error(MISSING_KEYS_ERROR, missing) dependencies = d['dependencies'] if not isinstance(dependencies, (list, tuple)) or \ - not all(map(lambda x: isinstance(x, str), dependencies)): + not all(isinstance(dep, str) for dep in dependencies): config_error(DEPENDENCY_TYPE_ERROR) if not callable(d['function']): diff --git a/src/authentic2/backends/ldap_backend.py b/src/authentic2/backends/ldap_backend.py index 47731b8f..0b0859ee 100644 --- a/src/authentic2/backends/ldap_backend.py +++ b/src/authentic2/backends/ldap_backend.py @@ -24,7 +24,7 @@ try: from ldap.dn import escape_dn_chars from ldap.ldapobject import ReconnectLDAPObject as NativeLDAPObject from ldap.controls import SimplePagedResultsControl - PYTHON_LDAP3 = list(map(int, ldap.__version__.split('.'))) >= [3] + PYTHON_LDAP3 = [int(x) for x in ldap.__version__.split('.')] >= [3] LDAPObject = NativeLDAPObject except ImportError: ldap = None @@ -121,7 +121,7 @@ if PYTHON_LDAP3 is True: if mod_vals is None: pass elif isinstance(mod_vals, list): - mod_vals = list(map(convert, mod_vals)) + mod_vals = [convert(mod_val) for mod_val in mod_vals] else: mod_vals = convert(mod_vals) new_modlist.append((mod_op, mod_typ, mod_vals)) @@ -173,7 +173,7 @@ elif PYTHON_LDAP3 is False: base = force_bytes(base) filterstr = force_bytes(filterstr) if attrlist: - attrlist = map(force_bytes, attrlist) + attrlist = [force_bytes(attr) for attr in attrlist] return NativeLDAPObject.search_ext(self, base, scope, filterstr=filterstr, attrlist=attrlist, @@ -197,7 +197,7 @@ elif PYTHON_LDAP3 is False: if mod_vals is None: pass elif isinstance(mod_vals, list): - mod_vals = list(map(convert, mod_vals)) + mod_vals = [convert(mod_val) for mod_val in mod_vals] else: mod_vals = convert(mod_vals) new_modlist.append((mod_op, mod_typ, mod_vals)) @@ -1214,10 +1214,10 @@ class LDAPBackend(object): new_attributes = {} for key in attributes: try: - new_attributes[key.lower()] = list(map(lambda x: force_text(x, encoding), attributes[key])) + new_attributes[key.lower()] = [force_text(value, encoding) for value in attributes[key]] except UnicodeDecodeError: log.debug('unable to decode attribute %r as UTF-8, converting to base64', key) - new_attributes[key.lower()] = list(map(base64.b64encode, attributes[key])) + new_attributes[key.lower()] = [base64.b64encode(value).decode('ascii') for value in attributes[key]] return new_attributes @classmethod diff --git a/src/authentic2/custom_user/models.py b/src/authentic2/custom_user/models.py index 11c3ff31..8230dc07 100644 --- a/src/authentic2/custom_user/models.py +++ b/src/authentic2/custom_user/models.py @@ -102,7 +102,7 @@ class Attributes(object): return atv.to_python() else: # multiple - return list(map(lambda x: x.to_python(), atv)) + return [x.to_python() for x in atv] return None diff --git a/src/authentic2/exponential_retry_timeout.py b/src/authentic2/exponential_retry_timeout.py index 450e5247..65bf8ac9 100644 --- a/src/authentic2/exponential_retry_timeout.py +++ b/src/authentic2/exponential_retry_timeout.py @@ -43,7 +43,7 @@ class ExponentialRetryTimeout(object): self.key_prefix = key_prefix def key(self, keys): - key = u'-'.join(map(six.text_type, keys)) + key = u'-'.join(six.text_type(key) for key in keys) key = key.encode('utf-8') return '%s%s' % (self.key_prefix or self.KEY_PREFIX, hashlib.md5(key).hexdigest()) diff --git a/src/authentic2/idp/saml/saml2_endpoints.py b/src/authentic2/idp/saml/saml2_endpoints.py index 65cf604d..b70fdd00 100644 --- a/src/authentic2/idp/saml/saml2_endpoints.py +++ b/src/authentic2/idp/saml/saml2_endpoints.py @@ -1466,7 +1466,7 @@ def idp_slo(request, provider_id=None): logout.request.sessionIndexes = [] else: session_indexes = lib_sessions.values_list('session_index', flat=True) - logout.request.sessionIndexes = tuple(map(force_str, session_indexes)) + logout.request.sessionIndexes = tuple(force_str(session_index) for session_index in session_indexes) logout.msgRelayState = logout.request.id try: logout.buildRequestMsg() diff --git a/src/authentic2/manager/resources.py b/src/authentic2/manager/resources.py index 0ebd565f..410de2fc 100644 --- a/src/authentic2/manager/resources.py +++ b/src/authentic2/manager/resources.py @@ -31,7 +31,7 @@ class ListWidget(Widget): raise NotImplementedError def render(self, value, object): - return u', '.join(map(six.text_type, value.all())) + return u', '.join(six.text_type(v) for v in value.all()) class UserResource(ModelResource): @@ -43,7 +43,7 @@ class UserResource(ModelResource): result.add(role) for pr in role.parent_relation.all(): result.add(pr.parent) - return ', '.join(map(six.text_type, result)) + return ', '.join(six.text_type(x) for x in result) class Meta: model = User diff --git a/src/authentic2/manager/user_views.py b/src/authentic2/manager/user_views.py index ddd47e48..dcbb934d 100644 --- a/src/authentic2/manager/user_views.py +++ b/src/authentic2/manager/user_views.py @@ -449,7 +449,7 @@ class UsersExportView(ExportMixin, UsersView): for attr in attributes: record.append(attr_d.get(attr)) - return list(map(iso, record)) + return [iso(x) for x in record] self._dataset = tablib.Dataset(headers=headers) for user in self.get_data(): @@ -560,7 +560,7 @@ class UserRolesView(HideOUColumnMixin, BaseSubTableView): 'members', queryset=User.objects.filter(pk=self.object.pk), to_attr='member')) qs2 = self.request.user.filter_by_perm('a2_rbac.manage_members_role', qs) - managable_ids = map(str, qs2.values_list('pk', flat=True)) + managable_ids = [str(pk) for pk in qs2.values_list('pk', flat=True)] qs = qs.extra(select={'has_perm': 'a2_rbac_role.id in (%s)' % ', '.join(managable_ids)}) qs = qs.exclude(slug__startswith='_a2-managers-of-role') return qs diff --git a/src/authentic2/utils/__init__.py b/src/authentic2/utils/__init__.py index 5dcd92eb..c65c910c 100644 --- a/src/authentic2/utils/__init__.py +++ b/src/authentic2/utils/__init__.py @@ -1181,7 +1181,7 @@ def get_remember_cookie(request, name, count=5): def prepend_remember_cookie(request, response, name, value, count=5): values = get_remember_cookie(request, name, count=count) values = [value] + values[:count - 1] - response.set_cookie(name, ' '.join(map(str, values)), + response.set_cookie(name, ' '.join(str(value) for value in values), max_age=86400 * 365, # keep preferences for 1 year path=request.path, httponly=True) diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 052d6ed3..fb1c66be 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -470,7 +470,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView): if not isinstance(value, (list, tuple)): value = (value,) raw_value = value - value = map(six.text_type, value) + value = [six.text_type(v) for v in value] if value or app_settings.A2_PROFILE_DISPLAY_EMPTY_FIELDS: profile.append((title, value)) attributes.append({'attribute': attribute, 'values': raw_value}) diff --git a/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py b/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py index eae9a75a..1577ebad 100644 --- a/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py +++ b/src/authentic2_auth_oidc/management/commands/oidc-register-issuer.py @@ -113,7 +113,7 @@ class Command(BaseCommand): raise CommandError('invalid claim mapping %r. it must contain at least a claim and ' 'an attribute name') claim, attribute = tup[:2] - claim_options = map(str.strip, tup[2:]) + claim_options = [x.strip() for x in tup[2:]] extra = { 'required': 'required' in claim_options, 'idtoken_claim': 'idtoken' in claim_options, diff --git a/src/authentic2_idp_oidc/utils.py b/src/authentic2_idp_oidc/utils.py index 26475dcf..954ad8bb 100644 --- a/src/authentic2_idp_oidc/utils.py +++ b/src/authentic2_idp_oidc/utils.py @@ -103,7 +103,7 @@ def scope_set(data): def clean_words(data): '''Clean and order a list of words''' - return u' '.join(sorted(map(six.text_type.strip, data.split()))) + return u' '.join(sorted(x.strip() for x in data.split())) def url_domain(url): diff --git a/tests/test_hashers.py b/tests/test_hashers.py index 63827d67..0886062b 100644 --- a/tests/test_hashers.py +++ b/tests/test_hashers.py @@ -28,12 +28,12 @@ def test_sha256_hasher(): def test_openldap_hashers(): - VECTORS = map(str.split, '''\ + VECTORS = [x.split() for x in '''\ coin {SHA}NHj+acfc68FPYrMipEBZ3t8ABGY= 250523 {SHA}4zuJhPW1w0upqG7beAlxDcvtBj0= coin {SSHA}zLPxfZ3RSNkIwVdHWEyB4Tpr6fT9LiVX coin {SMD5}+x9QkU2T/wlPp6NK3bfYYxPYwaE= -coin {MD5}lqlRm4/d0X6MxLugQI///Q=='''.splitlines()) +coin {MD5}lqlRm4/d0X6MxLugQI///Q=='''.splitlines()] for password, oldap_hash in VECTORS: dj_hash = hashers.olap_password_to_dj(oldap_hash) assert check_password(password, dj_hash) -- 2.26.2