Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mikolaï Krol
erp5
Commits
c0379cfb
Commit
c0379cfb
authored
Jan 27, 2020
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
patches/Restricted: allow collections.Counter
parent
426ff95b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
0 deletions
+23
-0
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testRestrictedPythonSecurity.py
...rtal_components/test.erp5.testRestrictedPythonSecurity.py
+13
-0
product/ERP5Type/patches/Restricted.py
product/ERP5Type/patches/Restricted.py
+10
-0
No files found.
bt5/erp5_core_test/TestTemplateItem/portal_components/test.erp5.testRestrictedPythonSecurity.py
View file @
c0379cfb
...
...
@@ -336,3 +336,16 @@ class TestRestrictedPythonSecurity(ERP5TypeTestCase):
calendar.HTMLCalendar().getfirstweekday()
'''
),
)
def
test_collections_Counter
(
self
):
self
.
createAndRunScript
(
textwrap
.
dedent
(
'''
\
from collections import Counter
c = Counter(["a", "b"])
c["a"] = c["a"] + 1
del c["b"]
c.update({"a": 1})
return c.most_common(1)
'''
),
expected
=
[(
'a'
,
3
)]
)
product/ERP5Type/patches/Restricted.py
View file @
c0379cfb
...
...
@@ -11,6 +11,7 @@
#
##############################################################################
import
copy
import
sys
import
types
...
...
@@ -187,6 +188,9 @@ ModuleSecurityInfo('collections').declarePublic('OrderedDict')
from
collections
import
defaultdict
ModuleSecurityInfo
(
'collections'
).
declarePublic
(
'defaultdict'
)
from
collections
import
Counter
ModuleSecurityInfo
(
'collections'
).
declarePublic
(
'Counter'
)
from
AccessControl.ZopeGuards
import
_dict_white_list
# Attributes cannot be set on defaultdict, thus modify 'safetype' dict
...
...
@@ -201,6 +205,12 @@ ContainerAssertions[OrderedDict] = _check_access_wrapper(OrderedDict, _dict_whit
OrderedDict
.
__guarded_setitem__
=
OrderedDict
.
__setitem__
.
__func__
OrderedDict
.
__guarded_delitem__
=
OrderedDict
.
__delitem__
.
__func__
_counter_white_list
=
copy
.
copy
(
_dict_white_list
)
_counter_white_list
[
'most_common'
]
=
1
ContainerAssertions
[
Counter
]
=
_check_access_wrapper
(
Counter
,
_counter_white_list
)
Counter
.
__guarded_setitem__
=
dict
.
__setitem__
Counter
.
__guarded_delitem__
=
dict
.
__delitem__
# given as example in Products.PythonScripts.module_access_examples
allow_module
(
'base64'
)
allow_module
(
'binascii'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment