Browse Source

Merge branch 'fix-wheezy' of https://github.com/methane/FrameworkBenchmarks

blee-techempower 9 years ago
parent
commit
f240abdf42

+ 3 - 2
frameworks/Python/cherrypy/app.py

@@ -1,10 +1,10 @@
+import cgi
 import os
 import os
 import sys
 import sys
 from functools import partial
 from functools import partial
 from operator import attrgetter
 from operator import attrgetter
 from random import randint
 from random import randint
 import json
 import json
-import bleach
 
 
 import cherrypy
 import cherrypy
 from sqlalchemy.ext.declarative import declarative_base
 from sqlalchemy.ext.declarative import declarative_base
@@ -59,6 +59,7 @@ class CherryPyBenchmark(object):
 
 
     @cherrypy.expose
     @cherrypy.expose
     def plaintext(self):
     def plaintext(self):
+        cherrypy.response.headers["Content-Type"] = "text/plain"
         return "Hello, world!"
         return "Hello, world!"
 
 
     @cherrypy.expose
     @cherrypy.expose
@@ -111,7 +112,7 @@ class CherryPyBenchmark(object):
         fortunes.sort(key=attrgetter("message"))
         fortunes.sort(key=attrgetter("message"))
         html = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>"
         html = "<!DOCTYPE html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>"
         for f in fortunes:
         for f in fortunes:
-            html += "<tr><td>" + str(f.id) + "</td><td>" + bleach.clean(f.message) + "</td></tr>"
+            html += "<tr><td>" + str(f.id) + "</td><td>" + cgi.escape(f.message) + "</td></tr>"
         html += "</table></body></html>"
         html += "</table></body></html>"
         return html
         return html
 
 

+ 0 - 3
frameworks/Python/cherrypy/requirements.txt

@@ -1,6 +1,3 @@
 cherrypy==3.7.0
 cherrypy==3.7.0
-
-bleach==1.4.1
-
 SQLAlchemy==1.0.4
 SQLAlchemy==1.0.4
 mysqlclient==1.3.6
 mysqlclient==1.3.6

+ 2 - 2
frameworks/Python/historical/webware/app/Context/fortune.py

@@ -1,5 +1,5 @@
+import cgi
 import json
 import json
-import bleach
 from random import randint
 from random import randint
 from operator import attrgetter
 from operator import attrgetter
 
 
@@ -16,7 +16,7 @@ class fortune(Page):
                 fortunes.append(AFortune(id=0, message="Additional fortune added at request time."))
                 fortunes.append(AFortune(id=0, message="Additional fortune added at request time."))
                 fortunes.sort(key=attrgetter("message"))
                 fortunes.sort(key=attrgetter("message"))
                 for fortune in fortunes:
                 for fortune in fortunes:
-                        message = bleach.clean(fortune.message)
+                        message = cgi.escape(fortune.message)
                         output += "<tr><td>%s</td><td>%s</td></tr>" % (fortune.id , message.encode("utf-8"))
                         output += "<tr><td>%s</td><td>%s</td></tr>" % (fortune.id , message.encode("utf-8"))
                 output += "</table></body></html>"
                 output += "</table></body></html>"
                 self.response()._headers["Content-Length"] = len(output)
                 self.response()._headers["Content-Length"] = len(output)

+ 0 - 1
frameworks/Python/historical/webware/requirements.txt

@@ -1,3 +1,2 @@
-bleach==1.4.1
 mysqlclient==1.3.6
 mysqlclient==1.3.6
 SQLAlchemy==1.0.4
 SQLAlchemy==1.0.4

+ 17 - 7
frameworks/Python/wheezyweb/app.py

@@ -1,11 +1,10 @@
+import cgi
 import os
 import os
 import sys
 import sys
 from functools import partial
 from functools import partial
 from operator import attrgetter
 from operator import attrgetter
 from random import randint
 from random import randint
 
 
-import bleach
-
 from wheezy.http import HTTPResponse
 from wheezy.http import HTTPResponse
 from wheezy.http import WSGIApplication
 from wheezy.http import WSGIApplication
 from wheezy.routing import url
 from wheezy.routing import url
@@ -109,15 +108,16 @@ class UpdatesHandler(BaseHandler):
         db_session.commit()
         db_session.commit()
         return self.json_response(worlds)
         return self.json_response(worlds)
 
 
+
+template_engine = Engine(loader=FileLoader(["views"]), extensions=[CoreExtension()])
+template_engine.global_vars['escape'] = cgi.escape
+
 class FortuneHandler(BaseHandler):
 class FortuneHandler(BaseHandler):
     def get(self):
     def get(self):
         fortunes = db_session.query(Fortune).all()
         fortunes = db_session.query(Fortune).all()
         fortunes.append(Fortune(id=0, message="Additional fortune added at request time."))
         fortunes.append(Fortune(id=0, message="Additional fortune added at request time."))
         fortunes.sort(key=attrgetter("message"))
         fortunes.sort(key=attrgetter("message"))
-        engine = Engine(loader=FileLoader(["views"]), extensions=[CoreExtension()])
-        template = engine.get_template("fortune.html")
-        for f in fortunes:
-            f.message = bleach.clean(f.message)
+        template = template_engine.get_template("fortune.html")
         template_html = template.render({"fortunes": fortunes})		
         template_html = template.render({"fortunes": fortunes})		
 
 
         response = HTTPResponse()
         response = HTTPResponse()
@@ -130,6 +130,15 @@ def plaintext(request):
     response.write("Hello, world!")
     response.write("Hello, world!")
     return response
     return response
 
 
+
+def sqlalchemy_close_middleware(request, following):
+    """Close db_session for each request"""
+    try:
+        return following(request)
+    finally:
+        db_session.remove()
+
+
 all_urls = [
 all_urls = [
     url("plaintext", plaintext, name="plaintext"),
     url("plaintext", plaintext, name="plaintext"),
     url("json", JsonHandler, name="json"),
     url("json", JsonHandler, name="json"),
@@ -144,7 +153,8 @@ options = {}
 app = WSGIApplication(
 app = WSGIApplication(
     middleware = [
     middleware = [
         bootstrap_defaults(url_mapping=all_urls),
         bootstrap_defaults(url_mapping=all_urls),
-        path_routing_middleware_factory
+        path_routing_middleware_factory,
+        lambda _: sqlalchemy_close_middleware,
     ],
     ],
     options = options
     options = options
 )
 )

+ 0 - 2
frameworks/Python/wheezyweb/requirements.txt

@@ -1,8 +1,6 @@
 wheezy.web==0.1.485
 wheezy.web==0.1.485
 wheezy.template==0.1.167
 wheezy.template==0.1.167
 
 
-bleach==1.4.1
-
 SQLAlchemy==1.0.4
 SQLAlchemy==1.0.4
 mysqlclient==1.3.6
 mysqlclient==1.3.6
 
 

+ 1 - 1
frameworks/Python/wheezyweb/views/fortune.html

@@ -13,7 +13,7 @@
 @for fortune in fortunes:
 @for fortune in fortunes:
 <tr>
 <tr>
 <td>@str(fortune.id)</td>
 <td>@str(fortune.id)</td>
-<td>@fortune.message</td>
+<td>@{fortune.message !! escape}</td>
 </tr>
 </tr>
 @end
 @end
 </table>
 </table>