Commits

Remi Delon  committed 38c5c72

Couple of small bugfixes. Fixed ticket #170

  • Participants
  • Parent commits 7c60071
  • Branches cherrypy

Comments (0)

Files changed (3)

File _cpconfig.py

 def outputConfigMap():
     _cpLogMessage = _cputil.getSpecialFunction('_cpLogMessage')
     _cpLogMessage("Server parameters:", 'CONFIG')
-    _cpLogMessage("  server.environment: %s" % cpg.config.get('server.env'), 'CONFIG')
+    _cpLogMessage("  server.environment: %s" % cpg.config.get('server.environment'), 'CONFIG')
     _cpLogMessage("  server.logToScreen: %s" % cpg.config.get('server.logToScreen'), 'CONFIG')
     _cpLogMessage("  server.logFile: %s" % cpg.config.get('server.logFile'), 'CONFIG')
     _cpLogMessage("  server.protocolVersion: %s" % cpg.config.get('server.protocolVersion'), 'CONFIG')

File lib/filter/logdebuginfofilter.py

         cpg.request.startBuilTime = time.time()
     
     def beforeFinalize(self):
-        if cpg.config.get('server.environment') == 'dev':
+        if cpg.config.get('server.environment') == 'development':
             # In "dev" environment, log everything by default
             defaultOn = True
         else:

File lib/filter/tidyfilter.py

         originalBody = ''.join(cpg.response.body)
         cpg.response.body = [originalBody]
         
-        ct = cpg.response.headerMap.get('Content-Type', '').split(';')[0]
+        fct = cpg.response.headerMap.get('Content-Type', '')
+        ct = fct.split(';')[0]
         if ct == 'text/html':
             tmpdir = cpg.config.get('tidyFilter.tmpDir')
             pageFile = os.path.join(tmpdir, 'page.html')
             f.write(originalBody)
             f.close()
             encoding = ''
-            i = ct.find('charset=')
+            i = fct.find('charset=')
             if i != -1:
                 encoding = fct[i+8:]
-            encoding = encoding.replace('utf-8', 'utf8')
+            encoding = encoding.replace('-', '')
             if encoding:
                 encoding = '-' + encoding
             
                         newErrList.append(err)
             
             if newErrList:
-                newBody = "Wrong HTML:<br>" + cgi.escape('\n'.join(newErrList)).replace('\n','<br>')
-                newBody += '<br><br>'
+                newBody = "Wrong HTML:<br />" + cgi.escape('\n'.join(newErrList)).replace('\n','<br />')
+                newBody += '<br /><br />'
                 i = 0
                 for line in originalBody.splitlines():
                     i += 1
-                    newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br>'
+                    newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br />'
                 
                 cpg.response.body = [newBody]
 
                 # The HTML is OK, but is it valid XML
                 # Use elementtree to parse XML
                 from elementtree.ElementTree import parse
-                f = StringIO.StringIO(originalBody.replace('&nbsp;', 'NBSP'))
+                tagList = ['nbsp', 'quot']
+                for tag in tagList:
+                    originalBody = originalBody.replace(
+                        '&' + tag + ';', tag.upper())
+
+                if encoding:
+                    originalBody = """<?xml version="1.0" encoding="%s"?>""" % encoding[1:] + originalBody
+                f = StringIO.StringIO(originalBody)
                 try:
                     tree = parse(f)
                 except:
                     traceback.print_exc(file = bodyFile)
                     cpg.response.body = [bodyFile.getvalue()]
                     
-                    newBody = "Wrong XML:<br>" + cgi.escape(bodyFile.getvalue().replace('\n','<br>'))
-                    newBody += '<br><br>'
+                    newBody = "Wrong XML:<br />" + cgi.escape(bodyFile.getvalue().replace('\n','<br />'))
+                    newBody += '<br /><br />'
                     i = 0
                     for line in originalBody.splitlines():
                         i += 1
-                        newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br>'
+                        newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br />'
                     
                     cpg.response.body = [newBody]