diff --git a/misc/bench-bar-graph-asgi.png b/misc/bench-bar-graph-asgi.png index 82ff921..f1bc29d 100644 Binary files a/misc/bench-bar-graph-asgi.png and b/misc/bench-bar-graph-asgi.png differ diff --git a/misc/bench-bar-graph-general.png b/misc/bench-bar-graph-general.png index 8799942..2e898c7 100644 Binary files a/misc/bench-bar-graph-general.png and b/misc/bench-bar-graph-general.png differ diff --git a/misc/bench-bar-graph-wsgi.png b/misc/bench-bar-graph-wsgi.png index e905b22..5755334 100644 Binary files a/misc/bench-bar-graph-wsgi.png and b/misc/bench-bar-graph-wsgi.png differ diff --git a/src/tests.py b/src/tests.py index 3e94066..af60a13 100644 --- a/src/tests.py +++ b/src/tests.py @@ -1,89 +1,26 @@ -from socketify.template import * +from socketify import App -# https://github.com/chtd/psycopg2cffi/ -# https://github.com/tlocke/pg8000 -# https://www.psycopg.org/docs/advanced.html#asynchronous-support (works in cffi version too) -# https://github.com/sass/libsass-python +app = App() -# @memo() # generate an static string after first execution aka skipping re-rendering when props are unchanged -# def title(message): -# return h1(message, classes="title-light") +def extension(request, response, ws): -# @memo(maxsize=128) -def htemplate(message, left_message, right_message): + @request.method + async def get_user(self): + token = self.get_header("token") + self.token = token + return { "name": "Test" } if token else { "name", "Anonymous" } - return ( - h1(message), - span( - children=( - span(left_message, classes=("text-light", "align-left")), - span(right_message, classes=("text-light", "align-right")), - ), - ), - ) + @request.method + async def get_cart(self): + return [{ "quantity": 10, "name": "T-Shirt" }] + request.property("token", None) -# -# -# -# -# -# -# Document -# -# -# -# -def html5(): - return ( - doctype(), - html(lang="en", children=( - head(children=( - # meta(charset="UTF-8") - # meta(http_equiv="X-UA-Compatible",content="IE=edge") - # meta(name="vieport",content="width=device-width, initial-scale=1.0") - title("Document") - )), - body() - )) - ) +app.register(extension) -# print(render_tostring(html5())) -# from mako.template import Template - -# template = Template( -# "

${message}

${left_message}${right_message}" -# ) - -# from jinja2 import Environment, BaseLoader -# rtemplate = Environment(loader=BaseLoader()).from_string("

{{ message }}

{{ left_message }}{{ right_message }}") - -# print( -# render_tostring(htemplate( -# message="Hello, World!", -# left_message="Text in Left", -# right_message="Text in Right", -# )) -# ) -# print( -# render_tostring(htemplate( -# message="Hello, World!", -# left_message="Text in Left", -# right_message="Text in Right", -# )) -# ) - -# for i in range(1_000_000): -# render_tostring(htemplate(message="Hello, World!", left_message="Text in Left", right_message="Text in Right")) - # template.render(message="Hello, World!", left_message="Text in Left", right_message="Text in Right") - # rtemplate.render(message="Hello, World!", left_message="Text in Left", right_message="Text in Right") - -# print( -# render( -# html( -# message="Hello, World!", -# left_message="Text in Left", -# right_message="Text in Right", -# ) -# ) -# ) +app.get("/", lambda res, req: res.end("Hello World!")) +app.listen( + 3000, + lambda config: print("Listening on port http://localhost:%d now\n" % config.port), +) +app.run()