Skip to content

Commit

Permalink
chore: Refactor. #1796
Browse files Browse the repository at this point in the history
  • Loading branch information
mturoci committed Feb 24, 2023
1 parent 045a0a5 commit 929b11a
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions py/h2o_wavelite/h2o_wavelite/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,14 @@
import json
import logging
import traceback
from typing import Any, Awaitable, Callable, Dict, Optional
from typing import Any, Awaitable, Callable, Optional

from .core import AsyncPage, Expando
from .ui import markdown_card

logger = logging.getLogger(__name__)


def _session_for(sessions: dict, session_id: str):
session = sessions.get(session_id, None)
if session is None:
session = Expando()
sessions[session_id] = session
return session


class Query:
"""
Represents the query context.
Expand Down Expand Up @@ -65,7 +57,7 @@ class _App:
def __init__(self, handle: HandleAsync, send: Optional[Callable] = None, recv: Optional[Callable] = None):
self._recv = recv
self._handle = handle
self._state: Dict[str, Expando] = {}
self._state: Expando = Expando()
self._page: AsyncPage = AsyncPage(send)

async def _run(self):
Expand All @@ -89,7 +81,7 @@ async def _process(self, args: dict):
if isinstance(events_state, dict):
events_state = {k: Expando(v) for k, v in events_state.items()}
del args['']
q = Q(self._page, _session_for(self._state, ''), Expando(args), Expando(events_state))
q = Q(self._page, self._state, Expando(args), Expando(events_state))
try:
await self._handle(q)
except Exception:
Expand Down

0 comments on commit 929b11a

Please sign in to comment.