瀏覽代碼

Updated weppy framework to 1.0 (#2587)

* Updated weppy framework to 1.0

* Updated weppy to 1.0.1
Giovanni Barillari 8 年之前
父節點
當前提交
a2c7fc0212

+ 8 - 26
frameworks/Python/weppy/app.py

@@ -1,36 +1,17 @@
-import cgi
 import os
 import os
 import sys
 import sys
 from functools import partial
 from functools import partial
 from random import randint
 from random import randint
 from weppy import App, request, response
 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
 from weppy.tools import service
 
 
 _is_pypy = hasattr(sys, 'pypy_version_info')
 _is_pypy = hasattr(sys, 'pypy_version_info')
 if sys.version_info[0] == 3:
 if sys.version_info[0] == 3:
     xrange = range
     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 = {
-#     "&": "&",
-#     '"': """,
-#     "'": "'",
-#     ">": ">",
-#     "<": "&lt;",
-# }
-
-
-def light_html_escape(text):
-    # return "".join(_html_escape_table.get(c, c) for c in text)
-    return cgi.escape(text, True).replace("'", "&#x27;")
-
-
 DBHOSTNAME = os.environ.get('DBHOST', 'localhost')
 DBHOSTNAME = os.environ.get('DBHOST', 'localhost')
 
 
-
 app = App(__name__)
 app = App(__name__)
 
 
 
 
@@ -52,6 +33,7 @@ class Fortune(Model):
         return {'id': row.id, 'message': row.message}
         return {'id': row.id, 'message': row.message}
 
 
 
 
+app.config.handle_static = False
 app.config.db.adapter = 'postgres:psycopg2' \
 app.config.db.adapter = 'postgres:psycopg2' \
     if not _is_pypy else 'postgres:pg8000'
     if not _is_pypy else 'postgres:pg8000'
 app.config.db.host = DBHOSTNAME
 app.config.db.host = DBHOSTNAME
@@ -60,7 +42,7 @@ app.config.db.password = 'benchmarkdbpass'
 app.config.db.database = 'hello_world'
 app.config.db.database = 'hello_world'
 app.config.db.pool_size = 100
 app.config.db.pool_size = 100
 
 
-db = DAL(app, auto_migrate=False)
+db = Database(app, auto_migrate=False)
 db.define_models(World, Fortune)
 db.define_models(World, Fortune)
 
 
 
 
@@ -70,7 +52,7 @@ def json():
     return {'message': 'Hello, World!'}
     return {'message': 'Hello, World!'}
 
 
 
 
[email protected]("/db", handlers=[db.handler])
[email protected]("/db", pipeline=[db.pipe])
 @service.json
 @service.json
 def get_random_world():
 def get_random_world():
     return World.get(randint(1, 10000)).serialize()
     return World.get(randint(1, 10000)).serialize()
@@ -88,7 +70,7 @@ def get_qparam():
     return rv
     return rv
 
 
 
 
[email protected]("/queries", handlers=[db.handler])
[email protected]("/queries", pipeline=[db.pipe])
 @service.json
 @service.json
 def get_random_worlds():
 def get_random_worlds():
     num_queries = get_qparam()
     num_queries = get_qparam()
@@ -97,16 +79,16 @@ def get_random_worlds():
     return worlds
     return worlds
 
 
 
 
[email protected](handlers=[db.handler])
[email protected](pipeline=[db.pipe])
 def fortunes():
 def fortunes():
     fortunes = Fortune.all().select()
     fortunes = Fortune.all().select()
     fortunes.append(
     fortunes.append(
         Fortune.new(id=0, message="Additional fortune added at request time."))
         Fortune.new(id=0, message="Additional fortune added at request time."))
     fortunes.sort(lambda m: m.message)
     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
 @service.json
 def updates():
 def updates():
     num_queries = get_qparam()
     num_queries = get_qparam()

+ 1 - 1
frameworks/Python/weppy/requirements-pypy.txt

@@ -1,4 +1,4 @@
 pg8000==1.10.6
 pg8000==1.10.6
-weppy==0.8.4
+weppy==1.0.1
 gunicorn==19.4.5
 gunicorn==19.4.5
 tornado==4.3
 tornado==4.3

+ 1 - 1
frameworks/Python/weppy/requirements.txt

@@ -1,5 +1,5 @@
 psycopg2==2.6.1
 psycopg2==2.6.1
-weppy==0.8.4
+weppy==1.0.1
 gunicorn==19.4.5
 gunicorn==19.4.5
 meinheld==0.6.1
 meinheld==0.6.1
 uwsgi==2.0.12
 uwsgi==2.0.12

+ 1 - 1
frameworks/Python/weppy/templates/fortunes.html

@@ -12,7 +12,7 @@
             {{for fortune in fortunes:}}
             {{for fortune in fortunes:}}
             <tr>
             <tr>
                 <td>{{=fortune.id}}</td>
                 <td>{{=fortune.id}}</td>
-                <td>{{=asis(escape(fortune.message))}}</td>
+                <td>{{=fortune.message}}</td>
             </tr>
             </tr>
             {{pass}}
             {{pass}}
         </table>
         </table>