Commits

Anonymous committed ad2c3a4

More work on utf-8, think it works now.

Comments (0)

Files changed (1)

             elif stmt in (STMT_TEXT, STMT_CEMBED) :
                 assert(isinstance(value, (str, unicode))), type(value)
                 try:
-                    ostream.write(unicode(value, "utf-8").encode("utf-8"))
+                    if not isinstance(value, unicode):
+                        value = unicode(value, "utf-8")
+                    ostream.write(value.encode("utf-8"))
                 except UnicodeDecodeError, e:
                     raise texceptions.TemplateException(str(e), filepos)
 
                 if isinstance(res, ttypes.Null):
                     pass
                 elif isinstance(res, ttypes.String):
-                    ostream.write(unicode(res.str, "utf-8").encode("utf-8"))
+                    string = res.str
+                    if not isinstance(string, unicode):
+                        string = unicode(string, "utf-8")
+                    ostream.write(string.encode("utf-8"))
                 else:
                     raise texceptions.TemplateTypeException("Top level expression resulted in non-String value.", res.filepos, got=res)