-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
213c6c5
commit 07c32b7
Showing
4 changed files
with
19 additions
and
82 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
# <!DOCTYPE html> | ||
# <html lang="en"> | ||
# <head> | ||
# <meta charset="UTF-8"> | ||
# <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
# <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
# <title>Document</title> | ||
# </head> | ||
# <body> | ||
# </body> | ||
# </html> | ||
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( | ||
# "<h1>${message}</h1><span><span classes=\"text-light align-left\">${left_message}</span><span classes=\"text-light align-right\">${right_message}</span></span>" | ||
# ) | ||
|
||
# from jinja2 import Environment, BaseLoader | ||
# rtemplate = Environment(loader=BaseLoader()).from_string("<h1>{{ message }}</h1><span><span classes=\"text-light align-left\">{{ left_message }}</span><span classes=\"text-light align-right\">{{ right_message }}</span></span>") | ||
|
||
# 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() |