From: noah morrison Date: Tue, 18 Nov 2014 02:17:12 +0000 (-0500) Subject: python 2 working X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=d632f9c63ebd7c1f324772b80c152fb8c262055a;p=chevron.git python 2 working --- diff --git a/entei.py b/entei.py index 0e82dd5..447c2b4 100755 --- 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):