Edgewall Software

Changeset 6692

Show
Ignore:
Timestamp:
03/13/2008 08:48:47 PM (7 months ago)
Author:
cboos
Message:

Render using a cStringIO buffer if [Genshi 804] is available, as this is more memory efficient.

The rendering done without a cStringIO can be removed once we depend on Genshi 0.5. We might want to re-add it in the future once we get rid of our memory issues, as using the cStringIO way seems to be a bit slower.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/trac/web/chrome.py

    r6654 r6692  
    2020import pprint 
    2121import re 
     22try:  
     23    from cStringIO import StringIO as cStringIO  
     24except ImportError:  
     25    cStringIO = StringIO  
    2226 
    2327from genshi import Markup 
     
    3539from trac.resource import * 
    3640from trac.util import compat, get_reporter_id, presentation, get_pkginfo, \ 
    37                       get_module_path, translation 
     41                      get_module_path, translation, arity 
    3842from trac.util.compat import partial, set 
    3943from trac.util.html import plaintext 
     
    683687 
    684688        if method == 'text': 
    685             return stream.render('text') 
     689            if arity(stream.render) == 3: 
     690                # TODO: remove this when we depend on Genshi >= 0.5 
     691                return stream.render('text') 
     692            else: 
     693                buffer = cStringIO() 
     694                stream.render('text', out=buffer) 
     695                return buffer.getvalue() 
    686696 
    687697        doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type) 
     
    702712 
    703713        try: 
    704             return stream.render(method, doctype=doctype) 
     714            if arity(stream.render) == 3: 
     715                # TODO: remove this when we depend on Genshi >= 0.5 
     716                return stream.render(method, doctype=doctype) 
     717            else: 
     718                buffer = cStringIO() 
     719                stream.render('xhtml', doctype=doctype, out=buffer) 
     720                return buffer.getvalue() 
    705721        except: 
    706722            # restore what may be needed by the error template