Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More type fixes #86

Merged
merged 13 commits into from
Feb 4, 2024
14 changes: 6 additions & 8 deletions kalamine/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from .layout import KeyboardLayout


def keyboard_server(file_path: Path) -> None:
kb_layout = KeyboardLayout(file_path)

Expand Down Expand Up @@ -60,22 +59,21 @@ def main_page(layout: KeyboardLayout) -> str:
"""

class LayoutHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
dir_path = os.path.dirname(os.path.realpath(__file__))
www_path = os.path.join(dir_path, "www")
super().__init__(*args, directory=www_path, **kwargs)
def __init__(self, *args, **kwargs) -> None: # type: ignore
kwargs['directory'] = str(Path(__file__).parent / "www")
super().__init__(*args, **kwargs)

def do_GET(self):
def do_GET(self) -> None:
self.send_response(200)

def send(page, content="text/plain", charset="utf-8"):
def send(page: str, content:str = "text/plain", charset:str = "utf-8") -> None:
self.send_header("Content-type", f"{content}; charset={charset}")
self.end_headers()
self.wfile.write(bytes(page, charset))
# self.wfile.write(page.encode(charset))

# XXX always reloads the layout on the root page, never in sub pages
global kb_layout
nonlocal kb_layout
fabi1cazenave marked this conversation as resolved.
Show resolved Hide resolved
if self.path == "/json":
send(json.dumps(kb_layout.json), content="application/json")
elif self.path == "/keylayout":
Expand Down