# 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
|
b
|
|
| 19 | 19 | import pkg_resources |
| 20 | 20 | import pprint |
| 21 | 21 | import re |
| | 22 | |
| | 23 | from cStringIO import StringIO |
| 22 | 24 | |
| 23 | 25 | from genshi import Markup |
| 24 | 26 | from genshi.builder import tag, Element |
| … |
… |
|
| 701 | 703 | }) |
| 702 | 704 | |
| 703 | 705 | try: |
| 704 | | return stream.render(method, doctype=doctype) |
| | 706 | buffer = StringIO() |
| | 707 | for chunk in stream.serialize(method, doctype=doctype): |
| | 708 | buffer.write(chunk.encode('utf-8')) |
| | 709 | return buffer.getvalue() |
| 705 | 710 | except: |
| 706 | 711 | # restore what may be needed by the error template |
| 707 | 712 | req.chrome['links'] = links |