Commit b5ae2cd3 authored by Emmanuel Gil Peyrot's avatar Emmanuel Gil Peyrot

structs: Start typing some dataclasses

parent 93889f28
Pipeline #5391 canceled with stages
......@@ -17,7 +17,9 @@
import time
import random
from dataclasses import dataclass
from collections import namedtuple
from typing import Dict, Optional
from gi.repository import Soup
from gi.repository import Gio
......@@ -40,55 +42,110 @@ from nbxmpp.const import StatusCode
from nbxmpp.const import PresenceType
from nbxmpp.const import LOCATION_DATA
from nbxmpp.const import AdHocStatus
from nbxmpp.const import AdHocNoteType
from nbxmpp.const import InviteType
from nbxmpp.const import Role
from nbxmpp.const import Affiliation
StanzaHandler = namedtuple('StanzaHandler',
'name callback typ ns xmlns priority')
StanzaHandler.__new__.__defaults__ = ('', '', None, 50)
CommonResult = namedtuple('CommonResult', 'jid')
CommonResult.__new__.__defaults__ = (None,)
InviteData = namedtuple('InviteData',
'muc from_ reason password type continued thread')
DeclineData = namedtuple('DeclineData', 'muc from_ reason')
@dataclass(frozen=True)
class CommonResult:
jid: Optional[JID] = None
@dataclass(frozen=True)
class InviteData:
muc: JID
from_: JID
reason: str
password: str
type: InviteType
continued: bool
thread: str
@dataclass(frozen=True)
class DeclineData:
muc: JID
from_: JID
reason: str
CaptchaData = namedtuple('CaptchaData', 'form bob_data')
BobData = namedtuple('BobData', 'algo hash_ max_age data cid type')
@dataclass(frozen=True)
class BobData:
algo: str
hash_: str
max_age: int
data: bytes
cid: str
type: str
VoiceRequest = namedtuple('VoiceRequest', 'form jid nick')
MucUserData = namedtuple('MucUserData', 'affiliation jid nick role actor reason')
MucUserData.__new__.__defaults__ = (None, None, None, None, None)
MucDestroyed = namedtuple('MucDestroyed', 'alternate reason password')
MucDestroyed.__new__.__defaults__ = (None, None, None)
@dataclass(frozen=True)
class MucUserData:
affiliation: Affiliation
jid: JID
nick: Optional[str] = None
role: Role
actor: Optional[str] = None
reason: Optional[str] = None
@dataclass(frozen=True)
class MucDestroyed:
alternate: Optional[JID] = None
reason: Optional[str] = None
password: Optional[str] = None
MucConfigResult = namedtuple('MucConfigResult', 'jid form')
MucConfigResult.__new__.__defaults__ = (None,)
AffiliationResult = namedtuple('AffiliationResult', 'jid users')
EntityCapsData = namedtuple('EntityCapsData', 'hash node ver')
EntityCapsData.__new__.__defaults__ = (None, None, None)
HTTPAuthData = namedtuple('HTTPAuthData', 'id method url body')
HTTPAuthData.__new__.__defaults__ = (None, None, None, None)
StanzaIDData = namedtuple('StanzaIDData', 'id by')
StanzaIDData.__new__.__defaults__ = (None, None)
@dataclass(frozen=True)
class AffiliationResult:
jid: JID
users: Dict[JID, Dict[str, Optional[str]]]
@dataclass(frozen=True)
class EntityCapsData:
hash: Optional[str] = None
node: Optional[str] = None
ver: Optional[str] = None
@dataclass(frozen=True)
class HTTPAuthData:
id: Optional[str] = None
method: Optional[str] = None
url: Optional[str] = None
body: Optional[str] = None
@dataclass(frozen=True)
class StanzaIDData:
id: str
by: str
PubSubEventData = namedtuple('PubSubEventData', 'node id item data deleted retracted purged')
PubSubEventData.__new__.__defaults__ = (None, None, None, False, False, False)
PubSubConfigResult = namedtuple('PubSubConfigResult', 'jid node form')
PubSubPublishResult = namedtuple('PubSubPublishResult', 'jid node id')
@dataclass(frozen=True)
class PubSubPublishResult:
jid: JID
node: Optional[str] = None
id: Optional[str] = None
MoodData = namedtuple('MoodData', 'mood text')
@dataclass(frozen=True)
class MoodData:
mood: str
text: Optional[str]
ActivityData = namedtuple('ActivityData', 'activity subactivity text')
@dataclass(frozen=True)
class ActivityData:
activity: str
subactivity: Optional[str]
text: Optional[str]
LocationData = namedtuple('LocationData', LOCATION_DATA)
LocationData.__new__.__defaults__ = (None,) * len(LocationData._fields)
......@@ -96,11 +153,19 @@ LocationData.__new__.__defaults__ = (None,) * len(LocationData._fields)
AvatarMetaData = namedtuple('AvatarMetaData', 'bytes height width id type url')
AvatarMetaData.__new__.__defaults__ = (None,) * len(AvatarMetaData._fields)
AvatarData = namedtuple('AvatarData', 'jid sha data')
AvatarData.__new__.__defaults__ = (None,) * len(AvatarData._fields)
@dataclass(frozen=True)
class AvatarData:
jid: JID
sha: Optional[str]
data: bytes
BookmarkData = namedtuple('BookmarkData', 'jid name nick autojoin password')
BookmarkData.__new__.__defaults__ = (None, None, None, None)
@dataclass(frozen=True)
class BookmarkData:
jid: JID
name: Optional[str] = None
nick: Optional[str] = None
autojoin: bool = False
password: Optional[str] = None
BlockingListResult = namedtuple('BlockingListResult', 'blocking_list')
......@@ -113,26 +178,46 @@ OMEMOMessage = namedtuple('OMEMOMessage', 'sid iv keys payload')
AnnotationNote = namedtuple('AnnotationNote', 'jid data cdate mdate')
AnnotationNote.__new__.__defaults__ = (None, None)
EMEData = namedtuple('EMEData', 'name namespace')
@dataclass(frozen=True)
class EMEData:
name: Optional[str]
namespace: str
MuclumbusResult = namedtuple('MuclumbusResult', 'first last max end items')
MuclumbusItem = namedtuple('MuclumbusItem', 'jid name nusers description language is_open anonymity_mode')
SoftwareVersionResult = namedtuple('SoftwareVersionResult', 'name version os')
AdHocCommandNote = namedtuple('AdHocCommandNote', 'text type')
IBBData = namedtuple('IBBData', 'block_size sid seq type data')
IBBData.__new__.__defaults__ = (None, None, None, None, None)
@dataclass(frozen=True)
class SoftwareVersionResult:
name: str
version: str
os: Optional[str]
@dataclass(frozen=True)
class AdHocCommandNote:
text: Optional[str]
type: AdHocNoteType = AdHocNoteType.INFO
@dataclass(frozen=True)
class IBBData:
block_size: Optional[int] = None
sid: str
seq: Optional[int] = None
type: Optional[str] = None
data: Optional[bytes] = None
DiscoItems = namedtuple('DiscoItems', 'jid node items')
DiscoItem = namedtuple('DiscoItem', 'jid name node')
DiscoItem.__new__.__defaults__ = (None, None)
OOBData = namedtuple('OOBData', 'url desc')
@dataclass(frozen=True)
class OOBData:
url: str
desc: Optional[str]
CorrectionData = namedtuple('CorrectionData', 'id')
@dataclass(frozen=True)
class CorrectionData:
id: str
DisplayMarking = namedtuple('DisplayMarking', 'label fgcolor bgcolor')
SecurityLabel = namedtuple('SecurityLabel', 'displaymarking')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment