diff options
author | Erik Johnston <erik@matrix.org> | 2019-01-23 20:21:33 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2019-01-23 20:21:33 +0000 |
commit | f431ff3fb82cb3da549f92d8aef704bbf58387b6 (patch) | |
tree | 8e3ecbec9e8f656aaed1bc4642ad000f11816302 /synapse/events/__init__.py | |
parent | Merge branch 'erikj/fixup_rejecting_invites' of github.com:matrix-org/synapse... (diff) | |
download | synapse-f431ff3fb82cb3da549f92d8aef704bbf58387b6.tar.xz |
Require event format version to parse or create events
Diffstat (limited to 'synapse/events/__init__.py')
-rw-r--r-- | synapse/events/__init__.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index 01db729847..e74ea33a7c 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -18,7 +18,11 @@ from distutils.util import strtobool import six -from synapse.api.constants import KNOWN_ROOM_VERSIONS, EventFormatVersions +from synapse.api.constants import ( + KNOWN_EVENT_FORMAT_VERSIONS, + KNOWN_ROOM_VERSIONS, + EventFormatVersions, +) from synapse.util.caches import intern_dict from synapse.util.frozenutils import freeze @@ -254,3 +258,21 @@ def room_version_to_event_format(room_version): raise return EventFormatVersions.V1 + + +def event_type_from_format_version(format_version): + """Returns the python type to use to construct an Event object for the + given event format version. + + Args: + format_version (int): The event format version + + Returns: + type: A type that can be initialized as per the initializer of + `FrozenEvent` + """ + if format_version not in KNOWN_EVENT_FORMAT_VERSIONS: + raise Exception( + "No event format %r" % (format_version,) + ) + return FrozenEvent |