Skip to content

Commit

Permalink
should work ootb (py>3.7)
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Jun 3, 2024
1 parent 866e158 commit 2d958aa
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/on_commit_do_all_unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, "3.10" ,"3.11"]
# python-version: [ 3.7, 3.8, 3.9, "3.10" ,"3.11"]
python-version: [ 3.8, 3.9, "3.10" ,"3.11"]

steps:
- uses: actions/checkout@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ Process live as long as the server live
**Features**

* based on [starlette](https://pypi.org/project/starlette/)
* use session (in file)
* use session
* compatible with **uvloop** !!!
* compatible with multiple gunicorn/uvicorn/webworkers !!!
* compatible with [tag.update()](https://manatlan.github.io/htag/tag_update/)
* works on gnu/linux, ios ~~or windows~~ (from py3.7 to py3.11)!
* works on gnu/linux, ios ~~or windows~~ (from py3.8 to py3.11)! (**not py3.7 anymore ;-(**)
* real starlette session available (in tag.state, and starlette request.session)
* compatible with oauth2 authent ( [authlib](https://pypi.org/project/Authlib/) )
* 'parano mode' (can aes encrypt all communications between client & server ... to avoid mitm'proxies on ws/http interactions)
Expand Down
16 changes: 11 additions & 5 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def clllll(o):
self <= Tag.button("X",_onclick=lambda o: self.exit(),_style="float:right")
self <= TagSession()

self+=Tag.li(Tag.a("t0",_href="/"))
self+=Tag.li(Tag.a("t1",_href="/?v=1"))
self+=Tag.li(Tag.a("t2",_href="/?v=2"))
self+=Tag.li(Tag.a("Other app",_href="/jo"))
self+=Tag.li(Tag.a("t0",_href="/")) # \
self+=Tag.li(Tag.a("t1",_href="/?v=1")) # |---> recreate the same app (param change)
self+=Tag.li(Tag.a("t2",_href="/?v=2")) # /
self+=Tag.li(Tag.a("Other app",_href="/jo")) # test an app with hhtp only, and parano mode
self+=Tag.li(Tag.a("kaputt",_href="/kaputt")) # test a broken file app
self+=self.place


Expand All @@ -82,14 +83,19 @@ def test(o):

async def serve(req):
return await req.app.handle(req,Jo,http_only=True,parano=True)

async def serve_kaputt(req):
return await req.app.handle(req, "examples.kaputt.App" )

#------------------------------------------------------
from htagweb import Runner
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
# **IMPORTANT** current host serving on SSL
# on your localmachine, switch ssl to False !!!
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
app=Runner( App, debug=True, ssl=True )
app=Runner( App, debug=False, ssl=True )
app.add_route("/jo", serve)
app.add_route("/kaputt", serve_kaputt)

if __name__=="__main__":
#~ import logging
Expand Down
4 changes: 4 additions & 0 deletions examples/kaputt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# -*- coding: utf-8 -*-

NOT A REAL PYTHON FILE (for unitests)
7 changes: 5 additions & 2 deletions htagweb/hrprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ def destroy():
coro=sys.hr.interact(args['id'],args['method'],args["args"],args["kargs"],args["event"])
try:
actions= await asyncio.wait_for(coro, timeout=timeout_interaction)
# always save session after interaction # ALWAYS NEEDED ?? (24/5/24)
sys.hr.session._save()
#=======================================
# always save session after interaction # (when using FileDict & co)
# not needed for shm
# sys.hr.session._save()
#=======================================
except asyncio.TimeoutError:
log("timeout interaction > kill")
process_exit()
Expand Down
19 changes: 8 additions & 11 deletions htagweb/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ def __init__(self,uid):
FileDict.__init__(self,uid,persistent=True)


try:
from shared_memory_dict import SharedMemoryDict
class ShmDict(SharedMemoryDict):
def __init__(self,uid):
self._uid=uid
SharedMemoryDict.__init__(self,name=uid, size=10240)
from shared_memory_dict import SharedMemoryDict
class ShmDict(SharedMemoryDict):
def __init__(self,uid):
self._uid=uid
SharedMemoryDict.__init__(self,name=uid, size=10240)

def _save(self):
pass
except ImportError:
pass
def _save(self):
pass

Session = FileDict
Session = ShmDict
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ starlette = "0.29.0"
pycryptodomex = "^3.19.0"
uvicorn = {version = "0.22.0", extras = ["standard"]}
aiofiles = "^23.2.1"
# shared-memory-dict = "^0.7.2"
shared-memory-dict = "^0.7.2"


[tool.poetry.group.dev.dependencies]
Expand Down
10 changes: 10 additions & 0 deletions test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ async def test_process_trouble_bad_moduleapp():
except Exception as e:
assert "miss" in str(e)

@pytest.mark.asyncio
async def test_process_kaputt():
hr=HrClient("u1","examples.kaputt.App")
try:
await hr.create("//ddd")
except Exception as e:
assert "invalid" in str(e)



@pytest.mark.asyncio
async def test_process_trouble_bad_app(): # but existing module
hr=HrClient("u1","examples.simple.UNKOWN")
Expand Down
6 changes: 3 additions & 3 deletions test_sessions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest,asyncio,sys
from htagweb.session import Session,FileDict,FilePersistentDict #,ShmDict
from htagweb.session import Session,FileDict,FilePersistentDict,ShmDict


def session_test(factory):
Expand Down Expand Up @@ -49,8 +49,8 @@ def test_sessions_file():
def test_sessions_filepersitent():
session_test( FilePersistentDict )

# def test_sessions_ShmDict():
# session_test( ShmDict )
def test_sessions_ShmDict():
session_test( ShmDict )



Expand Down

0 comments on commit 2d958aa

Please sign in to comment.