Index: trac/mimeview/api.py
===================================================================
--- trac/mimeview/api.py	(revision 10169)
+++ trac/mimeview/api.py	(working copy)
@@ -811,7 +811,7 @@
                 annotators[atype] = annotator
 
         if isinstance(stream, list):
-            stream = HTMLParser(StringIO('\n'.join(stream)))
+            stream = HTMLParser(StringIO(u'\n'.join(stream)))
         elif isinstance(stream, unicode):
             text = stream
             def linesplitter():
Index: trac/mimeview/tests/api.py
===================================================================
--- trac/mimeview/tests/api.py	(revision 10169)
+++ trac/mimeview/tests/api.py	(working copy)
@@ -126,7 +126,7 @@
         self.assertEquals(lines[0].events, [(TEXT, "test", (None, -1, -1))])
 
     def test_simplespan(self):
-        input = HTMLParser(StringIO("<span>test</span>"))
+        input = HTMLParser(StringIO(u"<span>test</span>"), encoding=None)
         lines = list(_group_lines(input))
         self.assertEquals(len(lines), 1)
         self.assertTrue(isinstance(lines[0], Stream))
@@ -168,7 +168,8 @@
         If the text element does not end with a newline, it's not properly
         closed.
         """
-        input = HTMLParser(StringIO('<span class="c">a\nb</span>'))
+        input = HTMLParser(StringIO(u'<span class="c">a\nb</span>'),
+            encoding=None)
         expected = ['<span class="c">a</span>',
                     '<span class="c">b</span>',
                    ]
@@ -182,7 +183,8 @@
         Same as test_newline above, but make sure it behaves properly wrt
         the trailing \\n, especially given it's inside an element.
         """
-        input = HTMLParser(StringIO('<span class="c">a\nb\n</span>'))
+        input = HTMLParser(StringIO(u'<span class="c">a\nb\n</span>'),
+            encoding=None)
         expected = ['<span class="c">a</span>',
                     '<span class="c">b</span>',
                    ]
@@ -195,7 +197,8 @@
         """
         ditto.
         """
-        input = HTMLParser(StringIO('<span class="c">\n\n\na</span>'))
+        input = HTMLParser(StringIO(u'<span class="c">\n\n\na</span>'),
+            encoding=None)
         expected = ['<span class="c"></span>',
                     '<span class="c"></span>',
                     '<span class="c"></span>',
Index: trac/mimeview/tests/patch.py
===================================================================
--- trac/mimeview/tests/patch.py	(revision 10169)
+++ trac/mimeview/tests/patch.py	(working copy)
@@ -35,14 +35,14 @@
         self.patch = Mimeview(env).renderers[0]
         patch_html = open(os.path.join(os.path.split(__file__)[0],
                                        'patch.html'))
-        self.patch_html = Stream(list(HTMLParser(patch_html)))
+        self.patch_html = Stream(list(HTMLParser(patch_html, encoding='utf-8')))
 
     def _expected(self, expected_id):
         return self.patch_html.select('//div[@id="%s"]/div' % expected_id)
 
     def _test(self, expected_id, result):
-        expected = str(self._expected(expected_id))
-        result = str(XML(result))
+        expected = self._expected(expected_id).render(encoding='utf-8')
+        result = XML(result.render(encoding='utf-8')).render(encoding='utf-8')
         expected, result = expected.splitlines(), result.splitlines()
         for exp, res in zip(expected, result):
             self.assertEquals(exp, res)
Index: trac/mimeview/tests/pygments.py
===================================================================
--- trac/mimeview/tests/pygments.py	(revision 10169)
+++ trac/mimeview/tests/pygments.py	(working copy)
@@ -42,7 +42,7 @@
         self.context = Context.from_request(self.req)
         pygments_html = open(os.path.join(os.path.split(__file__)[0],
                                        'pygments.html'))
-        self.pygments_html = Stream(list(HTMLParser(pygments_html)))
+        self.pygments_html = Stream(list(HTMLParser(pygments_html, encoding='utf-8')))
 
     def _expected(self, expected_id):
         return self.pygments_html.select(
Index: trac/web/main.py
===================================================================
--- trac/web/main.py	(revision 10169)
+++ trac/web/main.py	(working copy)
@@ -696,10 +696,10 @@
             req.hdf['projects'] = projects
             req.display(template)
 
-        loader = TemplateLoader(loadpaths, variable_lookup='lenient')
+        loader = TemplateLoader(loadpaths, variable_lookup='lenient', encoding='utf-8')
         tmpl = loader.load(template)
         stream = tmpl.generate(**data)
-        output = stream.render('xhtml', doctype=DocType.XHTML_STRICT)
+        output = stream.render('xhtml', doctype=DocType.XHTML_STRICT, encoding='utf-8')
         req.send(output, 'text/html')
 
     except RequestDone:
Index: trac/notification.py
===================================================================
--- trac/notification.py	(revision 10169)
+++ trac/notification.py	(working copy)
@@ -399,7 +399,7 @@
         # don't translate the e-mail stream
         t = deactivate()
         try:
-            body = stream.render('text')
+            body = stream.render('text', encoding='utf-8')
         finally:
             reactivate(t)
         projname = self.env.project_name
