Projet

Général

Profil

0009-misc-fix-consider-using-dict-items-pylint-error-5698.patch

Valentin Deniaud, 21 septembre 2021 17:09

Télécharger (8,22 ko)

Voir les différences:

Subject: [PATCH 09/59] misc: fix consider-using-dict-items pylint error
 (#56982)

 src/authentic2/a2_rbac/management.py          |  8 ++++----
 src/authentic2/backends/ldap_backend.py       | 20 +++++++++----------
 src/authentic2/custom_user/apps.py            |  4 ++--
 .../management/commands/check-and-repair.py   |  4 ++--
 src/authentic2/utils/misc.py                  | 12 +++++------
 src/authentic2_auth_fc/utils.py               |  2 +-
 6 files changed, 25 insertions(+), 25 deletions(-)
src/authentic2/a2_rbac/management.py
33 33
    else:
34 34
        ou_admin_role = ou.get_admin_role()
35 35

  
36
    for key in MANAGED_CT:
36
    for key, info in MANAGED_CT.items():
37 37
        ct = ContentType.objects.get_by_natural_key(key[0], key[1])
38 38
        model_class = ct.model_class()
39 39
        ou_model = get_fk_model(model_class, 'ou')
40 40
        # do not create scoped admin roles if the model is not scopable
41 41
        if not ou_model:
42 42
            continue
43
        name = str(MANAGED_CT[key]['name'])
43
        name = str(info['name'])
44 44
        slug = '_a2-' + slugify(name)
45
        scoped_name = str(MANAGED_CT[key]['scoped_name'])
45
        scoped_name = str(info['scoped_name'])
46 46
        name = scoped_name.format(ou=ou)
47 47
        ou_slug = slug + '-' + ou.slug
48 48
        if app_settings.MANAGED_CONTENT_TYPES == ():
......
56 56
            ou_ct_admin_role.add_child(ou_admin_role)
57 57
        else:
58 58
            ou_ct_admin_role.remove_child(ou_admin_role)
59
        if MANAGED_CT[key].get('must_view_user'):
59
        if info.get('must_view_user'):
60 60
            ou_ct_admin_role.permissions.add(utils.get_view_user_perm(ou))
61 61
        ou_ct_admin_role.permissions.add(utils.get_search_ou_perm(ou))
62 62

  
src/authentic2/backends/ldap_backend.py
925 925
                user_attributes[to_user] = ''
926 926
            else:
927 927
                user_attributes[to_user] = attributes[from_ldap][0]
928
        for name in user_attributes:
928
        for name, new_value in user_attributes.items():
929 929
            value = getattr(user.attributes, name, None)
930
            if value != user_attributes[name]:
930
            if value != new_value:
931 931
                if not user.pk:
932 932
                    user.save()
933
                setattr(user.attributes, name, user_attributes[name])
933
                setattr(user.attributes, name, new_value)
934 934
                user._changed = True
935 935

  
936 936
    def populate_admin_flags_by_group(self, user, block, group_dns):
......
1825 1825
            if i in block and isinstance(block[i], str):
1826 1826
                block[i] = (block[i],)
1827 1827

  
1828
        for d in cls._DEFAULTS:
1828
        for d, value in cls._DEFAULTS.items():
1829 1829
            if d not in block:
1830
                block[d] = cls._DEFAULTS[d]
1830
                block[d] = value
1831 1831
                if d == 'user_filter' and app_settings.A2_ACCEPT_EMAIL_AUTHENTICATION:
1832 1832
                    block[d] = '(|(mail=%s)(uid=%s))'
1833 1833
            else:
1834
                if isinstance(cls._DEFAULTS[d], str):
1834
                if isinstance(value, str):
1835 1835
                    if not isinstance(block[d], str):
1836 1836
                        raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: attribute %r must be a string' % d)
1837 1837
                    try:
1838 1838
                        block[d] = force_text(block[d])
1839 1839
                    except UnicodeEncodeError:
1840 1840
                        raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: attribute %r must be a string' % d)
1841
                if isinstance(cls._DEFAULTS[d], bool) and not isinstance(block[d], bool):
1841
                if isinstance(value, bool) and not isinstance(block[d], bool):
1842 1842
                    raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: attribute %r must be a boolean' % d)
1843
                if isinstance(cls._DEFAULTS[d], (list, tuple)) and not isinstance(block[d], (list, tuple)):
1843
                if isinstance(value, (list, tuple)) and not isinstance(block[d], (list, tuple)):
1844 1844
                    raise ImproperlyConfigured(
1845 1845
                        'LDAP_AUTH_SETTINGS: attribute %r must be a list or a tuple' % d
1846 1846
                    )
1847
                if isinstance(cls._DEFAULTS[d], dict) and not isinstance(block[d], dict):
1847
                if isinstance(value, dict) and not isinstance(block[d], dict):
1848 1848
                    raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: attribute %r must be a dictionary' % d)
1849
                if not isinstance(cls._DEFAULTS[d], bool) and d in cls._REQUIRED and not block[d]:
1849
                if not isinstance(value, bool) and d in cls._REQUIRED and not block[d]:
1850 1850
                    raise ImproperlyConfigured('LDAP_AUTH_SETTINGS: attribute %r is required but is empty')
1851 1851
                # force_bytes all strings in iterable or dict
1852 1852
                if isinstance(block[d], (list, tuple, dict)):
src/authentic2/custom_user/apps.py
75 75

  
76 76
        serialize = get_kind('string').get('serialize')
77 77
        for user in User.objects.all():
78
            for attr_name in attrs:
78
            for attr_name, value in attrs.items():
79 79
                av, created = AttributeValue.objects.get_or_create(
80 80
                    content_type=content_type,
81 81
                    object_id=user.id,
82
                    attribute=attrs[attr_name],
82
                    attribute=value,
83 83
                    defaults={
84 84
                        'multiple': False,
85 85
                        'verified': False,
src/authentic2/management/commands/check-and-repair.py
337 337
                roles_to_fix[ou] = wrong_ou_roles
338 338
        if roles_to_fix and self.do_repair():
339 339
            self.notice('Changing ou of admin roles...', ending=' ')
340
            for ou in roles_to_fix:
341
                roles_to_fix[ou].update(ou=ou)
340
            for ou, role in roles_to_fix.items():
341
                role.update(ou=ou)
342 342
            self.success('DONE!')
343 343

  
344 344
    def check_manager_of_roles(self):
src/authentic2/utils/misc.py
76 76

  
77 77
    def collect(self):
78 78
        """Clear cache of results which have timed out"""
79
        for func in self._caches:
80
            cache = {}
81
            for key in self._caches[func]:
82
                if (time.time() - self._caches[func][key][1]) < self._timeouts[func]:
83
                    cache[key] = self._caches[func][key]
84
            self._caches[func] = cache
79
        for func, cache in self._caches.items():
80
            updated_cache = {}
81
            for key in cache:
82
                if (time.time() - cache[key][1]) < self._timeouts[func]:
83
                    updated_cache[key] = cache[key]
84
            cache = updated_cache
85 85

  
86 86
    def __call__(self, f):
87 87
        self.cache = self._caches[f] = {}
src/authentic2_auth_fc/utils.py
195 195
        s = super().__str__()
196 196
        if self.details:
197 197
            s += ' ('
198
            s += ' '.join('%s=%r' % (key, self.details[key]) for key in self.details)
198
            s += ' '.join('%s=%r' % (k, v) for k, v in self.details.items())
199 199
            s += ')'
200 200
        return s
201 201

  
202
-