changeset 513:1c9250cc4365 stable-0.4.x

Ported [616] to 0.4.x branch.
author cmlenz
date Wed, 06 Jun 2007 11:33:23 +0000
parents 1a29617a5d87
children c8b6d3c0d389
files ChangeLog genshi/template/tests/text.py genshi/template/text.py
diffstat 3 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,7 @@
    of the doctype as string, in addition to the `(name, pubid, sysid)` tuple.
  * The I18n filter was not replacing the original attributes with the
    translation, but instead adding a second attribute with the same name.
+ * `TextTemplate` can now handle unicode source (ticket #125).
 
 
 Version 0.4.1
--- a/genshi/template/tests/text.py
+++ b/genshi/template/tests/text.py
@@ -44,6 +44,11 @@
         tmpl = TextTemplate(text, encoding='iso-8859-1')
         self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y')))
 
+    def test_unicode_input(self):
+        text = u'$foo\xf6$bar'
+        tmpl = TextTemplate(text)
+        self.assertEqual(u'x\xf6y', unicode(tmpl.generate(foo='x', bar='y')))
+
     def test_empty_lines1(self):
         tmpl = TextTemplate("""Your items:
 
--- a/genshi/template/text.py
+++ b/genshi/template/text.py
@@ -63,10 +63,10 @@
         stream = [] # list of events of the "compiled" template
         dirmap = {} # temporary mapping of directives to elements
         depth = 0
-        if not encoding:
-            encoding = 'utf-8'
 
-        source = source.read().decode(encoding, 'replace')
+        source = source.read()
+        if isinstance(source, str):
+            source = source.decode(encoding or 'utf-8', 'replace')
         offset = 0
         lineno = 1
 
Copyright (C) 2012-2017 Edgewall Software