diff options
Diffstat (limited to 'synapse/rest/client/keys.py')
-rw-r--r-- | synapse/rest/client/keys.py | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/synapse/rest/client/keys.py b/synapse/rest/client/keys.py index 5ba4fabbbc..8379092ac0 100644 --- a/synapse/rest/client/keys.py +++ b/synapse/rest/client/keys.py @@ -15,10 +15,20 @@ # limitations under the License. import logging -from typing import TYPE_CHECKING, Any, Optional, Tuple, Union, Dict, Sequence, TypeVar, Type +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Optional, + Sequence, + Tuple, + Type, + TypeVar, + Union, +) import attr -from attr.validators import instance_of, deep_iterable, deep_mapping, optional +from attr.validators import deep_iterable, deep_mapping, instance_of, optional from synapse.api.errors import InvalidAPICallError, SynapseError from synapse.http.server import HttpServer @@ -50,11 +60,13 @@ def check_str_or_jsondict(instance: Any, attribute: str, input: Any) -> None: if isinstance(input, str): pass elif isinstance(input, dict): - for key, val in input.items(): + for key in input: if not isinstance(key, str): raise TypeError(f"{attribute} dictionary has non-string key {key}") else: - raise TypeError(f"{attribute} should be a string, or a map from strings to any type.") + raise TypeError( + f"{attribute} should be a string, or a map from strings to any type." + ) @attr.s(frozen=True, slots=True) @@ -62,19 +74,23 @@ class DeviceKeys: user_id: str = attr.ib(validator=instance_of(str)) device_id: str = attr.ib(validator=instance_of(str)) algorithms: Sequence[str] = attr.ib(validator=deep_iterable(instance_of(str))) - keys: Dict[str, str] = attr.ib(validator=deep_mapping(instance_of(str), instance_of(str))) - signatures: Signatures = attr.ib(validator=deep_mapping( - instance_of(str), deep_mapping(instance_of(str), instance_of(str)) - )) + keys: Dict[str, str] = attr.ib( + validator=deep_mapping(instance_of(str), instance_of(str)) + ) + signatures: Signatures = attr.ib( + validator=deep_mapping( + instance_of(str), deep_mapping(instance_of(str), instance_of(str)) + ) + ) @attr.s(frozen=True, slots=True, auto_attribs=True) class KeyUploadBody: - device_keys: Optional[DeviceKeys] = attr.ib(converter=attr.converters.optional(DeviceKeys)) + device_keys: Optional[DeviceKeys] = attr.ib( + converter=attr.converters.optional(DeviceKeys) + ) one_time_keys: Optional[Dict[str, Union[str, JsonDict]]] = attr.ib( - validator=optional(deep_mapping( - instance_of(str), check_str_or_jsondict - )) + validator=optional(deep_mapping(instance_of(str), check_str_or_jsondict)) ) org_matrix_msc2732_fallback_keys: Optional[Dict[str, Union[str, JsonDict]]] @@ -83,7 +99,9 @@ class KeyUploadBody: return cls( device_keys=src.get("device_keys"), one_time_keys=src.get("one_time_keys"), - org_matrix_msc2732_fallback_keys=src.get("org.matrix.msc2732.fallback.keys"), + org_matrix_msc2732_fallback_keys=src.get( + "org.matrix.msc2732.fallback.keys" + ), ) |