RestrictedPython 7.1__tar.gz → 7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {RestrictedPython-7.1 → RestrictedPython-7.2}/CHANGES.rst +10 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/PKG-INFO +11 -1
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/usage/basic_usage.rst +56 -0
- RestrictedPython-7.2/setup.py +74 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/Guards.py +2 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/transformer.py +4 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/PKG-INFO +11 -1
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_Guards.py +36 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_compile.py +17 -6
- RestrictedPython-7.1/setup.py +0 -79
- {RestrictedPython-7.1 → RestrictedPython-7.2}/.readthedocs.yaml +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/CONTRIBUTING.md +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/COPYRIGHT.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/LICENSE.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/MANIFEST.in +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/README.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/buildout.cfg +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/constraints.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/Makefile +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/changes.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/conf.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_10.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_11.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_12.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_6.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_7.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_8.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/ast/python3_9.ast +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/changes_from310to311.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/changes_from311to312.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/changes_from36to37.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/changes_from37to38.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/changes_from38to39.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/changes_from39to310.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/contributing/index.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/idea.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/index.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/install/index.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/logo.jpg +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/make.bat +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/requirements.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/roadmap/index.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/upgrade_dependencies/index.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/usage/api.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/usage/framework_usage.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/usage/index.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/docs/usage/policy.rst +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/setup.cfg +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/Eval.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/Limits.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/PrintCollector.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/Utilities.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/__init__.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/_compat.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython/compile.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/SOURCES.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/dependency_links.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/not-zip-safe +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/requires.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/top_level.txt +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/__init__.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/builtins/test_limits.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/builtins/test_utilities.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/helper.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_NamedExpr.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_Utilities.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_compile_restricted_function.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_eval.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_imports.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_iterating_over_dict_items.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/test_print_function.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_arithmetic_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_bit_wise_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_bool_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_comparison_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_identity_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_logical_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_unary_operators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_assert.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_assign.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_async.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_attribute.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_augassign.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_base_types.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_breakpoint.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_call.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_classdef.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_comparators.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_conditional.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_dict_comprehension.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_eval_exec.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_fstring.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_functiondef.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_generic.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_global_local.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_import.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_inspect.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_iterator.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_lambda.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_loop.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_name.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_slice.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_subscript.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_try.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_with_stmt.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/test_yield.py +0 -0
- {RestrictedPython-7.1 → RestrictedPython-7.2}/tox.ini +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
Changes
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
+
7.2 (2024-08-02)
|
|
5
|
+
----------------
|
|
6
|
+
|
|
7
|
+
- Remove unneeded setuptools fossils that may cause installation problems
|
|
8
|
+
with recent setuptools versions.
|
|
9
|
+
- Add support for single mode statements / execution.
|
|
10
|
+
- Fix a potential breakout capability in the provided ``safer_getattr`` method
|
|
11
|
+
that is part of the ``safer_builtins``.
|
|
12
|
+
|
|
13
|
+
|
|
4
14
|
7.1 (2024-03-14)
|
|
5
15
|
----------------
|
|
6
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: RestrictedPython
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.2
|
|
4
4
|
Summary: RestrictedPython is a defined subset of the Python language which allows to provide a program input into a trusted environment.
|
|
5
5
|
Home-page: https://github.com/zopefoundation/RestrictedPython
|
|
6
6
|
Author: Zope Foundation and Contributors
|
|
@@ -124,6 +124,16 @@ the documentation `Contributing page
|
|
|
124
124
|
Changes
|
|
125
125
|
=======
|
|
126
126
|
|
|
127
|
+
7.2 (2024-08-02)
|
|
128
|
+
----------------
|
|
129
|
+
|
|
130
|
+
- Remove unneeded setuptools fossils that may cause installation problems
|
|
131
|
+
with recent setuptools versions.
|
|
132
|
+
- Add support for single mode statements / execution.
|
|
133
|
+
- Fix a potential breakout capability in the provided ``safer_getattr`` method
|
|
134
|
+
that is part of the ``safer_builtins``.
|
|
135
|
+
|
|
136
|
+
|
|
127
137
|
7.1 (2024-03-14)
|
|
128
138
|
----------------
|
|
129
139
|
|
|
@@ -94,6 +94,62 @@ One common advanced usage would be to define an own restricted builtin dictionar
|
|
|
94
94
|
|
|
95
95
|
There is a shortcut for ``{'__builtins__': safe_builtins}`` named ``safe_globals`` which can be imported from ``RestrictedPython``.
|
|
96
96
|
|
|
97
|
+
Other Usages
|
|
98
|
+
------------
|
|
99
|
+
|
|
100
|
+
RestrictedPython has similar to normal Python multiple modes:
|
|
101
|
+
|
|
102
|
+
* exec
|
|
103
|
+
* eval
|
|
104
|
+
* single
|
|
105
|
+
* function
|
|
106
|
+
|
|
107
|
+
you can use it by:
|
|
108
|
+
|
|
109
|
+
.. testcode::
|
|
110
|
+
|
|
111
|
+
from RestrictedPython import compile_restricted
|
|
112
|
+
|
|
113
|
+
source_code = """
|
|
114
|
+
def do_something():
|
|
115
|
+
pass
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
byte_code = compile_restricted(
|
|
119
|
+
source_code,
|
|
120
|
+
filename='<inline code>',
|
|
121
|
+
mode='exec'
|
|
122
|
+
)
|
|
123
|
+
exec(byte_code)
|
|
124
|
+
do_something()
|
|
125
|
+
|
|
126
|
+
.. testcode::
|
|
127
|
+
|
|
128
|
+
from RestrictedPython import compile_restricted
|
|
129
|
+
|
|
130
|
+
byte_code = compile_restricted(
|
|
131
|
+
"2 + 2",
|
|
132
|
+
filename='<inline code>',
|
|
133
|
+
mode='eval'
|
|
134
|
+
)
|
|
135
|
+
eval(byte_code)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
.. testcode:: single
|
|
139
|
+
|
|
140
|
+
from RestrictedPython import compile_restricted
|
|
141
|
+
|
|
142
|
+
byte_code = compile_restricted(
|
|
143
|
+
"2 + 2",
|
|
144
|
+
filename='<inline code>',
|
|
145
|
+
mode='single'
|
|
146
|
+
)
|
|
147
|
+
exec(byte_code)
|
|
148
|
+
|
|
149
|
+
.. testoutput:: single
|
|
150
|
+
|
|
151
|
+
4
|
|
152
|
+
|
|
97
153
|
Necessary setup
|
|
98
154
|
---------------
|
|
99
155
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
##############################################################################
|
|
2
|
+
#
|
|
3
|
+
# Copyright (c) 2006 Zope Foundation and Contributors.
|
|
4
|
+
# All Rights Reserved.
|
|
5
|
+
#
|
|
6
|
+
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
+
# Version 2.1 (ZPL). A copy of the ZPL should accompany this 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
|
+
"""Setup for RestrictedPython package"""
|
|
15
|
+
|
|
16
|
+
import os
|
|
17
|
+
|
|
18
|
+
from setuptools import find_packages
|
|
19
|
+
from setuptools import setup
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def read(*rnames):
|
|
23
|
+
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
|
|
24
|
+
return f.read()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
tests_require = [
|
|
28
|
+
'pytest',
|
|
29
|
+
'pytest-mock',
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
setup(name='RestrictedPython',
|
|
33
|
+
version='7.2',
|
|
34
|
+
url='https://github.com/zopefoundation/RestrictedPython',
|
|
35
|
+
license='ZPL 2.1',
|
|
36
|
+
description=(
|
|
37
|
+
'RestrictedPython is a defined subset of the Python language which '
|
|
38
|
+
'allows to provide a program input into a trusted environment.'),
|
|
39
|
+
long_description=read('README.rst') + '\n' + read('CHANGES.rst'),
|
|
40
|
+
long_description_content_type='text/x-rst',
|
|
41
|
+
classifiers=[
|
|
42
|
+
'Development Status :: 6 - Mature',
|
|
43
|
+
'License :: OSI Approved :: Zope Public License',
|
|
44
|
+
'Programming Language :: Python',
|
|
45
|
+
'Operating System :: OS Independent',
|
|
46
|
+
'Programming Language :: Python :: 3',
|
|
47
|
+
'Programming Language :: Python :: 3.7',
|
|
48
|
+
'Programming Language :: Python :: 3.8',
|
|
49
|
+
'Programming Language :: Python :: 3.9',
|
|
50
|
+
'Programming Language :: Python :: 3.10',
|
|
51
|
+
'Programming Language :: Python :: 3.11',
|
|
52
|
+
'Programming Language :: Python :: 3.12',
|
|
53
|
+
'Programming Language :: Python :: Implementation :: CPython',
|
|
54
|
+
'Topic :: Security',
|
|
55
|
+
],
|
|
56
|
+
keywords='restricted execution security untrusted code',
|
|
57
|
+
author='Zope Foundation and Contributors',
|
|
58
|
+
author_email='zope-dev@zope.org',
|
|
59
|
+
project_urls={
|
|
60
|
+
"Documentation": "https://restrictedpython.readthedocs.io/",
|
|
61
|
+
"Source": "https://github.com/zopefoundation/RestrictedPython",
|
|
62
|
+
"Tracker":
|
|
63
|
+
"https://github.com/zopefoundation/RestrictedPython/issues",
|
|
64
|
+
},
|
|
65
|
+
packages=find_packages('src'),
|
|
66
|
+
package_dir={'': 'src'},
|
|
67
|
+
install_requires=[],
|
|
68
|
+
python_requires=">=3.7, <3.13",
|
|
69
|
+
extras_require={
|
|
70
|
+
'test': tests_require,
|
|
71
|
+
'docs': ['Sphinx', 'sphinx_rtd_theme'],
|
|
72
|
+
},
|
|
73
|
+
include_package_data=True,
|
|
74
|
+
zip_safe=False)
|
|
@@ -246,6 +246,8 @@ def safer_getattr(object, name, default=None, getattr=getattr):
|
|
|
246
246
|
http://lucumr.pocoo.org/2016/12/29/careful-with-str-format/
|
|
247
247
|
|
|
248
248
|
"""
|
|
249
|
+
if type(name) is not str:
|
|
250
|
+
raise TypeError('type(name) must be str')
|
|
249
251
|
if name in ('format', 'format_map') and (
|
|
250
252
|
isinstance(object, str) or
|
|
251
253
|
(isinstance(object, type) and issubclass(object, str))):
|
|
@@ -593,6 +593,10 @@ class RestrictingNodeTransformer(ast.NodeTransformer):
|
|
|
593
593
|
"""
|
|
594
594
|
return self.node_contents_visit(node)
|
|
595
595
|
|
|
596
|
+
def visit_Interactive(self, node):
|
|
597
|
+
"""Allow single mode without restrictions."""
|
|
598
|
+
return self.node_contents_visit(node)
|
|
599
|
+
|
|
596
600
|
def visit_List(self, node):
|
|
597
601
|
"""Allow list literals without restrictions."""
|
|
598
602
|
return self.node_contents_visit(node)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: RestrictedPython
|
|
3
|
-
Version: 7.
|
|
3
|
+
Version: 7.2
|
|
4
4
|
Summary: RestrictedPython is a defined subset of the Python language which allows to provide a program input into a trusted environment.
|
|
5
5
|
Home-page: https://github.com/zopefoundation/RestrictedPython
|
|
6
6
|
Author: Zope Foundation and Contributors
|
|
@@ -124,6 +124,16 @@ the documentation `Contributing page
|
|
|
124
124
|
Changes
|
|
125
125
|
=======
|
|
126
126
|
|
|
127
|
+
7.2 (2024-08-02)
|
|
128
|
+
----------------
|
|
129
|
+
|
|
130
|
+
- Remove unneeded setuptools fossils that may cause installation problems
|
|
131
|
+
with recent setuptools versions.
|
|
132
|
+
- Add support for single mode statements / execution.
|
|
133
|
+
- Fix a potential breakout capability in the provided ``safer_getattr`` method
|
|
134
|
+
that is part of the ``safer_builtins``.
|
|
135
|
+
|
|
136
|
+
|
|
127
137
|
7.1 (2024-03-14)
|
|
128
138
|
----------------
|
|
129
139
|
|
|
@@ -259,6 +259,42 @@ def test_Guards__safer_getattr__3():
|
|
|
259
259
|
assert restricted_globals['result'] == 2
|
|
260
260
|
|
|
261
261
|
|
|
262
|
+
SAFER_GETATTR_BREAKOUT = """\
|
|
263
|
+
def g(obj, name):
|
|
264
|
+
# create class FakeString which inherits from str
|
|
265
|
+
class FakeString(str):
|
|
266
|
+
# overload startswith() to always return false
|
|
267
|
+
def startswith(self, _):
|
|
268
|
+
return False
|
|
269
|
+
return getattr(obj, FakeString(name))
|
|
270
|
+
|
|
271
|
+
# call str.__class__.__base__.__subclasses__()
|
|
272
|
+
subclasses = g(g(g(str, "__class__"), "__base__"), "__subclasses__")()
|
|
273
|
+
# traverse list of subclasses until we reach the BuiltinImporter class
|
|
274
|
+
x = "test"
|
|
275
|
+
while "BuiltinImporter" not in str(x):
|
|
276
|
+
x = subclasses.pop()
|
|
277
|
+
continue
|
|
278
|
+
# use BuiltinImporter to import 'os' and access to a not allowed function
|
|
279
|
+
result = x.load_module('os').getgid()
|
|
280
|
+
"""
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def test_Guards__safer_getattr__4():
|
|
284
|
+
restricted_globals = dict(
|
|
285
|
+
__builtins__=safe_builtins,
|
|
286
|
+
__name__=None,
|
|
287
|
+
__metaclass__=type,
|
|
288
|
+
# _write_=_write_,
|
|
289
|
+
getattr=safer_getattr,
|
|
290
|
+
result=None,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
with pytest.raises(TypeError) as err:
|
|
294
|
+
restricted_exec(SAFER_GETATTR_BREAKOUT, restricted_globals)
|
|
295
|
+
assert 'type(name) must be str' == str(err.value)
|
|
296
|
+
|
|
297
|
+
|
|
262
298
|
def test_call_py3_builtins():
|
|
263
299
|
"""It should not be allowed to access global builtins in Python3."""
|
|
264
300
|
result = compile_restricted_exec('builtins["getattr"]')
|
|
@@ -160,13 +160,24 @@ def test_compile__compile_restricted_eval__used_names():
|
|
|
160
160
|
assert result.used_names == {'a': True, 'b': True, 'x': True, 'func': True}
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
def
|
|
163
|
+
def test_compile__compile_restricted_single__1():
|
|
164
164
|
"""It compiles code as an Interactive."""
|
|
165
|
-
result = compile_restricted_single('4 * 6')
|
|
166
|
-
|
|
167
|
-
assert result.errors == (
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
result = compile_restricted_single('x = 4 * 6')
|
|
166
|
+
|
|
167
|
+
assert result.errors == ()
|
|
168
|
+
assert result.warnings == []
|
|
169
|
+
assert result.code is not None
|
|
170
|
+
locals = {}
|
|
171
|
+
exec(result.code, {}, locals)
|
|
172
|
+
assert locals["x"] == 24
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_compile__compile_restricted__2():
|
|
176
|
+
"""It compiles code as an Interactive."""
|
|
177
|
+
code = compile_restricted('x = 4 * 6', filename="<string>", mode="single")
|
|
178
|
+
locals = {}
|
|
179
|
+
exec(code, {}, locals)
|
|
180
|
+
assert locals["x"] == 24
|
|
170
181
|
|
|
171
182
|
|
|
172
183
|
PRINT_EXAMPLE = """
|
RestrictedPython-7.1/setup.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
##############################################################################
|
|
2
|
-
#
|
|
3
|
-
# Copyright (c) 2006 Zope Foundation and Contributors.
|
|
4
|
-
# All Rights Reserved.
|
|
5
|
-
#
|
|
6
|
-
# This software is subject to the provisions of the Zope Public License,
|
|
7
|
-
# Version 2.1 (ZPL). A copy of the ZPL should accompany this 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
|
-
"""Setup for RestrictedPython package"""
|
|
15
|
-
|
|
16
|
-
import os
|
|
17
|
-
|
|
18
|
-
from setuptools import find_packages
|
|
19
|
-
from setuptools import setup
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def read(*rnames):
|
|
23
|
-
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
|
|
24
|
-
return f.read()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
tests_require = [
|
|
28
|
-
'pytest',
|
|
29
|
-
'pytest-mock',
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
setup(
|
|
34
|
-
name='RestrictedPython',
|
|
35
|
-
version='7.1',
|
|
36
|
-
url='https://github.com/zopefoundation/RestrictedPython',
|
|
37
|
-
license='ZPL 2.1',
|
|
38
|
-
description=(
|
|
39
|
-
'RestrictedPython is a defined subset of the Python language which '
|
|
40
|
-
'allows to provide a program input into a trusted environment.'
|
|
41
|
-
),
|
|
42
|
-
long_description=read('README.rst') + '\n' + read('CHANGES.rst'),
|
|
43
|
-
long_description_content_type='text/x-rst',
|
|
44
|
-
classifiers=[
|
|
45
|
-
'Development Status :: 6 - Mature',
|
|
46
|
-
'License :: OSI Approved :: Zope Public License',
|
|
47
|
-
'Programming Language :: Python',
|
|
48
|
-
'Operating System :: OS Independent',
|
|
49
|
-
'Programming Language :: Python :: 3',
|
|
50
|
-
'Programming Language :: Python :: 3.7',
|
|
51
|
-
'Programming Language :: Python :: 3.8',
|
|
52
|
-
'Programming Language :: Python :: 3.9',
|
|
53
|
-
'Programming Language :: Python :: 3.10',
|
|
54
|
-
'Programming Language :: Python :: 3.11',
|
|
55
|
-
'Programming Language :: Python :: 3.12',
|
|
56
|
-
'Programming Language :: Python :: Implementation :: CPython',
|
|
57
|
-
'Topic :: Security',
|
|
58
|
-
],
|
|
59
|
-
keywords='restricted execution security untrusted code',
|
|
60
|
-
author='Zope Foundation and Contributors',
|
|
61
|
-
author_email='zope-dev@zope.org',
|
|
62
|
-
project_urls={
|
|
63
|
-
"Documentation": "https://restrictedpython.readthedocs.io/",
|
|
64
|
-
"Source": "https://github.com/zopefoundation/RestrictedPython",
|
|
65
|
-
"Tracker": "https://github.com/zopefoundation/RestrictedPython/issues",
|
|
66
|
-
},
|
|
67
|
-
packages=find_packages('src'),
|
|
68
|
-
package_dir={'': 'src'},
|
|
69
|
-
install_requires=[
|
|
70
|
-
],
|
|
71
|
-
python_requires=">=3.7, <3.13",
|
|
72
|
-
tests_require=tests_require,
|
|
73
|
-
extras_require={
|
|
74
|
-
'test': tests_require,
|
|
75
|
-
'docs': ['Sphinx', 'sphinx_rtd_theme'],
|
|
76
|
-
},
|
|
77
|
-
include_package_data=True,
|
|
78
|
-
zip_safe=False
|
|
79
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{RestrictedPython-7.1 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_bit_wise_operators.py
RENAMED
|
File without changes
|
{RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_bool_operators.py
RENAMED
|
File without changes
|
|
File without changes
|
{RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_identity_operators.py
RENAMED
|
File without changes
|
{RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_logical_operators.py
RENAMED
|
File without changes
|
{RestrictedPython-7.1 → RestrictedPython-7.2}/tests/transformer/operators/test_unary_operators.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|