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

zopefoundation / Products.PluggableAuthService / 5303493172

pending completion
5303493172

push

github

web-flow
Drop support for Python 2.7, 3.5, 3.6. (#116)

* Drop zserver extra in setup.py. Thus dropping FTP support.
* Drop support for Zope < 5.
Co-authored-by: Jens Vagelpohl <jens@plyp.com>

1288 of 1745 branches covered (73.81%)

Branch coverage included in aggregate %.

127 of 127 new or added lines in 30 files covered. (100.0%)

9619 of 10349 relevant lines covered (92.95%)

0.93 hits per line

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

87.39
/src/Products/PluggableAuthService/UserPropertySheet.py
1
##############################################################################
2
#
3
# Copyright (c) 2001 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
7
# distribution.
8
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
9
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
11
# FOR A PARTICULAR PURPOSE.
12
#
13
##############################################################################
14
""" Represent a group of properties about a user.
1✔
15
"""
16

17

18
from DateTime.DateTime import DateTime
1✔
19
from OFS.Image import Image
1✔
20

21
from .interfaces.propertysheets import IPropertySheet
1✔
22
from .utils import classImplements
1✔
23

24

25
StringTypes = (str, str)
1✔
26

27

28
def _guessSchema(kw):
1✔
29

30
    schema = []
1✔
31
    for k, v in kw.items():
1✔
32

33
        ptype = 'string'
1✔
34

35
        if isinstance(v, (bytes, str)):
1✔
36
            ptype = 'string'
1✔
37

38
        elif type(v) == int:
1✔
39
            # bool is a subsclass of int, so we cannot use isinstance
40
            ptype = 'int'
1✔
41

42
        elif isinstance(v, float):
1✔
43
            ptype = 'float'
1✔
44

45
        elif isinstance(v, bool):
1✔
46
            ptype = 'boolean'
1✔
47

48
        elif isinstance(v, (tuple, list)):
1✔
49

50
            if v and not isinstance(v[0], (bytes, str)):
1!
51
                raise ValueError('Property %s: sequence items not strings' % k)
×
52

53
            ptype = 'lines'
1✔
54

55
        elif isinstance(v, DateTime):
1✔
56
            ptype = 'date'
1✔
57

58
        elif isinstance(v, type):
1!
59

60
            if isinstance(v, DateTime):
×
61
                ptype = 'date'
×
62
            else:
63
                raise ValueError('Property %s: unknown class' % k)
×
64

65
        elif isinstance(v, Image):
1!
66
            ptype = 'image'
1✔
67

68
        elif not isinstance(v, (bytes, str)):
×
69
            raise ValueError('Property %s: unknown type' % k)
×
70

71
        schema.append((k, ptype))
1✔
72

73
    return schema
1✔
74

75

76
class UserPropertySheet:
1✔
77

78
    """ Model a single, read-only set of properties about a user.
79

80
    o Values for the sheet are passed as keyword args to the c'tor.
81

82
    o The schema for the sheet may be passed into the c'tor explicitly
83
      as a sequence of (id, type) tuples;  if not passed, the c'tor will
84
      guess the schema from the keyword args.
85
    """
86

87
    def __init__(self, id, schema=None, **kw):
1✔
88

89
        self._id = id
1✔
90

91
        if schema is None:
1✔
92
            schema = _guessSchema(kw)
1✔
93

94
        self._schema = tuple(schema)
1✔
95
        self._properties = {}
1✔
96

97
        for id, ptype in schema:
1✔
98

99
            value = kw.get(id)
1✔
100

101
            if ptype == 'lines':
1✔
102
                if value is not None:
1✔
103
                    value = tuple(value)
1✔
104

105
            self._properties[id] = value
1✔
106

107
    #
108
    #   IPropertySheet implementation
109
    #
110
    def getId(self):
1✔
111
        """ See IPropertySheet.
112
        """
113
        return self._id
1✔
114

115
    def hasProperty(self, id):
1✔
116
        """ See IPropertySheet.
117
        """
118
        return id in self.propertyIds()
1✔
119

120
    def getProperty(self, id, default=None):
1✔
121
        """ See IPropertySheet.
122
        """
123
        return self._properties.get(id, default)
1✔
124

125
    def getPropertyType(self, id):
1✔
126
        """ See IPropertySheet.
127
        """
128
        found = [x[1] for x in self._schema if x[0] == id]
1✔
129

130
        return found and found[0] or None
1✔
131

132
    def propertyInfo(self, id):
1✔
133
        """ See IPropertySheet.
134
        """
135
        for schema_id, ptype in self._schema:
1!
136

137
            if schema_id == id:
1✔
138
                return {'id': id, 'type': ptype, 'mode': ''}
1✔
139

140
        return None
×
141

142
    def propertyMap(self):
1✔
143
        """ See IPropertySheet.
144
        """
145
        result = []
1✔
146

147
        for id, ptype in self._schema:
1✔
148
            result.append({'id': id, 'type': ptype, 'mode': ''})
1✔
149

150
        return tuple(result)
1✔
151

152
    def propertyIds(self):
1✔
153
        """ See IPropertySheet.
154
        """
155
        return [x[0] for x in self._schema]
1✔
156

157
    def propertyValues(self):
1✔
158
        """ See IPropertySheet.
159
        """
160
        return [self._properties.get(x) for x in self.propertyIds()]
1✔
161

162
    def propertyItems(self):
1✔
163
        """ See IPropertySheet.
164
        """
165
        return [(x, self._properties.get(x)) for x in self.propertyIds()]
1✔
166

167

168
classImplements(UserPropertySheet, IPropertySheet)
1✔
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

© 2025 Coveralls, Inc