• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / AccessControl / 3742027669

pending completion
3742027669

push

github

Michael Howitz
Drop support for Python 2.7 up to 3.6.

934 of 1458 branches covered (64.06%)

Branch coverage included in aggregate %.

100 of 105 new or added lines in 26 files covered. (95.24%)

4982 of 5839 relevant lines covered (85.32%)

4.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/AccessControl/class_init.py
1
##############################################################################
2
#
3
# Copyright (c) 2002 Zope Foundation and Contributors.
4
#
5
# This software is subject to the provisions of the Zope Public License,
6
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
7
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10
# FOR A PARTICULAR PURPOSE.
11
#
12
##############################################################################
13
"""Class initialization.
5✔
14
"""
15

16
import logging
5✔
17

18
from AccessControl.Permission import ApplicationDefaultPermissions  # NOQA
5✔
19

20

21
def InitializeClass(self):
5✔
22
    from AccessControl.Permission import registerPermissions
5✔
23
    from AccessControl.PermissionRole import PermissionRole
5✔
24

25
    dict = self.__dict__
5✔
26
    have = dict.__contains__
5✔
27
    ft = type(InitializeClass)
5✔
28
    dict_items = list(dict.items())
5✔
29

30
    for name, v in dict_items:
5✔
31
        if getattr(v, '_need__name__', 0):
5!
32
            d = v.__dict__
×
33
            oldname = d.get('__name__', '')
×
34
            if d.get('_implicit__name__', 0):
×
35
                # Already supplied a name.
36
                if name != oldname:
×
37
                    # Tried to implicitly assign a different name!
38
                    try:
×
NEW
39
                        classname = '{}.{}'.format(
×
40
                            self.__module__, self.__name__)
41
                    except AttributeError:
×
42
                        classname = repr(self)
×
43
                    logging.getLogger("Init").warning(
×
44
                        'Ambiguous name for method of %s: %r != %r',
45
                        classname, d['__name__'], name)
46
            else:
47
                # Supply a name implicitly so that the method can
48
                # find the security assertions on its container.
49
                v._implicit__name__ = 1
×
50
                v.__name__ = name
×
51
            if name == 'manage' or name[:7] == 'manage_':
×
52
                name = name + '__roles__'
×
53
                if not have(name):
×
54
                    setattr(self, name, ('Manager',))
×
55
        elif name == 'manage' or name[:7] == 'manage_' and isinstance(v, ft):
5✔
56
            name = name + '__roles__'
5✔
57
            if not have(name):
5!
58
                setattr(self, name, ('Manager',))
5✔
59

60
    # Look for a SecurityInfo object on the class. If found, call its
61
    # apply() method to generate __ac_permissions__ for the class. We
62
    # delete the SecurityInfo from the class dict after it has been
63
    # applied out of paranoia.
64
    for key, value in dict_items:
5✔
65
        if hasattr(value, '__security_info__'):
5✔
66
            security_info = value
5✔
67
            security_info.apply(self)
5✔
68
            delattr(self, key)
5✔
69
            break
5✔
70

71
    if '__ac_permissions__' in self.__dict__:
5✔
72
        registerPermissions(self.__ac_permissions__)
5✔
73
        for acp in self.__ac_permissions__:
5✔
74
            pname, mnames = acp[:2]
5✔
75
            if len(acp) > 2:
5✔
76
                roles = acp[2]
5✔
77
                pr = PermissionRole(pname, roles)
5✔
78
            else:
79
                pr = PermissionRole(pname)
5✔
80
            for mname in mnames:
5✔
81
                setattr(self, mname + '__roles__', pr)
5✔
82
                if mname and \
5!
83
                   mname not in ('context', 'request') and \
84
                   not hasattr(self, mname):
85
                    # don't complain about context or request, as they are
86
                    # frequently not available as class attributes
87
                    logging.getLogger("Init").warning(
×
88
                        "Class %s.%s has a security declaration for "
89
                        "nonexistent method %r", self.__module__,
90
                        self.__name__, mname)
91

92

93
default__class_init__ = InitializeClass  # BBB: old name
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc