Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
4f33b8e0
Commit
4f33b8e0
authored
May 06, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed a UnicodeEncodeError that occurred when generating cache keys
from non-ASCII unicode code submissions.
parent
e3de0dc8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletions
+14
-1
common/lib/capa/capa/safe_exec/safe_exec.py
+1
-1
common/lib/capa/capa/safe_exec/tests/test_safe_exec.py
+13
-0
No files found.
common/lib/capa/capa/safe_exec/safe_exec.py
View file @
4f33b8e0
...
@@ -58,7 +58,7 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None
...
@@ -58,7 +58,7 @@ def safe_exec(code, globals_dict, random_seed=None, python_path=None, cache=None
if
cache
:
if
cache
:
canonical_globals
=
sorted
(
json_safe
(
globals_dict
)
.
iteritems
())
canonical_globals
=
sorted
(
json_safe
(
globals_dict
)
.
iteritems
())
md5er
=
hashlib
.
md5
()
md5er
=
hashlib
.
md5
()
md5er
.
update
(
code
)
md5er
.
update
(
repr
(
code
)
)
md5er
.
update
(
repr
(
canonical_globals
))
md5er
.
update
(
repr
(
canonical_globals
))
key
=
"safe_exec.
%
r.
%
s"
%
(
random_seed
,
md5er
.
hexdigest
())
key
=
"safe_exec.
%
r.
%
s"
%
(
random_seed
,
md5er
.
hexdigest
())
cached
=
cache
.
get
(
key
)
cached
=
cache
.
get
(
key
)
...
...
common/lib/capa/capa/safe_exec/tests/test_safe_exec.py
View file @
4f33b8e0
...
@@ -143,6 +143,19 @@ class TestSafeExecCaching(unittest.TestCase):
...
@@ -143,6 +143,19 @@ class TestSafeExecCaching(unittest.TestCase):
safe_exec
(
code
,
g
,
cache
=
DictCache
(
cache
))
safe_exec
(
code
,
g
,
cache
=
DictCache
(
cache
))
self
.
assertEqual
(
g
[
'a'
],
17
)
self
.
assertEqual
(
g
[
'a'
],
17
)
def
test_unicode_submission
(
self
):
# Check that using non-ASCII unicode does not raise an encoding error.
# Try several non-ASCII unicode characters
for
code
in
[
129
,
500
,
2
**
8
-
1
,
2
**
16
-
1
]:
code_with_unichr
=
unicode
(
"# "
)
+
unichr
(
code
)
try
:
safe_exec
(
code_with_unichr
,
{},
cache
=
DictCache
({}))
except
UnicodeEncodeError
:
self
.
fail
(
"Tried executing code with non-ASCII unicode: {0}"
.
format
(
code
))
class
TestRealProblems
(
unittest
.
TestCase
):
class
TestRealProblems
(
unittest
.
TestCase
):
def
test_802x
(
self
):
def
test_802x
(
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