Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Add additional types to the federation transport server #10213

Merged
merged 8 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,9 @@ async def on_GET(
) -> Tuple[int, JsonDict]:
try:
# Retrieve the room versions the remote homeserver claims to support
supported_versions = parse_strings_from_args(query, "ver", encoding="utf-8")
supported_versions = parse_strings_from_args(
query, "ver", required=True, encoding="utf-8"
)
clokep marked this conversation as resolved.
Show resolved Hide resolved
except KeyError:
raise SynapseError(400, "Missing required query parameter 'ver'")

Expand Down
50 changes: 46 additions & 4 deletions synapse/http/servlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,22 @@ def parse_boolean_from_args(args, name, default=None, required=False):
return default


@overload
def parse_bytes_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[bytes] = None,
) -> Optional[bytes]:
...


@overload
def parse_bytes_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Literal[None] = None,
required: Literal[True] = True,
*,
required: Literal[True],
) -> bytes:
...

Expand Down Expand Up @@ -197,7 +207,12 @@ def parse_string(
"""
args = request.args # type: Dict[bytes, List[bytes]] # type: ignore
return parse_string_from_args(
args, name, default, required, allowed_values, encoding
args,
name,
default,
required=required,
allowed_values=allowed_values,
encoding=encoding,
)


Expand Down Expand Up @@ -227,7 +242,20 @@ def parse_strings_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[List[str]] = None,
required: Literal[True] = True,
*,
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
) -> Optional[List[str]]:
...


@overload
def parse_strings_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[List[str]] = None,
*,
required: Literal[True],
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
) -> List[str]:
Expand All @@ -239,6 +267,7 @@ def parse_strings_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[List[str]] = None,
*,
required: bool = False,
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
Expand Down Expand Up @@ -299,7 +328,20 @@ def parse_string_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[str] = None,
required: Literal[True] = True,
*,
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
) -> Optional[str]:
...


@overload
def parse_string_from_args(
args: Dict[bytes, List[bytes]],
name: str,
default: Optional[str] = None,
*,
required: Literal[True],
allowed_values: Optional[Iterable[str]] = None,
encoding: str = "ascii",
) -> str:
Expand Down