Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: third_party/handlebar/handlebar.py

Issue 10815059: Extensions Docs Server: Handlebar updates again (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/handlebar/README.chromium ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/handlebar/handlebar.py
diff --git a/third_party/handlebar/handlebar.py b/third_party/handlebar/handlebar.py
index c3f8ffee24d0022a9bf1278184f721ee6a86a714..2d03e422a82c704ed34972a97bf2664000755397 100644
--- a/third_party/handlebar/handlebar.py
+++ b/third_party/handlebar/handlebar.py
@@ -43,6 +43,9 @@ class CustomContext(object):
print(Handlebar('hello {{world}}').render(CustomContext()).text)
"""
+def _SafeStr(obj):
+ return obj if (type(obj) in [str, unicode]) else str(obj)
+
class ParseException(Exception):
""" Exception thrown while parsing the template.
"""
@@ -68,12 +71,15 @@ class StringBuilder(object):
return self._length
def append(self, obj):
- string = str(obj)
+ string = _SafeStr(obj)
self._buf.append(string)
self._length += len(string)
def toString(self):
- return ''.join(self._buf)
+ return u''.join(self._buf)
+
+ def __str__(self):
+ return self.toString()
class RenderState(object):
""" The state of a render call.
@@ -349,7 +355,7 @@ class EscapedVariableNode(LeafNode):
def render(self, renderState):
value = self._id.resolve(renderState)
if value != None:
- self._appendEscapedHtml(renderState.text, str(value))
+ self._appendEscapedHtml(renderState.text, _SafeStr(value))
def _appendEscapedHtml(self, escaped, unescaped):
for c in unescaped:
@@ -420,9 +426,9 @@ def _VertedSectionNodeShouldRender(value):
type_ = type(value)
if type_ == bool:
return value
- if type_ == int or type_ == float:
+ if type_ in [int, float]:
return True
- if type_ == str or type_ == unicode:
+ if type_ in [str, unicode]:
return True
if type_ == list:
return len(value) > 0
« no previous file with comments | « third_party/handlebar/README.chromium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698