diff --git a/cgi-bin/form.py b/cgi-bin/form.py index 5ca8b69..9fd4268 100755 --- a/cgi-bin/form.py +++ b/cgi-bin/form.py @@ -131,15 +131,16 @@ if form_disabled: form = cgi.FieldStorage() @overload -def get_form_value(name: str, default: Optional[str], cast: type[str] = str) -> str: ... +def get_form_value(name: str, default: None = ..., *, cast: type[bytes]) -> tuple[str, bytes]:... @overload -def get_form_value(name: str, default: Optional[int], cast: type[int]) -> int:... +def get_form_value(name: str, default: Optional[int] = ..., *, cast: type[int]) -> int:... @overload -def get_form_value(name: str, default: None = ..., cast: type[bytes] = ...) -> tuple[str, bytes]:... +def get_form_value(name: str, default: Optional[str] = ..., *, cast: type[str] = ...) -> str: ... def get_form_value( name: str, default: Any = None, - cast: type[str] | type[int] | type[io.BytesIO] = str, + *, + cast: type[str] | type[int] | type[bytes] = str, ) -> Any: if name not in form: if default is None: @@ -166,7 +167,7 @@ def get_form_value( # constant-time string comparison here. given_csrf_token = get_form_value("csrftoken") if not hmac.compare_digest(csrf_token, given_csrf_token): - fail("400 Bad Request", f"Invalid CSRF token") + fail("400 Bad Request", "Invalid CSRF token") # If the honeypot field was not empty, back off. @@ -194,7 +195,7 @@ if not EMAIL_REGEX.fullmatch(contact_email): message = get_form_value("message", "[Keine Nachricht hinterlassen]") attachment: Optional[tuple[str, bytes]] = None -ticket_details = collections.OrderedDict() +ticket_details = collections.OrderedDict[str, str | int]() ticket_details["Kontaktperson"] = contact_name ticket_details["Email"] = contact_email @@ -220,9 +221,9 @@ match request_uri: ticket_details["Adresse"] = get_form_value("addressline") ticket_details["PLZ"] = get_form_value("postalcode") ticket_details["Stadt"] = get_form_value("city") - ticket_details["Anzahl Desktops"] = get_form_value("desktopcount", 0, int) - ticket_details["Anzahl Laptops"] = get_form_value("laptopcount", 0, int) - ticket_details["Anzahl Drucker"] = get_form_value("printercount", 0, int) + ticket_details["Anzahl Desktops"] = get_form_value("desktopcount", 0, cast=int) + ticket_details["Anzahl Laptops"] = get_form_value("laptopcount", 0, cast=int) + ticket_details["Anzahl Drucker"] = get_form_value("printercount", 0, cast=int) case "/computer-beantragen/privat": form_name = "Computerantrag (privat)" @@ -256,13 +257,13 @@ match request_uri: ticket_details["Teilnehmenden-Name"] = get_form_value("participantname", "-") ticket_details["Telefonnummer"] = get_form_value("contactphone", "-") ticket_details["Fotos?"] = get_form_value("photos") - + case "/party": form_name = "CoderDojo Minecraft LAN" form_group = "CoderDojo" ticket_details["Java-Spielername"] = get_form_value("javaname", "") ticket_details["Bedrock-Spielername"] = get_form_value("bedrockname", "") - + case "/freizeit": form_name = "CoderCamp Umfrage" form_group = "CoderDojo"