1
1
# Copyright 2014-2016 OpenMarket Ltd
2
+ # Copyright 2021 The Matrix.org Foundation C.I.C.
2
3
#
3
4
# Licensed under the Apache License, Version 2.0 (the "License");
4
5
# you may not use this file except in compliance with the License.
@@ -350,7 +351,7 @@ class BaseFederationRow:
350
351
TypeId = "" # Unique string that ids the type. Must be overridden in sub classes.
351
352
352
353
@staticmethod
353
- def from_data (data ) :
354
+ def from_data (data : JsonDict ) -> "BaseFederationRow" :
354
355
"""Parse the data from the federation stream into a row.
355
356
356
357
Args:
@@ -359,7 +360,7 @@ def from_data(data):
359
360
"""
360
361
raise NotImplementedError ()
361
362
362
- def to_data (self ):
363
+ def to_data (self ) -> JsonDict :
363
364
"""Serialize this row to be sent over the federation stream.
364
365
365
366
Returns:
@@ -368,7 +369,7 @@ def to_data(self):
368
369
"""
369
370
raise NotImplementedError ()
370
371
371
- def add_to_buffer (self , buff ) :
372
+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
372
373
"""Add this row to the appropriate field in the buffer ready for this
373
374
to be sent over federation.
374
375
@@ -391,15 +392,15 @@ class PresenceDestinationsRow(
391
392
TypeId = "pd"
392
393
393
394
@staticmethod
394
- def from_data (data ) :
395
+ def from_data (data : JsonDict ) -> "PresenceDestinationsRow" :
395
396
return PresenceDestinationsRow (
396
397
state = UserPresenceState .from_dict (data ["state" ]), destinations = data ["dests" ]
397
398
)
398
399
399
- def to_data (self ):
400
+ def to_data (self ) -> JsonDict :
400
401
return {"state" : self .state .as_dict (), "dests" : self .destinations }
401
402
402
- def add_to_buffer (self , buff ) :
403
+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
403
404
buff .presence_destinations .append ((self .state , self .destinations ))
404
405
405
406
@@ -417,13 +418,13 @@ class KeyedEduRow(
417
418
TypeId = "k"
418
419
419
420
@staticmethod
420
- def from_data (data ) :
421
+ def from_data (data : JsonDict ) -> "KeyedEduRow" :
421
422
return KeyedEduRow (key = tuple (data ["key" ]), edu = Edu (** data ["edu" ]))
422
423
423
- def to_data (self ):
424
+ def to_data (self ) -> JsonDict :
424
425
return {"key" : self .key , "edu" : self .edu .get_internal_dict ()}
425
426
426
- def add_to_buffer (self , buff ) :
427
+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
427
428
buff .keyed_edus .setdefault (self .edu .destination , {})[self .key ] = self .edu
428
429
429
430
@@ -433,13 +434,13 @@ class EduRow(BaseFederationRow, namedtuple("EduRow", ("edu",))): # Edu
433
434
TypeId = "e"
434
435
435
436
@staticmethod
436
- def from_data (data ) :
437
+ def from_data (data : JsonDict ) -> "EduRow" :
437
438
return EduRow (Edu (** data ))
438
439
439
- def to_data (self ):
440
+ def to_data (self ) -> JsonDict :
440
441
return self .edu .get_internal_dict ()
441
442
442
- def add_to_buffer (self , buff ) :
443
+ def add_to_buffer (self , buff : "ParsedFederationStreamData" ) -> None :
443
444
buff .edus .setdefault (self .edu .destination , []).append (self .edu )
444
445
445
446
0 commit comments