Commits

Anonymous committed 120ac1d

small fixes for new cpg.response.body iterable type; getting ready for 2.0.0b release

Comments (0)

Files changed (4)

-__version__ = '2.0.0a2'
+__version__ = '2.0.0b'
                 _cputil.getSpecialFunction('_cpSaveSessionData')(sessionId, cpg.request.sessionMap, expirationTime)
 
             wfile.write('%s %s\r\n' % (cpg.response.headerMap['protocolVersion'], cpg.response.headerMap['Status']))
-            if cpg.response.headerMap.has_key('Content-Length') and cpg.response.headerMap['Content-Length'] == 0:
-                cpg.response.headerMap['Content-Length'] = len(cpg.response.body)
+
+            if (cpg.response.headerMap.has_key('Content-Length') and
+                    cpg.response.headerMap['Content-Length']==0):
+  	 	        buf = StringIO.StringIO()
+  	 	        [buf.write(x) for x in cpg.response.body]
+  	 	        buf.seek(0)
+  	 	        cpg.response.body = [buf.read()]
+  	 	        cpg.response.headerMap['Content-Length'] = len(cpg.response.body[0])
+
             for key, valueList in cpg.response.headerMap.items():
                 if key not in ('Status', 'protocolVersion'):
                     if type(valueList) != type([]): valueList = [valueList]
                     for value in valueList:
                         wfile.write('%s: %s\r\n'%(key, value))
             wfile.write('\r\n')
-            wfile.write(cpg.response.body)
+            for line in cpg.response.body:
+                wfile.write(line)
         except:
             bodyFile = StringIO.StringIO()
             traceback.print_exc(file = bodyFile)
 
     # Set the content-length
     if (cpg.response.headerMap.has_key('Content-Length') and
-        cpg.response.headerMap['Content-Length']==0):
-        #body = "" 
-        #body = ''.join(list(cpg.response.body))  # a local var is more efficient here
-        #body = u''.join(cpg.response.body)  # a local var is more efficient here
-        #body = ''
-        #for line in cpg.response.body:
-        #    print body
-        #    body += line
+            cpg.response.headerMap['Content-Length']==0):
         buf = StringIO.StringIO()
         [buf.write(x) for x in cpg.response.body]
         buf.seek(0)

lib/filter/tidyfilter.py

         # the tidy filter, by its very nature it's not generator friendly, 
         # so we just collect the body and work with it.
         originalBody = ''.join(cpg.response.body)
+        cpg.response.body = [originalBody]
         
-        ct = cpg.response.headerMap.get('Content-Type')
+        ct = cpg.response.headerMap.get('Content-Type').split(';')[0]
         if ct == 'text/html':
             pageFile = os.path.join(self.tmpDir, 'page.html')
             outFile = os.path.join(self.tmpDir, 'tidy.out')
                 newBody = "Wrong HTML:<br>" + cgi.escape('\n'.join(newErrList)).replace('\n','<br>')
                 newBody += '<br><br>'
                 i=0
-                for line in oldHtml.splitlines():
+                for line in originalBody.splitlines():
                     i += 1
                     newBody += "%03d - "%i + cgi.escape(line).replace('\t','    ').replace(' ','&nbsp;') + '<br>'
 
             newUrl = cpg.request.browserUrl[:i+1] + newUrl
     cpg.response.headerMap['Status'] = 302
     cpg.response.headerMap['Location'] = newUrl
-    return ""
+    return []
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.