# HG changeset patch
# User Christian Boos <cboos@bct-technology.com>
# Date 1205339881 -3600
# Node ID 7334686a938b90c35ef3cdc058ad7f007cb900bc
# Parent  fbf91c6896bdb00dd0bdb5a1e1c5206777b569f6
Avoid creating a big unicode string while rendering the stream.

We retrieve the generated content in chunks and encode it to UTF-8 directly.

diff -r fbf91c6896bd -r 7334686a938b trac/web/chrome.py
--- a/trac/web/chrome.py	Wed Mar 12 16:09:45 2008 +0100
+++ b/trac/web/chrome.py	Wed Mar 12 17:38:01 2008 +0100
@@ -19,6 +19,8 @@ import pkg_resources
 import pkg_resources
 import pprint
 import re
+
+from cStringIO import StringIO
 
 from genshi import Markup
 from genshi.builder import tag, Element
@@ -701,7 +703,10 @@ class Chrome(Component):
         })
 
         try:
-            return stream.render(method, doctype=doctype)
+            buffer = StringIO()
+            for chunk in stream.serialize(method, doctype=doctype):
+                buffer.write(chunk.encode('utf-8'))
+            return buffer.getvalue()
         except:
             # restore what may be needed by the error template
             req.chrome['links'] = links

