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

zopefoundation / Products.CMFCore / 6246931310

20 Sep 2023 09:54AM UTC coverage: 86.008% (-0.3%) from 86.266%
6246931310

Pull #131

github

mauritsvanrees
gha: don't need setup-python on 27 as we use the 27 container.
Pull Request #131: Make decodeFolderFilter and encodeFolderFilter non-public.

2466 of 3689 branches covered (0.0%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

17297 of 19289 relevant lines covered (89.67%)

0.9 hits per line

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

84.95
/src/Products/CMFCore/FSPropertiesObject.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 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
""" Customizable properties that come from the filesystem.
1✔
14
"""
15

16
from AccessControl.class_init import InitializeClass
1✔
17
from AccessControl.SecurityInfo import ClassSecurityInfo
1✔
18
from Acquisition import ImplicitAcquisitionWrapper
1✔
19
from App.config import getConfiguration
1✔
20
from App.special_dtml import DTMLFile
1✔
21
from OFS.Folder import Folder
1✔
22
from OFS.PropertyManager import PropertyManager
1✔
23
from ZPublisher.Converters import get_converter
1✔
24

25
from .DirectoryView import registerFileExtension
1✔
26
from .DirectoryView import registerMetaType
1✔
27
from .FSObject import FSObject
1✔
28
from .permissions import ViewManagementScreens
1✔
29
from .utils import _dtmldir
1✔
30

31

32
class FSPropertiesObject(FSObject, PropertyManager):
1✔
33

34
    """FSPropertiesObjects simply hold properties."""
35

36
    meta_type = 'Filesystem Properties Object'
1✔
37

38
    manage_options = ({'label': 'Customize', 'action': 'manage_main'},)
1✔
39

40
    security = ClassSecurityInfo()
1✔
41

42
    security.declareProtected(ViewManagementScreens,  # NOQA: flake8: D001
1✔
43
                              'manage_main')
44
    manage_main = DTMLFile('custprops', _dtmldir)
1✔
45

46
    # Declare all (inherited) mutating methods private.
47
    security.declarePrivate('manage_addProperty')  # NOQA: flake8: D001
1✔
48
    security.declarePrivate('manage_editProperties')  # NOQA: flake8: D001
1✔
49
    security.declarePrivate('manage_delProperties')  # NOQA: flake8: D001
1✔
50
    security.declarePrivate('manage_changeProperties')  # NOQA: flake8: D001
1✔
51
    security.declarePrivate('manage_propertiesForm')  # NOQA: flake8: D001
1✔
52
    security.declarePrivate('manage_propertyTypeForm')  # NOQA: flake8: D001
1✔
53
    security.declarePrivate('manage_changePropertyTypes')  # NOQA: flake8: D001
1✔
54

55
    @security.protected(ViewManagementScreens)
1✔
56
    def manage_doCustomize(self, folder_path, RESPONSE=None, root=None,
1✔
57
                           obj=None):
58
        """Makes a ZODB Based clone with the same data.
59

60
        Calls _createZODBClone for the actual work.
61
        """
62
        # Overridden here to provide a different redirect target.
63

64
        FSObject.manage_doCustomize(self, folder_path, RESPONSE, root=root,
1✔
65
                                    obj=obj)
66

67
        if RESPONSE is not None:
1!
68
            if folder_path == '.':
×
69
                fpath = ()
×
70
            else:
71
                fpath = tuple(folder_path.split('/'))
×
72
            folder = self.restrictedTraverse(fpath)
×
73
            RESPONSE.redirect('%s/%s/manage_propertiesForm' % (
×
74
                folder.absolute_url(), self.getId()))
75

76
    def _createZODBClone(self):
1✔
77
        """Create a ZODB (editable) equivalent of this object."""
78
        # Create a Folder to hold the properties.
79
        obj = Folder()
1✔
80
        obj.id = self.getId()
1✔
81
        map = []
1✔
82
        for p in self._properties:
1✔
83
            # This should be secure since the properties come
84
            # from the filesystem.
85
            setattr(obj, p['id'], getattr(self, p['id']))
1✔
86
            map.append({'id': p['id'],
1✔
87
                        'type': p['type'],
88
                        'mode': 'wd'})
89
        obj._properties = tuple(map)
1✔
90

91
        return obj
1✔
92

93
    def _readFile(self, reparse):
1✔
94
        """Read the data from the filesystem.
95
        """
96
        file = open(self._filepath, 'r')  # not 'rb', as this is a text file!
1✔
97
        try:
1✔
98
            lines = file.readlines()
1✔
99
        finally:
100
            file.close()
1✔
101

102
        map = []
1✔
103
        lino = 0
1✔
104

105
        for line in lines:
1✔
106

107
            lino = lino + 1
1✔
108
            line = line.strip()
1✔
109

110
            if not line or line[0] == '#':
1!
111
                continue
×
112

113
            try:
1✔
114
                propname, proptv = line.split(':', 1)
1✔
115
                # ??? multi-line properties?
116
                proptype, propvstr = proptv.split('=', 1)
1✔
117
                propname = propname.strip()
1✔
118
                proptype = proptype.strip()
1✔
119
                propvstr = propvstr.strip()
1✔
120
                converter = get_converter(proptype, lambda x: x)
1!
121
                propvalue = converter(propvstr)
1✔
122
                # Should be safe since we're loading from
123
                # the filesystem.
124
                setattr(self, propname, propvalue)
1✔
125
                map.append({'id': propname,
1✔
126
                            'type': proptype,
127
                            'mode': '',
128
                            'default_value': propvalue,
129
                            })
130
            except Exception:
×
131
                raise ValueError('Error processing line %s of %s:\n%s'
×
132
                                 % (lino, self._filepath, line))
133
        self._properties = tuple(map)
1✔
134

135
    if getConfiguration().debug_mode:
1!
136
        # Provide an opportunity to update the properties.
137
        def __of__(self, parent):
1✔
138
            self = ImplicitAcquisitionWrapper(self, parent)
1✔
139
            self._updateFromFS()
1✔
140
            return self
1✔
141

142

143
InitializeClass(FSPropertiesObject)
1✔
144

145
registerFileExtension('props', FSPropertiesObject)
1✔
146
registerMetaType('Properties Object', FSPropertiesObject)
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