Forráskód Böngészése

[Python] socketify send and asgi lifespan (#7851)

* Added a benchmark test for the socketify.py Python/PyPy web framework

* removed alpine docker

* updated readme.md

* No need to manually add Date header anymore on Socketify.py

* updated socketify.py benchmark to use object factories to increase performance

* add object factory to app-python3.py in socketify

* [Python] Update socketify.py with ASGI and SSGI, add Falcon ASGI SSGI with socketify.py

* fix merge erros

* remove \n from plaintext in socketify.py-wsgi plaintext

* add socketify send and asgi without lifespan
Ciro Spaciari 2 éve
szülő
commit
ddafe636fb

+ 5 - 8
frameworks/Python/socketify.py/app-python3.py

@@ -1,23 +1,20 @@
 
 import os
 
-from ujson import dumps as json
+import ujson
 
 from socketify import App
 
 def plaintext(res, req):
-    res.write_header("Server", "socketify")
-    res.write_header("Content-Type", "text/plain")
-    res.end(b'Hello, World!')
+    res.send(b'Hello, World!')
 
 def applicationjson(res, req):
-    res.write_header("Server", "socketify")
-    res.write_header("Content-Type", "application/json")
-    res.end(json({"message":"Hello, World!"}))
+    res.send({"message":"Hello, World!"})
 
 
 def run_app():
-    app = app = App(None, 200_000, 0)
+    app = App(None, 200_000, 0)
+    app.json_serializer(ujson)
     app.get("/", plaintext)
     app.get("/json", applicationjson)
     app.get("/plaintext", plaintext)

+ 2 - 5
frameworks/Python/socketify.py/app.py

@@ -5,13 +5,10 @@ from socketify import App
 
 
 def plaintext(res, req):
-    res.write_header("Server", "socketify")
-    res.write_header("Content-Type", "text/plain")
-    res.end(b'Hello, World!')
+    res.send(b'Hello, World!')
 
 def applicationjson(res, req):
-    res.write_header("Server", "socketify")
-    res.end({"message":"Hello, World!"})
+    res.send({"message":"Hello, World!"})
 
 
 def run_app():

+ 1 - 1
frameworks/Python/socketify.py/raw-asgi.py

@@ -37,7 +37,7 @@ async def app(scope, receive, send):
 
 
 def run_app():
-    ASGI(app).listen(3000, lambda config: print(f"Listening on port http://localhost:{config.port} now\n")).run()
+    ASGI(app,lifespan=False).listen(3000, lambda config: print(f"Listening on port http://localhost:{config.port} now\n")).run()
 
 def create_fork():
     n = os.fork()