]> Devi Nivas Git - chevron.git/commitdiff
python 2 working
authornoah morrison <noah@morrison.ph>
Tue, 18 Nov 2014 02:17:12 +0000 (21:17 -0500)
committernoah morrison <noah@morrison.ph>
Tue, 18 Nov 2014 02:17:12 +0000 (21:17 -0500)
entei.py

index 0e82dd5b23ca54d9c13b4012c2e744057df196c1..447c2b4857e1d86deb69e07c61fb95dffcb6d30e 100755 (executable)
--- a/entei.py
+++ b/entei.py
@@ -4,7 +4,6 @@ import json
 
 from sys import argv
 
-
 class UnclosedSection(Exception):
     """Raised when you have unbalanced section tags"""
     pass
@@ -255,7 +254,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
         # Otherwise make a generator
         tokens = tokenize(template)
 
-    output = ''
+    output = unicode('', 'utf-8')
 
     # If the data is a list
     if type(data) is list:
@@ -290,12 +289,17 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
         # If we're a literal tag
         elif tag == 'literal':
             # Add padding to the key and add it to the output
+            if type(key) != unicode:
+                key = unicode(key, 'utf-8')
             output += key.replace('\n', '\n' + (' ' * padding))
 
         # If we're a variable tag
         elif tag == 'variable':
             # Add the html escaped key to the output
-            output += html_escape(str(get_key(key)))
+            thing = get_key(key)
+            if type(thing) != unicode:
+                thing = unicode(str(thing), 'utf-8')
+            output += html_escape(thing)
 
         # If we're a no html escape tag
         elif tag == 'no escape':
@@ -356,9 +360,9 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
                 part_out = part_out.rstrip(' ')
 
             # Add the partials output to the ouput
-            output += part_out
+            output += part_out.decode('utf-8')
 
-    return output
+    return output.encode('utf-8')
 
 
 def main(data, template, **kwargs):