Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1313

Show
Ignore:
Timestamp:
09/02/06 03:40:14
Author:
fumanchu
Message:

Fix for # 255 (use output from tidy). Untested, but then it never was before. :/

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/lib/tidy.py

    r1281 r1313  
    77 
    88 
    9 def tidy(temp_dir, tidy_path, strict_xml=False, errors_to_ignore=None): 
     9def tidy(temp_dir, tidy_path, strict_xml=False, errors_to_ignore=None, 
     10         indent=False, wrap=False): 
    1011    """Run cherrypy.response through Tidy. 
     12     
     13    If either 'indent' or 'wrap' are specified, then response.body will be 
     14    set to the output of tidy. Otherwise, only errors will change the body. 
    1115     
    1216    Note that we use the standalone Tidy tool rather than the python 
     
    3741         
    3842        strict_xml = (" -xml", "")[bool(strict_xml)] 
    39         os.system('"%s" %s%s -f %s -o %s %s' % 
    40                   (tidy_path, tidy_enc, strict_xml, 
    41                    err_file, out_file, page_file)) 
    42         errs = open(err_file, 'rb').read() 
     43         
     44        if indent: 
     45            indent = ' -indent' 
     46        else: 
     47            index = '' 
     48         
     49        if wrap is False: 
     50            wrap = '' 
     51        else: 
     52            try: 
     53                wrap = ' -wrap %d' % int(tidyWrap) 
     54            except: 
     55                wrap = '' 
     56         
     57        result = os.system('"%s" %s%s%s%s -f %s -o %s %s' % 
     58                           (tidy_path, tidy_enc, strict_xml, indent, wrap, 
     59                            err_file, out_file, page_file)) 
     60        use_output = bool(indent or wrap) and not result 
     61        if use_output: 
     62            output = open(out_file, 'rb').read() 
    4363         
    4464        new_errs = [] 
    45         for err in errs.splitlines(): 
     65        for err in open(err_file, 'rb').read().splitlines(): 
    4666            if (err.find('Warning') != -1 or err.find('Error') != -1): 
    4767                ignore = 0 
     
    5676            cherrypy.response.body = wrong_content('<br />'.join(new_errs), 
    5777                                                   orig_body) 
     78            return 
    5879        elif strict_xml: 
    5980            # The HTML is OK, but is it valid XML? 
     
    7798                body_file = '<br />'.join(body_file.getvalue()) 
    7899                cherrypy.response.body = wrong_content(body_file, orig_body, "XML") 
     100                return 
     101         
     102        if use_output: 
     103            cherrypy.response.body = [output] 
    79104 
    80105def html_space(text): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets