-
Couldn't load subscription status.
- Fork 42
Port eval py #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Port eval py #43
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f525898
'RestrictingNodeTransformer' reports now the used names.
stephan-hof 9ab2d69
Use the ast module to get all the used names.
stephan-hof 95fcf82
Remove not needed code.
stephan-hof 1f20bcf
Port maketrans to python3 and remove other usages of the string module.
stephan-hof 2d0c442
Refactor 'eval'.
stephan-hof e5817ac
Use 'compile_restricted_eval' from compile.py
stephan-hof 6fcc399
Move the tests for 'Eval.py' to the new tests.
stephan-hof 2f572d2
Make isort and flake8 happy.
stephan-hof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from RestrictedPython.Eval import RestrictionCapableEval | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| exp = """ | ||
| {'a':[m.pop()]}['a'] \ | ||
| + [m[0]] | ||
| """ | ||
|
|
||
|
|
||
| def test_init(): | ||
| ob = RestrictionCapableEval(exp) | ||
|
|
||
| assert ob.expr == "{'a':[m.pop()]}['a'] + [m[0]]" | ||
| assert ob.used == ('m', ) | ||
| assert ob.ucode is not None | ||
| assert ob.rcode is None | ||
|
|
||
|
|
||
| def test_init_with_syntax_error(): | ||
| with pytest.raises(SyntaxError): | ||
| RestrictionCapableEval("if:") | ||
|
|
||
|
|
||
| def test_prepRestrictedCode(): | ||
| ob = RestrictionCapableEval(exp) | ||
| ob.prepRestrictedCode() | ||
| assert ob.used == ('m', ) | ||
| assert ob.rcode is not None | ||
|
|
||
|
|
||
| def test_call(): | ||
| ob = RestrictionCapableEval(exp) | ||
| ret = ob(m=[1, 2]) | ||
| assert ret == [2, 1] | ||
|
|
||
|
|
||
| def test_eval(): | ||
| ob = RestrictionCapableEval(exp) | ||
| ret = ob.eval({'m': [1, 2]}) | ||
| assert ret == [2, 1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
prepUnrestrictedCodeactually still needed?I think getting SyntaxErrors and used names can be done by
compile_restricted_eval.Or do I miss something here?
(Maybe this can be delayed after the release to stay backwards compatible to see if some code uses this method or the
ucodeattribute.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, the only justification for this method is the
ucodeattribute.I did a quick search and found one user of it: https://github.com/zopefoundation/DocumentTemplate/blob/6b526d4b76f5496de5049f365a09ab712751c532/src/DocumentTemplate/DT_Util.py#L212
My suggestion would be to keep this method and
ucode. To stay backwards compatible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.