kopia lustrzana https://github.com/cirospaciari/socketify.py
rodzic
213c6c5384
commit
07c32b7f77
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 51 KiB Po Szerokość: | Wysokość: | Rozmiar: 50 KiB |
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 32 KiB Po Szerokość: | Wysokość: | Rozmiar: 42 KiB |
Plik binarny nie jest wyświetlany.
Przed Szerokość: | Wysokość: | Rozmiar: 53 KiB Po Szerokość: | Wysokość: | Rozmiar: 52 KiB |
101
src/tests.py
101
src/tests.py
|
@ -1,89 +1,26 @@
|
||||||
from socketify.template import *
|
from socketify import App
|
||||||
|
|
||||||
# https://github.com/chtd/psycopg2cffi/
|
app = App()
|
||||||
# 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
|
|
||||||
|
|
||||||
# @memo() # generate an static string after first execution aka skipping re-rendering when props are unchanged
|
def extension(request, response, ws):
|
||||||
# def title(message):
|
|
||||||
# return h1(message, classes="title-light")
|
|
||||||
|
|
||||||
# @memo(maxsize=128)
|
@request.method
|
||||||
def htemplate(message, left_message, right_message):
|
async def get_user(self):
|
||||||
|
token = self.get_header("token")
|
||||||
|
self.token = token
|
||||||
|
return { "name": "Test" } if token else { "name", "Anonymous" }
|
||||||
|
|
||||||
return (
|
@request.method
|
||||||
h1(message),
|
async def get_cart(self):
|
||||||
span(
|
return [{ "quantity": 10, "name": "T-Shirt" }]
|
||||||
children=(
|
|
||||||
span(left_message, classes=("text-light", "align-left")),
|
|
||||||
span(right_message, classes=("text-light", "align-right")),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
request.property("token", None)
|
||||||
|
|
||||||
# <!DOCTYPE html>
|
app.register(extension)
|
||||||
# <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()
|
|
||||||
))
|
|
||||||
)
|
|
||||||
|
|
||||||
# print(render_tostring(html5()))
|
app.get("/", lambda res, req: res.end("Hello World!"))
|
||||||
# from mako.template import Template
|
app.listen(
|
||||||
|
3000,
|
||||||
# template = Template(
|
lambda config: print("Listening on port http://localhost:%d now\n" % config.port),
|
||||||
# "<h1>${message}</h1><span><span classes=\"text-light align-left\">${left_message}</span><span classes=\"text-light align-right\">${right_message}</span></span>"
|
)
|
||||||
# )
|
app.run()
|
||||||
|
|
||||||
# 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",
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
|
|
Ładowanie…
Reference in New Issue