from sys import argv
-
class UnclosedSection(Exception):
"""Raised when you have unbalanced section tags"""
pass
# Otherwise make a generator
tokens = tokenize(template)
- output = ''
+ output = unicode('', 'utf-8')
# If the data is a list
if type(data) is list:
# 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':
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):