Changeset 1313
- Timestamp:
- 09/02/06 03:40:14
- Files:
-
- trunk/cherrypy/lib/tidy.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/tidy.py
r1281 r1313 7 7 8 8 9 def tidy(temp_dir, tidy_path, strict_xml=False, errors_to_ignore=None): 9 def tidy(temp_dir, tidy_path, strict_xml=False, errors_to_ignore=None, 10 indent=False, wrap=False): 10 11 """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. 11 15 12 16 Note that we use the standalone Tidy tool rather than the python … … 37 41 38 42 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() 43 63 44 64 new_errs = [] 45 for err in errs.splitlines():65 for err in open(err_file, 'rb').read().splitlines(): 46 66 if (err.find('Warning') != -1 or err.find('Error') != -1): 47 67 ignore = 0 … … 56 76 cherrypy.response.body = wrong_content('<br />'.join(new_errs), 57 77 orig_body) 78 return 58 79 elif strict_xml: 59 80 # The HTML is OK, but is it valid XML? … … 77 98 body_file = '<br />'.join(body_file.getvalue()) 78 99 cherrypy.response.body = wrong_content(body_file, orig_body, "XML") 100 return 101 102 if use_output: 103 cherrypy.response.body = [output] 79 104 80 105 def html_space(text):

