|
@@ -1,36 +1,17 @@
|
|
|
-import cgi
|
|
|
import os
|
|
|
import sys
|
|
|
from functools import partial
|
|
|
from random import randint
|
|
|
from weppy import App, request, response
|
|
|
-from weppy.dal import Model, Field, DAL, rowmethod
|
|
|
+from weppy.orm import Database, Model, Field, rowmethod
|
|
|
from weppy.tools import service
|
|
|
|
|
|
_is_pypy = hasattr(sys, 'pypy_version_info')
|
|
|
if sys.version_info[0] == 3:
|
|
|
xrange = range
|
|
|
|
|
|
-# NOTE on html escaping: weppy normally escapes every character to its ascii
|
|
|
-# html representation. The 'fortunes' test seems not to like that, so we
|
|
|
-# re-define the escaping only to the next characters
|
|
|
-# _html_escape_table = {
|
|
|
-# "&": "&",
|
|
|
-# '"': """,
|
|
|
-# "'": "'",
|
|
|
-# ">": ">",
|
|
|
-# "<": "<",
|
|
|
-# }
|
|
|
-
|
|
|
-
|
|
|
-def light_html_escape(text):
|
|
|
- # return "".join(_html_escape_table.get(c, c) for c in text)
|
|
|
- return cgi.escape(text, True).replace("'", "'")
|
|
|
-
|
|
|
-
|
|
|
DBHOSTNAME = os.environ.get('DBHOST', 'localhost')
|
|
|
|
|
|
-
|
|
|
app = App(__name__)
|
|
|
|
|
|
|
|
@@ -52,6 +33,7 @@ class Fortune(Model):
|
|
|
return {'id': row.id, 'message': row.message}
|
|
|
|
|
|
|
|
|
+app.config.handle_static = False
|
|
|
app.config.db.adapter = 'postgres:psycopg2' \
|
|
|
if not _is_pypy else 'postgres:pg8000'
|
|
|
app.config.db.host = DBHOSTNAME
|
|
@@ -60,7 +42,7 @@ app.config.db.password = 'benchmarkdbpass'
|
|
|
app.config.db.database = 'hello_world'
|
|
|
app.config.db.pool_size = 100
|
|
|
|
|
|
-db = DAL(app, auto_migrate=False)
|
|
|
+db = Database(app, auto_migrate=False)
|
|
|
db.define_models(World, Fortune)
|
|
|
|
|
|
|
|
@@ -70,7 +52,7 @@ def json():
|
|
|
return {'message': 'Hello, World!'}
|
|
|
|
|
|
|
|
|
[email protected]("/db", handlers=[db.handler])
|
|
|
[email protected]("/db", pipeline=[db.pipe])
|
|
|
@service.json
|
|
|
def get_random_world():
|
|
|
return World.get(randint(1, 10000)).serialize()
|
|
@@ -88,7 +70,7 @@ def get_qparam():
|
|
|
return rv
|
|
|
|
|
|
|
|
|
[email protected]("/queries", handlers=[db.handler])
|
|
|
[email protected]("/queries", pipeline=[db.pipe])
|
|
|
@service.json
|
|
|
def get_random_worlds():
|
|
|
num_queries = get_qparam()
|
|
@@ -97,16 +79,16 @@ def get_random_worlds():
|
|
|
return worlds
|
|
|
|
|
|
|
|
|
[email protected](handlers=[db.handler])
|
|
|
[email protected](pipeline=[db.pipe])
|
|
|
def fortunes():
|
|
|
fortunes = Fortune.all().select()
|
|
|
fortunes.append(
|
|
|
Fortune.new(id=0, message="Additional fortune added at request time."))
|
|
|
fortunes.sort(lambda m: m.message)
|
|
|
- return dict(fortunes=fortunes, escape=light_html_escape)
|
|
|
+ return {'fortunes': fortunes}
|
|
|
|
|
|
|
|
|
[email protected](handlers=[db.handler])
|
|
|
[email protected](pipeline=[db.pipe])
|
|
|
@service.json
|
|
|
def updates():
|
|
|
num_queries = get_qparam()
|