Skip to content

Commit

Permalink
Even more rearranging, this is so painful
Browse files Browse the repository at this point in the history
  • Loading branch information
MaddyGuthridge committed Aug 8, 2024
1 parent 50b8a43 commit a007d79
Show file tree
Hide file tree
Showing 38 changed files with 72 additions and 587 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,29 @@
It attaches to the "Flapi Request" device and handles messages before sending
a response via the "Flapi Respond" script.
"""
import sys
import logging
import device
from pathlib import Path
from typing import Optional
from base64 import b64decode, b64encode
from flapi import _consts as consts
from flapi._consts import MessageStatus, MessageOrigin, MessageType
from capout import Capout
from flapi.flapi_msg import FlapiMsg

# Add the dir containing flapi to the PATH, so that imports work
sys.path.append(str(Path(__file__).parent.parent))

# These imports need lint ignores, since they depend on the path modification
# above

from flapi import _consts as consts # noqa: E402
from flapi._consts import ( # noqa: E402
MessageStatus,
MessageOrigin,
MessageType,
)
from flapi.server.capout import Capout # noqa: E402
from flapi.server.client_context import ClientContext # noqa: E402
from flapi.flapi_msg import FlapiMsg # noqa: E402
from flapi.types import ScopeType

try:
from fl_classes import FlMidiMsg
Expand Down Expand Up @@ -44,6 +60,37 @@ def send_stdout(text: str):
capout = Capout(send_stdout)


###############################################################################


clients: dict[int, ClientContext] = {}


def version_query(
client_id: int,
status_code: int,
msg_data: Optional[bytes],
context: ClientContext,
) -> tuple[int, bytes]:
"""
Request the server version
"""
return MessageStatus.OK, bytes(consts.VERSION)


def register_message_type(
client_id: int,
status_code: int,
msg_data: Optional[bytes],
context: ClientContext,
) -> tuple[int, bytes]:
"""
Register a new message type
"""
assert msg_data
# TODO


def OnInit():
print("\n".join([
"Flapi request server",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"""
# Flapi Server / Client Context
"""
from typing import Any
from flapi.types import ServerMessageHandler


ScopeType = dict[str, Any]
from flapi.types import ServerMessageHandler, ScopeType


class ClientContext:
Expand Down
2 changes: 2 additions & 0 deletions src/flapi/types/__init__.py → flapi/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
Type definitions used by Flapi.
"""
from .mido_types import MidoPort, MidoMsg
from .scope import ScopeType
from .message_handler import ServerMessageHandler


__all__ = [
'MidoPort',
'MidoMsg',
'ServerMessageHandler',
'ScopeType',
]
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
# Flapi / Types / Message Handler
"""
from typing import Any, Optional, Protocol
from typing import Optional, Protocol
from flapi.server.client_context import ClientContext


class ServerMessageHandler(Protocol):
Expand All @@ -15,12 +16,17 @@ class ServerMessageHandler(Protocol):
* `status_code`: status code sent by client.
* `msg_data`: optional additional bytes.
* `scope`: local scope to use when executing arbitrary code.
## Returns of handler function
* `int` status code
* `bytes` additional data
"""
def __call__(
self,
client_id: int,
status_code: int,
msg_data: Optional[bytes],
scope: dict[str, Any],
context: ClientContext,
) -> int | tuple[int, bytes]:
...
File renamed without changes.
10 changes: 10 additions & 0 deletions flapi/types/scope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
# Flapi / Types / Scope
"""
from typing import Any


ScopeType = dict[str, Any]
"""
Represents a variable scope in Python
"""
26 changes: 0 additions & 26 deletions src/flapi/types/message_handler.py

This file was deleted.

33 changes: 0 additions & 33 deletions src/server/flapi/__util.py

This file was deleted.

185 changes: 0 additions & 185 deletions src/server/flapi/_consts.py

This file was deleted.

Loading

0 comments on commit a007d79

Please sign in to comment.