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
Lukas Niegsch
erp5
Commits
804e32d2
Commit
804e32d2
authored
Aug 27, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: add "future" features to PythonScript / TALES PythonExpr
parent
132c2685
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
2 deletions
+45
-2
product/ERP5Type/patches/my2to3_patch.py
product/ERP5Type/patches/my2to3_patch.py
+45
-2
No files found.
product/ERP5Type/patches/my2to3_patch.py
View file @
804e32d2
import
new
,
os
import
inspect
,
new
,
os
from
compiler
import
future
,
pyassem
,
walk
from
Acquisition
import
aq_parent
from
Acquisition
import
aq_parent
from
my2to3.trace
import
apply_fixers
,
patch_imports
,
tracing_functions
from
my2to3.trace
import
apply_fixers
,
patch_imports
,
tracing_functions
from
Products.PageTemplates.ZRPythonExpr
import
PythonExpr
from
Products.PageTemplates.ZRPythonExpr
import
PythonExpr
from
Products.PythonScripts.PythonScript
import
_marker
,
PythonScript
,
PythonScriptTracebackSupplement
from
Products.PythonScripts.PythonScript
import
_marker
,
PythonScript
,
PythonScriptTracebackSupplement
from
RestrictedPython
import
compile_restricted_eval
from
RestrictedPython
import
compile_restricted_eval
from
RestrictedPython.RCompile
import
RestrictedExpressionCodeGenerator
,
RestrictedModuleCodeGenerator
from
.
import
PatchClass
from
.
import
PatchClass
...
@@ -15,7 +17,8 @@ erp5_products = ['Products.' + p for p in os.listdir(erp5_products_path)
...
@@ -15,7 +17,8 @@ erp5_products = ['Products.' + p for p in os.listdir(erp5_products_path)
# Apply "trace" fixers on the fly
# Apply "trace" fixers on the fly
if
os
.
environ
.
get
(
"MY2TO3_ACTION"
)
==
"trace"
:
my2to3_action
=
os
.
environ
.
get
(
"MY2TO3_ACTION"
)
if
my2to3_action
==
"trace"
:
def
is_whitelisted
(
fullname
,
path
):
def
is_whitelisted
(
fullname
,
path
):
return
any
(
fullname
.
startswith
(
p
)
for
p
in
erp5_products
)
return
any
(
fullname
.
startswith
(
p
)
for
p
in
erp5_products
)
...
@@ -128,3 +131,43 @@ if os.environ.get("MY2TO3_ACTION") == "trace":
...
@@ -128,3 +131,43 @@ if os.environ.get("MY2TO3_ACTION") == "trace":
# Add new "builtins" which the script can access
# Add new "builtins" which the script can access
PythonExpr
.
_globals
.
update
({
f
.
__name__
:
f
for
f
in
tracing_functions
})
PythonExpr
.
_globals
.
update
({
f
.
__name__
:
f
for
f
in
tracing_functions
})
# TODO: ...
elif
my2to3_action
==
"whatever"
:
# Patch the compilation of PythonScript to add "future" features
class
____
(
PatchClass
(
RestrictedModuleCodeGenerator
)):
def
__init__
(
self
,
tree
):
self
.
graph
=
pyassem
.
PyFlowGraph
(
"<module>"
,
tree
.
filename
)
self
.
futures
=
future
.
find_futures
(
tree
)
# <patch>
try
:
caller
=
inspect
.
stack
()[
4
]
except
IndexError
:
pass
else
:
if
caller
[
1
].
endswith
(
'Products/PythonScripts/PythonScript.py'
)
and
caller
[
2
]
==
239
:
# Patch, to add "future" features
self
.
futures
+=
(
"division"
,)
# TODO: ...
# </patch>
self
.
_ModuleCodeGenerator__super_init
()
# self.__super_init()
walk
(
tree
,
self
)
# Patch the compilation of TALES PythonExpr to add "future" features
class
____
(
PatchClass
(
RestrictedExpressionCodeGenerator
)):
def
__init__
(
self
,
tree
):
self
.
graph
=
pyassem
.
PyFlowGraph
(
"<expression>"
,
tree
.
filename
)
# <patch>
try
:
caller
=
inspect
.
stack
()[
4
]
except
IndexError
:
pass
else
:
if
caller
[
1
]
==
__file__
and
caller
[
2
]
==
126
:
# Patch, to add "future" features
# See https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3f420bb23be1d081dac4/Lib/compiler/pycodegen.py#L214
futures
=
self
.
get_module
().
futures
assert
futures
==
(),
futures
self
.
get_module
().
futures
=
(
"division"
,)
# TODO: ...
# </patch>
self
.
_ExpressionCodeGenerator__super_init
()
# self.__super_init()
walk
(
tree
,
self
)
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