home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_1466 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.6 KB  |  94 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import cgi
  5. import os
  6. import StringIO
  7. import traceback
  8. import cherrypy
  9.  
  10. def tidy(temp_dir, tidy_path, strict_xml = False, errors_to_ignore = None, indent = False, wrap = False, warnings = True):
  11.     response = cherrypy.response
  12.     orig_body = response.collapse_body()
  13.     fct = response.headers.get('Content-Type', '')
  14.     ct = fct.split(';')[0]
  15.     encoding = ''
  16.     i = fct.find('charset=')
  17.     if i != -1:
  18.         encoding = fct[i + 8:]
  19.     
  20.     if use_output:
  21.         response.body = [
  22.             output]
  23.         if response.headers.has_key('Content-Length'):
  24.             del response.headers['Content-Length']
  25.         
  26.     
  27.     ct == 'text/html' if ct == 'text/html' else new_errs
  28.  
  29.  
  30. def html_space(text):
  31.     return cgi.escape(text).replace('\t', '    ').replace(' ', ' ')
  32.  
  33.  
  34. def html_break(text):
  35.     return cgi.escape(text).replace('\n', '<br />')
  36.  
  37.  
  38. def wrong_content(header, body, content_type = 'HTML'):
  39.     output = [
  40.         'Wrong %s:<br />%s<br />' % (content_type, html_break(header))]
  41.     for i, line in enumerate(body.splitlines()):
  42.         output.append('%03d - %s' % (i + 1, html_space(line)))
  43.     
  44.     return '<br />'.join(output)
  45.  
  46.  
  47. def nsgmls(temp_dir, nsgmls_path, catalog_path, errors_to_ignore = None):
  48.     response = cherrypy.response
  49.     orig_body = response.collapse_body()
  50.     fct = response.headers.get('Content-Type', '')
  51.     ct = fct.split(';')[0]
  52.     encoding = ''
  53.     i = fct.find('charset=')
  54.     if i != -1:
  55.         encoding = fct[i + 8:]
  56.     
  57.     if ct == 'text/html':
  58.         while True:
  59.             i = orig_body.find('<script')
  60.             if i == -1:
  61.                 break
  62.             
  63.             j = orig_body.find('</script>', i)
  64.             if j == -1:
  65.                 break
  66.             
  67.             orig_body = orig_body[:i] + orig_body[j + 9:]
  68.         page_file = os.path.join(temp_dir, 'page.html')
  69.         open(page_file, 'wb').write(orig_body)
  70.         err_file = os.path.join(temp_dir, 'nsgmls.err')
  71.         command = '%s -c%s -f%s -s -E10 %s' % (nsgmls_path, catalog_path, err_file, page_file)
  72.         command = command.replace('\\', '/')
  73.         os.system(command)
  74.         errs = open(err_file, 'rb').read()
  75.         new_errs = []
  76.         for err in errs.splitlines():
  77.             ignore = False
  78.             for err_ign in []:
  79.                 if err.find(err_ign) != -1:
  80.                     ignore = True
  81.                     break
  82.                     continue
  83.         elif not ignore:
  84.             new_errs.append(err)
  85.             continue
  86.     if new_errs:
  87.         response.body = wrong_content('<br />'.join(new_errs), orig_body)
  88.         if response.headers.has_key('Content-Length'):
  89.             del response.headers['Content-Length']
  90.         
  91.     
  92.     new_errs
  93.  
  94.