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

zopefoundation / Products.PythonScripts / 16248875199

17 Mar 2025 07:48AM CUT coverage: 86.279%. Remained the same
16248875199

push

github

web-flow
Update Python version support. (#68)

* Drop support for Python 3.8.

* Configuring for zope-product

* Update Python version support.

84 of 144 branches covered (58.33%)

Branch coverage included in aggregate %.

941 of 1044 relevant lines covered (90.13%)

0.9 hits per line

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

55.36
/src/Products/PythonScripts/standard.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

14
"""Python Scripts standard utility module
15

16
This module provides helpful functions and classes for use in Python
17
Scripts.  It can be accessed from Python with the statement
18
"import Products.PythonScripts.standard"
19
"""
20

21
from urllib.parse import urlencode  # NOQA
1✔
22

23
from AccessControl.SecurityInfo import ModuleSecurityInfo
1✔
24
from AccessControl.SecurityManagement import getSecurityManager
1✔
25
from App.special_dtml import HTML
1✔
26
from DocumentTemplate.DT_Var import dollars_and_cents  # NOQA
1✔
27
from DocumentTemplate.DT_Var import html_quote  # NOQA
1✔
28
from DocumentTemplate.DT_Var import newline_to_br  # NOQA
1✔
29
from DocumentTemplate.DT_Var import restructured_text  # NOQA
1✔
30
from DocumentTemplate.DT_Var import special_formats  # NOQA
1✔
31
from DocumentTemplate.DT_Var import sql_quote  # NOQA
1✔
32
from DocumentTemplate.DT_Var import structured_text  # NOQA
1✔
33
from DocumentTemplate.DT_Var import thousands_commas  # NOQA
1✔
34
from DocumentTemplate.DT_Var import url_quote  # NOQA
1✔
35
from DocumentTemplate.DT_Var import url_quote_plus  # NOQA
1✔
36
from DocumentTemplate.DT_Var import url_unquote  # NOQA
1✔
37
from DocumentTemplate.DT_Var import url_unquote_plus  # NOQA
1✔
38
from DocumentTemplate.DT_Var import whole_dollars  # NOQA
1✔
39
from DocumentTemplate.security import RestrictedDTML
1✔
40
from ZPublisher.HTTPRequest import record
1✔
41

42

43
security = ModuleSecurityInfo('Products.PythonScripts.standard')
1✔
44

45
security.declarePublic(  # noqa: D001
1✔
46
    'special_formats',
47
    'whole_dollars',
48
    'dollars_and_cents',
49
    'structured_text',
50
    'restructured_text',
51
    'sql_quote',
52
    'html_quote',
53
    'url_quote',
54
    'url_quote_plus',
55
    'newline_to_br',
56
    'thousands_commas',
57
    'url_unquote',
58
    'url_unquote_plus',
59
    'urlencode',
60
    'DTML',
61
    'Object',
62
)
63

64

65
class DTML(RestrictedDTML, HTML):
1✔
66
    """DTML objects are DocumentTemplate.HTML objects that allow
67
       dynamic, temporary creation of restricted DTML."""
68

69
    def __call__(self, client=None, REQUEST={}, RESPONSE=None, **kw):
1✔
70
        """Render the DTML given a client object, REQUEST mapping,
71
        Response, and key word arguments."""
72

73
        security = getSecurityManager()
×
74
        security.addContext(self)
×
75
        try:
×
76
            return HTML.__call__(self, client, REQUEST, **kw)
×
77
        finally:
78
            security.removeContext(self)
×
79

80

81
# We don't expose classes directly to restricted code
82
class _Object(record):
1✔
83
    _guarded_writes = 1
1✔
84

85
    def __init__(self, **kw):
1✔
86
        self.update(kw)
×
87

88
    def __setitem__(self, key, value):
1✔
89
        key = str(key)
×
90
        if key.startswith('_'):
×
91
            raise ValueError('Object key %r is invalid. '
×
92
                             'Keys may not begin with an underscore.' % key)
93
        self.__dict__[key] = value
×
94

95
    def update(self, d):
1✔
96
        for key in d.keys():
×
97
            # Ignore invalid keys, rather than raising an exception.
98
            try:
×
99
                skey = str(key)
×
100
            except Exception:
×
101
                continue
×
102
            if skey == key and not skey.startswith('_'):
×
103
                self.__dict__[skey] = d[key]
×
104

105
    def __hash__(self):
1✔
106
        return id(self)
×
107

108

109
def Object(**kw):
1✔
110
    return _Object(**kw)
×
111

112

113
security.apply(globals())
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