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
477604d0
Commit
477604d0
authored
Nov 13, 2001
by
Evan Simpson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test and fix for default argument processing in sub-functions.
parent
8d61d0d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
4 deletions
+19
-4
lib/python/RestrictedPython/MutatingWalker.py
lib/python/RestrictedPython/MutatingWalker.py
+4
-2
lib/python/RestrictedPython/RestrictionMutator.py
lib/python/RestrictedPython/RestrictionMutator.py
+3
-2
lib/python/RestrictedPython/tests/restricted_module.py
lib/python/RestrictedPython/tests/restricted_module.py
+9
-0
lib/python/RestrictedPython/tests/testRestrictions.py
lib/python/RestrictedPython/tests/testRestrictions.py
+3
-0
No files found.
lib/python/RestrictedPython/MutatingWalker.py
View file @
477604d0
...
...
@@ -83,7 +83,7 @@
#
##############################################################################
__version__
=
'$Revision: 1.
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
3
$'
[
11
:
-
2
]
from
compiler
import
ast
...
...
@@ -97,8 +97,10 @@ class MutatingWalker:
self
.
visitor
=
visitor
self
.
_cache
=
{}
def
defaultVisitNode
(
self
,
node
,
walker
=
None
):
def
defaultVisitNode
(
self
,
node
,
walker
=
None
,
exclude
=
None
):
for
name
,
child
in
node
.
__dict__
.
items
():
if
exclude
is
not
None
and
name
in
exclude
:
continue
v
=
self
.
dispatchObject
(
child
)
if
v
is
not
child
:
# Replace the node.
...
...
lib/python/RestrictedPython/RestrictionMutator.py
View file @
477604d0
...
...
@@ -87,7 +87,7 @@ RestrictionMutator modifies a tree produced by
compiler.transformer.Transformer, restricting and enhancing the
code in various ways before sending it to pycodegen.
'''
__version__
=
'$Revision: 1.
6
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
7
$'
[
11
:
-
2
]
from
compiler
import
ast
from
compiler.transformer
import
parse
...
...
@@ -206,10 +206,11 @@ class RestrictionMutator:
self
.
checkName
(
node
,
node
.
name
)
for
argname
in
node
.
argnames
:
self
.
checkName
(
node
,
argname
)
walker
.
visitSequence
(
node
.
defaults
)
former_funcinfo
=
self
.
funcinfo
self
.
funcinfo
=
FuncInfo
()
node
=
walker
.
defaultVisitNode
(
node
)
node
=
walker
.
defaultVisitNode
(
node
,
exclude
=
(
'defaults'
,)
)
self
.
prepBody
(
node
.
code
.
nodes
)
self
.
funcinfo
=
former_funcinfo
return
node
...
...
lib/python/RestrictedPython/tests/restricted_module.py
View file @
477604d0
...
...
@@ -42,6 +42,11 @@ def allowed_read(ob):
print
len
(
ob
)
return
printed
def
allowed_default_args
(
ob
):
def
f
(
a
=
ob
.
allowed
,
s
=
ob
.
s
):
return
a
,
s
def
allowed_simple
():
q
=
{
'x'
:
'a'
}
q
[
'y'
]
=
'b'
...
...
@@ -72,6 +77,10 @@ def denied_getattr(ob):
ob
.
disallowed
=
1
return
ob
.
disallowed
def
denied_default_args
(
ob
):
def
f
(
d
=
ob
.
disallowed
):
return
d
def
denied_setattr
(
ob
):
ob
.
allowed
=
-
1
...
...
lib/python/RestrictedPython/tests/testRestrictions.py
View file @
477604d0
...
...
@@ -204,6 +204,9 @@ class RestrictionTests(unittest.TestCase):
def
checkAllowedWrite
(
self
):
self
.
execFunc
(
'allowed_write'
,
RestrictedObject
())
def
checkAllowedArgs
(
self
):
self
.
execFunc
(
'allowed_default_args'
,
RestrictedObject
())
def
checkDenied
(
self
):
for
k
in
rmodule
.
keys
():
if
k
[:
6
]
==
'denied'
:
...
...
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