Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
5b7bb59c
Commit
5b7bb59c
authored
Nov 04, 2003
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Collector #445: Add internal global declaration for Script bindings.
parent
005b17f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
10 deletions
+19
-10
doc/CHANGES.txt
doc/CHANGES.txt
+2
-0
lib/python/Products/PythonScripts/PythonScript.py
lib/python/Products/PythonScripts/PythonScript.py
+6
-4
lib/python/RestrictedPython/RCompile.py
lib/python/RestrictedPython/RCompile.py
+7
-4
lib/python/RestrictedPython/RCompile_2_1.py
lib/python/RestrictedPython/RCompile_2_1.py
+4
-2
No files found.
doc/CHANGES.txt
View file @
5b7bb59c
...
...
@@ -33,6 +33,8 @@ Zope Changes
(such as storages, databases, or logging handlers) to be used.
Bugs fixed
- Collector #445: Add internal global declaration for Script bindings.
- Collector #616: Make CONTEXTS available to TALES Python expressions.
- Collector #1074: Give Script execution context a __name__
...
...
lib/python/Products/PythonScripts/PythonScript.py
View file @
5b7bb59c
...
...
@@ -17,7 +17,7 @@ This product provides support for Script objects containing restricted
Python code.
"""
__version__
=
'$Revision: 1.
49
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
50
$'
[
11
:
-
2
]
import
sys
,
os
,
traceback
,
re
,
marshal
,
new
from
Globals
import
DTMLFile
,
MessageDialog
,
package_home
...
...
@@ -220,11 +220,13 @@ class PythonScript(Script, Historical, Cacheable):
else
:
self
.
_newfun
(
marshal
.
loads
(
self
.
_code
))
def
_compiler
(
self
,
*
args
):
return
RestrictedPython
.
compile_restricted_function
(
*
args
)
def
_compiler
(
self
,
*
args
,
**
kw
):
return
RestrictedPython
.
compile_restricted_function
(
*
args
,
**
kw
)
def
_compile
(
self
):
bind_names
=
self
.
getBindingAssignments
().
getAssignedNamesInOrder
()
r
=
self
.
_compiler
(
self
.
_params
,
self
.
_body
or
'pass'
,
self
.
id
,
self
.
meta_type
)
self
.
id
,
self
.
meta_type
,
globalize
=
bind_names
)
code
=
r
[
0
]
errors
=
r
[
1
]
self
.
warnings
=
tuple
(
r
[
2
])
...
...
lib/python/RestrictedPython/RCompile.py
View file @
5b7bb59c
...
...
@@ -14,7 +14,7 @@
Python standard library.
"""
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
4
$'
[
11
:
-
2
]
from
compiler
import
ast
,
parse
,
misc
,
syntax
...
...
@@ -79,10 +79,11 @@ class RFunction(RModule):
"""A restricted Python function built from parts.
"""
def
__init__
(
self
,
p
,
body
,
name
,
filename
):
def
__init__
(
self
,
p
,
body
,
name
,
filename
,
globalize
=
None
):
self
.
params
=
p
self
.
body
=
body
self
.
name
=
name
self
.
globalize
=
globalize
RModule
.
__init__
(
self
,
None
,
filename
)
def
parse
(
self
):
...
...
@@ -100,6 +101,8 @@ class RFunction(RModule):
isinstance
(
stmt1
.
expr
,
ast
.
Const
)
and
type
(
stmt1
.
expr
.
value
)
is
type
(
''
)):
f
.
doc
=
stmt1
.
expr
.
value
if
self
.
globalize
:
f
.
code
.
nodes
.
insert
(
0
,
ast
.
Global
(
map
(
str
,
self
.
globalize
)))
return
tree
...
...
@@ -110,14 +113,14 @@ def compileAndTuplize(gen):
return
None
,
(
str
(
v
),),
gen
.
rm
.
warnings
,
gen
.
rm
.
used_names
return
gen
.
getCode
(),
(),
gen
.
rm
.
warnings
,
gen
.
rm
.
used_names
def
compile_restricted_function
(
p
,
body
,
name
,
filename
):
def
compile_restricted_function
(
p
,
body
,
name
,
filename
,
globalize
=
None
):
"""Compiles a restricted code object for a function.
The function can be reconstituted using the 'new' module:
new.function(<code>, <globals>)
"""
gen
=
RFunction
(
p
,
body
,
name
,
filename
)
gen
=
RFunction
(
p
,
body
,
name
,
filename
,
globalize
=
globalize
)
return
compileAndTuplize
(
gen
)
def
compile_restricted_exec
(
s
,
filename
=
'<string>'
):
...
...
lib/python/RestrictedPython/RCompile_2_1.py
View file @
5b7bb59c
...
...
@@ -11,7 +11,7 @@
#
##############################################################################
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
4
$'
[
11
:
-
2
]
import
sys
from
traceback
import
format_exception_only
...
...
@@ -43,7 +43,7 @@ import MutatingWalker
from
RestrictionMutator
import
RestrictionMutator
from
compiler_2_1
import
ast
,
visitor
,
pycodegen
def
compile_restricted_function
(
p
,
body
,
name
,
filename
):
def
compile_restricted_function
(
p
,
body
,
name
,
filename
,
globalize
=
None
):
'''Compile a restricted code object for a function.
The function can be reconstituted using the 'new' module:
...
...
@@ -63,6 +63,8 @@ def compile_restricted_function(p, body, name, filename):
f
=
tree
.
node
.
nodes
[
0
]
btree
,
err
=
tryParsing
(
body
,
'exec'
)
if
err
:
return
err
if
globalize
is
not
None
:
btree
.
node
.
nodes
.
insert
(
0
,
ast
.
Global
(
map
(
str
,
globalize
)))
f
.
code
.
nodes
=
btree
.
node
.
nodes
f
.
name
=
name
# Look for a docstring
...
...
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