RestrictedPython 7.0a2.dev0__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.
Files changed (107) hide show
  1. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/CHANGES.rst +20 -6
  2. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/PKG-INFO +23 -8
  3. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/conf.py +4 -4
  4. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_12.ast +12 -3
  5. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/index.rst +14 -14
  6. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/roadmap/index.rst +0 -5
  7. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/usage/basic_usage.rst +56 -0
  8. RestrictedPython-7.2/setup.py +74 -0
  9. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/Guards.py +2 -0
  10. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/transformer.py +6 -2
  11. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/PKG-INFO +23 -8
  12. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_Guards.py +36 -0
  13. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_compile.py +17 -6
  14. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_arithmetic_operators.py +9 -6
  15. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tox.ini +1 -1
  16. RestrictedPython-7.0a2.dev0/setup.py +0 -78
  17. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/.readthedocs.yaml +0 -0
  18. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/CONTRIBUTING.md +0 -0
  19. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/COPYRIGHT.txt +0 -0
  20. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/LICENSE.txt +0 -0
  21. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/MANIFEST.in +0 -0
  22. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/README.rst +0 -0
  23. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/buildout.cfg +0 -0
  24. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/constraints.txt +0 -0
  25. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/Makefile +0 -0
  26. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/changes.rst +0 -0
  27. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_10.ast +0 -0
  28. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_11.ast +0 -0
  29. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_6.ast +0 -0
  30. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_7.ast +0 -0
  31. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_8.ast +0 -0
  32. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/ast/python3_9.ast +0 -0
  33. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/changes_from310to311.rst +0 -0
  34. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/changes_from311to312.rst +0 -0
  35. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/changes_from36to37.rst +0 -0
  36. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/changes_from37to38.rst +0 -0
  37. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/changes_from38to39.rst +0 -0
  38. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/contributing/changes_from39to310.rst +0 -0
  39. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/idea.rst +0 -0
  40. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/index.rst +0 -0
  41. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/install/index.rst +0 -0
  42. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/logo.jpg +0 -0
  43. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/make.bat +0 -0
  44. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/requirements.txt +0 -0
  45. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/upgrade_dependencies/index.rst +0 -0
  46. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/usage/api.rst +0 -0
  47. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/usage/framework_usage.rst +0 -0
  48. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/usage/index.rst +0 -0
  49. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/docs/usage/policy.rst +0 -0
  50. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/setup.cfg +0 -0
  51. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/Eval.py +0 -0
  52. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/Limits.py +0 -0
  53. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/PrintCollector.py +0 -0
  54. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/Utilities.py +0 -0
  55. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/__init__.py +0 -0
  56. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/_compat.py +0 -0
  57. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython/compile.py +0 -0
  58. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/SOURCES.txt +0 -0
  59. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/dependency_links.txt +0 -0
  60. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/not-zip-safe +0 -0
  61. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/requires.txt +0 -0
  62. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/src/RestrictedPython.egg-info/top_level.txt +0 -0
  63. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/__init__.py +0 -0
  64. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/builtins/test_limits.py +0 -0
  65. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/builtins/test_utilities.py +0 -0
  66. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/helper.py +0 -0
  67. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_NamedExpr.py +0 -0
  68. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_Utilities.py +0 -0
  69. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_compile_restricted_function.py +0 -0
  70. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_eval.py +0 -0
  71. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_imports.py +0 -0
  72. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_iterating_over_dict_items.py +0 -0
  73. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/test_print_function.py +0 -0
  74. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_bit_wise_operators.py +0 -0
  75. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_bool_operators.py +0 -0
  76. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_comparison_operators.py +0 -0
  77. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_identity_operators.py +0 -0
  78. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_logical_operators.py +0 -0
  79. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/operators/test_unary_operators.py +0 -0
  80. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_assert.py +0 -0
  81. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_assign.py +0 -0
  82. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_async.py +0 -0
  83. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_attribute.py +0 -0
  84. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_augassign.py +0 -0
  85. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_base_types.py +0 -0
  86. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_breakpoint.py +0 -0
  87. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_call.py +0 -0
  88. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_classdef.py +0 -0
  89. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_comparators.py +0 -0
  90. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_conditional.py +0 -0
  91. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_dict_comprehension.py +0 -0
  92. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_eval_exec.py +0 -0
  93. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_fstring.py +0 -0
  94. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_functiondef.py +0 -0
  95. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_generic.py +0 -0
  96. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_global_local.py +0 -0
  97. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_import.py +0 -0
  98. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_inspect.py +0 -0
  99. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_iterator.py +0 -0
  100. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_lambda.py +0 -0
  101. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_loop.py +0 -0
  102. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_name.py +0 -0
  103. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_slice.py +0 -0
  104. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_subscript.py +0 -0
  105. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_try.py +0 -0
  106. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_with_stmt.py +0 -0
  107. {RestrictedPython-7.0a2.dev0 → RestrictedPython-7.2}/tests/transformer/test_yield.py +0 -0
@@ -1,8 +1,24 @@
1
1
  Changes
2
2
  =======
3
3
 
4
- 7.0a2.dev0 (2023-11-06)
5
- -----------------------
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
+
14
+ 7.1 (2024-03-14)
15
+ ----------------
16
+
17
+ - Add support for the matmul (``@``) operator.
18
+
19
+
20
+ 7.0 (2023-11-17)
21
+ ----------------
6
22
 
7
23
  Backwards incompatible changes
8
24
  ++++++++++++++++++++++++++++++
@@ -12,8 +28,7 @@ Backwards incompatible changes
12
28
  Features
13
29
  ++++++++
14
30
 
15
- - Allow to use the package with Python 3.12 and 3.13 -- Caution: No security
16
- audit has been done so far.
31
+ - Officially support Python 3.12.
17
32
 
18
33
  Fixes
19
34
  +++++
@@ -23,8 +38,7 @@ Fixes
23
38
  - Forbid using some attributes providing access to restricted Python internals.
24
39
  (CVE-2023-37271)
25
40
 
26
- - Fix information disclosure problems through
27
- Python's "format" functionality
41
+ - Fix information disclosure problems through Python's "format" functionality
28
42
  (``format`` and ``format_map`` methods on ``str`` and its instances,
29
43
  ``string.Formatter``). (CVE-2023-41039)
30
44
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RestrictedPython
3
- Version: 7.0a2.dev0
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
@@ -20,9 +20,10 @@ Classifier: Programming Language :: Python :: 3.8
20
20
  Classifier: Programming Language :: Python :: 3.9
21
21
  Classifier: Programming Language :: Python :: 3.10
22
22
  Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
23
24
  Classifier: Programming Language :: Python :: Implementation :: CPython
24
25
  Classifier: Topic :: Security
25
- Requires-Python: >=3.7, <3.14
26
+ Requires-Python: >=3.7, <3.13
26
27
  Description-Content-Type: text/x-rst
27
28
  License-File: LICENSE.txt
28
29
  Provides-Extra: test
@@ -123,8 +124,24 @@ the documentation `Contributing page
123
124
  Changes
124
125
  =======
125
126
 
126
- 7.0a2.dev0 (2023-11-06)
127
- -----------------------
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
+
137
+ 7.1 (2024-03-14)
138
+ ----------------
139
+
140
+ - Add support for the matmul (``@``) operator.
141
+
142
+
143
+ 7.0 (2023-11-17)
144
+ ----------------
128
145
 
129
146
  Backwards incompatible changes
130
147
  ++++++++++++++++++++++++++++++
@@ -134,8 +151,7 @@ Backwards incompatible changes
134
151
  Features
135
152
  ++++++++
136
153
 
137
- - Allow to use the package with Python 3.12 and 3.13 -- Caution: No security
138
- audit has been done so far.
154
+ - Officially support Python 3.12.
139
155
 
140
156
  Fixes
141
157
  +++++
@@ -145,8 +161,7 @@ Fixes
145
161
  - Forbid using some attributes providing access to restricted Python internals.
146
162
  (CVE-2023-37271)
147
163
 
148
- - Fix information disclosure problems through
149
- Python's "format" functionality
164
+ - Fix information disclosure problems through Python's "format" functionality
150
165
  (``format`` and ``format_map`` methods on ``str`` and its instances,
151
166
  ``string.Formatter``). (CVE-2023-41039)
152
167
 
@@ -47,7 +47,7 @@ master_doc = 'index'
47
47
 
48
48
  # General information about the project.
49
49
  project = 'RestrictedPython'
50
- copyright = '2017-2022, Zope Foundation and Contributors'
50
+ copyright = '2017-2023, Zope Foundation and Contributors'
51
51
  author = 'The Zope & Plone developer community'
52
52
 
53
53
  # The version info for the project you're documenting, acts as replacement for
@@ -55,9 +55,9 @@ author = 'The Zope & Plone developer community'
55
55
  # built documents.
56
56
  #
57
57
  # The short X.Y version.
58
- version = '5.0'
58
+ version = '7.0'
59
59
  # The full version, including alpha/beta/rc tags.
60
- release = '5.0'
60
+ release = '7.0'
61
61
 
62
62
  # The language for content autogenerated by Sphinx. Refer to documentation
63
63
  # for a list of supported languages.
@@ -217,7 +217,7 @@ html_theme = 'default'
217
217
  # html_search_scorer = 'scorer.js'
218
218
 
219
219
  # Output file base name for HTML help builder.
220
- htmlhelp_basename = 'RestrictedPythondoc'
220
+ htmlhelp_basename = 'RestrictedPython_doc'
221
221
 
222
222
  # -- Options for LaTeX output ---------------------------------------------
223
223
 
@@ -14,23 +14,27 @@ module Python version "3.12"
14
14
  stmt* body,
15
15
  expr* decorator_list,
16
16
  expr? returns,
17
- string? type_comment)
17
+ string? type_comment,
18
+ type_param* type_params)
18
19
  | AsyncFunctionDef(identifier name,
19
20
  arguments args,
20
21
  stmt* body,
21
22
  expr* decorator_list,
22
23
  expr? returns,
23
- string? type_comment)
24
+ string? type_comment,
25
+ type_param* type_params)
24
26
 
25
27
  | ClassDef(identifier name,
26
28
  expr* bases,
27
29
  keyword* keywords,
28
30
  stmt* body,
29
- expr* decorator_list)
31
+ expr* decorator_list,
32
+ type_param* type_params)
30
33
  | Return(expr? value)
31
34
 
32
35
  | Delete(expr* targets)
33
36
  | Assign(expr* targets, expr value, string? type_comment)
37
+ | TypeAlias(expr name, type_param* type_params, expr value)
34
38
  | AugAssign(expr target, operator op, expr value)
35
39
  -- 'simple' indicates that we annotate simple name without parens
36
40
  | AnnAssign(expr target, expr annotation, expr? value, int simple)
@@ -182,4 +186,9 @@ module Python version "3.12"
182
186
  attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
183
187
 
184
188
  type_ignore = TypeIgnore(int lineno, string tag)
189
+
190
+ type_param = TypeVar(identifier name, expr? bound)
191
+ | ParamSpec(identifier name)
192
+ | TypeVarTuple(identifier name)
193
+ attributes (int lineno, int col_offset, int end_lineno, int end_col_offset)
185
194
  }
@@ -91,8 +91,8 @@ To enable a certain functionality in RestrictedPython, do the following:
91
91
  * icemac
92
92
  * loechel
93
93
 
94
- Differences between different Python versions
95
- ---------------------------------------------
94
+ Differences between Python versions
95
+ -----------------------------------
96
96
 
97
97
  A (modified style) Copy of all Abstract Grammar Definitions for the Python versions does live in this Documentation (ast Subfolder) to help finding difference quicker by comparing files.
98
98
 
@@ -152,14 +152,14 @@ The ``ast`` module consists of four areas:
152
152
  A ``NodeVisitor`` is a class of a node / AST consumer, it reads the data by stepping through the tree without modifying it.
153
153
  In contrast, a ``NodeTransformer`` (which inherits from a ``NodeVisitor``) is allowed to modify the tree and nodes.
154
154
 
155
- Technical decissions on how to implement / maintain RestrictedPython (Design, Structure, Tools, ...)
156
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
155
+ Technical decisions on how to implement / maintain RestrictedPython (Design, Structure, Tools, ...)
156
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
157
157
 
158
158
  RestrictedPython is a core Package of the Zope & Plone Stack.
159
159
  Until Version 3.6 RestrictedPython was Python 2 only, and a critical blocker for Zope & Plone.
160
- With RestrictedPython 4.0 an API compatible rewrite has happend, which supports modern Python Versions.
160
+ With RestrictedPython 4.0 an API compatible rewrite has happened, which supports modern Python Versions.
161
161
 
162
- * Use modern python tool stack for maintainance and tests
162
+ * Use modern python tool stack for maintenance and tests
163
163
 
164
164
  * tox
165
165
  * pytest
@@ -179,7 +179,7 @@ With RestrictedPython 4.0 an API compatible rewrite has happend, which supports
179
179
  Resolve discussion about how RestrictedPython should be treat new expressions / ``ast.Nodes``.
180
180
  This belongs to :ref:`new_python_version`.
181
181
 
182
- **Option 1 - reduce maintainance burden (prefered by icemac)**
182
+ **Option 1 - reduce maintenance burden (preferred by icemac)**
183
183
 
184
184
 
185
185
  All AST Nodes without an explicit ``visit_<AST Node>`` method, are denied by default.
@@ -187,7 +187,7 @@ With RestrictedPython 4.0 an API compatible rewrite has happend, which supports
187
187
 
188
188
  *This is currently the promoted version.*
189
189
 
190
- **Option 2 - be as explicite as possible (prefered by loechel)**
190
+ **Option 2 - be as explicit as possible (preferred by loechel)**
191
191
 
192
192
  If the new AST Node should be disabled by default, add a ``visit_<AST Node>`` method such as the following:
193
193
 
@@ -237,12 +237,12 @@ Technical Backgrounds - Links to External Documentation
237
237
 
238
238
  * AST Grammar of Python (`Status of Python Versions`_)
239
239
 
240
- * `Python 3.12 AST`_ (development branch - EOL 2028-10)
241
- * `Python 3.11 AST`_ (in bugfix phase - EOL 2027-10)
242
- * `Python 3.10 AST`_ (in bugfix phase - EOL 2026-10)
243
- * `Python 3.9 AST`_ (in security phase - EOL 2025-10)
244
- * `Python 3.8 AST`_ (in security phase - EOL 2024-10)
245
- * `Python 3.7 AST`_ (in security phase - EOL 2023-06-27)
240
+ * `Python 3.12 AST`_ (EOL 2028-10)
241
+ * `Python 3.11 AST`_ (EOL 2027-10)
242
+ * `Python 3.10 AST`_ (EOL 2026-10)
243
+ * `Python 3.9 AST`_ (EOL 2025-10)
244
+ * `Python 3.8 AST`_ (EOL 2024-10)
245
+ * `Python 3.7 AST`_ (EOL 2023-06-27)
246
246
 
247
247
  * `AST NodeVistiors Class`_
248
248
  * `AST NodeTransformer Class`_
@@ -26,11 +26,6 @@ Full code coverage tests.
26
26
 
27
27
  stephan-hof did propose a solution, should be discussed and if approved implemented.
28
28
 
29
- RestrictedPython 4.1+
30
- ---------------------
31
-
32
- Enhance RestrictedPython, declare deprecations and possible new restrictions.
33
-
34
29
  RestrictedPython 6.0+
35
30
  ---------------------
36
31
 
@@ -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)
@@ -768,8 +772,8 @@ class RestrictingNodeTransformer(ast.NodeTransformer):
768
772
  return self.node_contents_visit(node)
769
773
 
770
774
  def visit_MatMult(self, node):
771
- """Matrix multiplication (`@`) is currently not allowed."""
772
- self.not_allowed(node)
775
+ """Allow multiplication (`@`)."""
776
+ return self.node_contents_visit(node)
773
777
 
774
778
  def visit_BoolOp(self, node):
775
779
  """Allow bool operator without restrictions."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: RestrictedPython
3
- Version: 7.0a2.dev0
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
@@ -20,9 +20,10 @@ Classifier: Programming Language :: Python :: 3.8
20
20
  Classifier: Programming Language :: Python :: 3.9
21
21
  Classifier: Programming Language :: Python :: 3.10
22
22
  Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
23
24
  Classifier: Programming Language :: Python :: Implementation :: CPython
24
25
  Classifier: Topic :: Security
25
- Requires-Python: >=3.7, <3.14
26
+ Requires-Python: >=3.7, <3.13
26
27
  Description-Content-Type: text/x-rst
27
28
  License-File: LICENSE.txt
28
29
  Provides-Extra: test
@@ -123,8 +124,24 @@ the documentation `Contributing page
123
124
  Changes
124
125
  =======
125
126
 
126
- 7.0a2.dev0 (2023-11-06)
127
- -----------------------
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
+
137
+ 7.1 (2024-03-14)
138
+ ----------------
139
+
140
+ - Add support for the matmul (``@``) operator.
141
+
142
+
143
+ 7.0 (2023-11-17)
144
+ ----------------
128
145
 
129
146
  Backwards incompatible changes
130
147
  ++++++++++++++++++++++++++++++
@@ -134,8 +151,7 @@ Backwards incompatible changes
134
151
  Features
135
152
  ++++++++
136
153
 
137
- - Allow to use the package with Python 3.12 and 3.13 -- Caution: No security
138
- audit has been done so far.
154
+ - Officially support Python 3.12.
139
155
 
140
156
  Fixes
141
157
  +++++
@@ -145,8 +161,7 @@ Fixes
145
161
  - Forbid using some attributes providing access to restricted Python internals.
146
162
  (CVE-2023-37271)
147
163
 
148
- - Fix information disclosure problems through
149
- Python's "format" functionality
164
+ - Fix information disclosure problems through Python's "format" functionality
150
165
  (``format`` and ``format_map`` methods on ``str`` and its instances,
151
166
  ``string.Formatter``). (CVE-2023-41039)
152
167
 
@@ -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 test_compile__compile_restricted_csingle():
163
+ def test_compile__compile_restricted_single__1():
164
164
  """It compiles code as an Interactive."""
165
- result = compile_restricted_single('4 * 6')
166
- assert result.code is None
167
- assert result.errors == (
168
- 'Line None: Interactive statements are not allowed.',
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 = """
@@ -1,4 +1,3 @@
1
- from RestrictedPython import compile_restricted_eval
2
1
  from tests.helper import restricted_eval
3
2
 
4
3
 
@@ -33,8 +32,12 @@ def test_FloorDiv():
33
32
 
34
33
 
35
34
  def test_MatMult():
36
- result = compile_restricted_eval('(8, 3, 5) @ (2, 7, 1)')
37
- assert result.errors == (
38
- 'Line None: MatMult statements are not allowed.',
39
- )
40
- assert result.code is None
35
+ class Vector:
36
+ def __init__(self, values):
37
+ self.values = values
38
+
39
+ def __matmul__(self, other):
40
+ return sum(x * y for x, y in zip(self.values, other.values))
41
+
42
+ assert restricted_eval(
43
+ 'Vector((8, 3, 5)) @ Vector((2, 7, 1))', {'Vector': Vector}) == 42
@@ -54,7 +54,7 @@ commands =
54
54
  coverage combine
55
55
  coverage html
56
56
  coverage report -m --fail-under=100
57
- depends = py37,py38,py39,py39-datetime,py310,py311,py312coverage
57
+ depends = py37,py38,py39,py39-datetime,py310,py311,py312,coverage
58
58
  [testenv:release-check]
59
59
  description = ensure that the distribution is ready to release
60
60
  basepython = python3
@@ -1,78 +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.0a2.dev0',
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 :: Implementation :: CPython',
56
- 'Topic :: Security',
57
- ],
58
- keywords='restricted execution security untrusted code',
59
- author='Zope Foundation and Contributors',
60
- author_email='zope-dev@zope.org',
61
- project_urls={
62
- "Documentation": "https://restrictedpython.readthedocs.io/",
63
- "Source": "https://github.com/zopefoundation/RestrictedPython",
64
- "Tracker": "https://github.com/zopefoundation/RestrictedPython/issues",
65
- },
66
- packages=find_packages('src'),
67
- package_dir={'': 'src'},
68
- install_requires=[
69
- ],
70
- python_requires=">=3.7, <3.14",
71
- tests_require=tests_require,
72
- extras_require={
73
- 'test': tests_require,
74
- 'docs': ['Sphinx', 'sphinx_rtd_theme'],
75
- },
76
- include_package_data=True,
77
- zip_safe=False
78
- )