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
5177e8c6
Commit
5177e8c6
authored
Oct 18, 2012
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch unicode errors in contextualize_text and deal with them.
parent
2e03a484
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletions
+11
-1
common/lib/capa/capa/util.py
+11
-1
No files found.
common/lib/capa/capa/util.py
View file @
5177e8c6
...
@@ -28,7 +28,17 @@ def contextualize_text(text, context): # private
...
@@ -28,7 +28,17 @@ def contextualize_text(text, context): # private
Does a substitution of those variables from the context '''
Does a substitution of those variables from the context '''
if
not
text
:
return
text
if
not
text
:
return
text
for
key
in
sorted
(
context
,
lambda
x
,
y
:
cmp
(
len
(
y
),
len
(
x
))):
for
key
in
sorted
(
context
,
lambda
x
,
y
:
cmp
(
len
(
y
),
len
(
x
))):
text
=
text
.
replace
(
'$'
+
key
,
str
(
context
[
key
]))
# TODO (vshnayder): This whole replacement thing is a big hack
# right now--context contains not just just the vars defined
# in the program, but also e.g. a reference to the numpy
# module. Should be a separate dict of variables that are
# should be replaced.
if
'$'
+
key
in
text
:
try
:
s
=
str
(
context
[
key
])
except
UnicodeEncodeError
:
s
=
context
[
key
]
.
encode
(
'utf8'
,
errors
=
'ignore'
)
text
=
text
.
replace
(
'$'
+
key
,
s
)
return
text
return
text
...
...
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