Index: genshi/template/tests/text.py
===================================================================
--- genshi/template/tests/text.py	(revision 611)
+++ genshi/template/tests/text.py	(working copy)
@@ -54,6 +54,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:
 
Index: genshi/template/text.py
===================================================================
--- genshi/template/text.py	(revision 611)
+++ genshi/template/text.py	(working copy)
@@ -64,10 +64,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
 
