Commit b48f0f6c authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Add annotations

parent b2a46b62
......@@ -15,9 +15,12 @@
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
from typing import Optional
import logging
import hashlib
from nbxmpp.simplexml import Node
from nbxmpp.namespaces import Namespace
from nbxmpp.structs import BobData
from nbxmpp.util import b64decode
......@@ -25,7 +28,7 @@ from nbxmpp.util import b64decode
log = logging.getLogger('nbxmpp.m.bob')
def parse_bob_data(stanza):
def parse_bob_data(stanza: Node) -> Optional[BobData]:
data_node = stanza.getTag('data', namespace=Namespace.BOB)
if data_node is None:
return None
......
......@@ -42,6 +42,7 @@ 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 InviteType
class StanzaHandler(NamedTuple):
......@@ -53,17 +54,39 @@ class StanzaHandler(NamedTuple):
priority: int = 50
CommonResult = namedtuple('CommonResult', 'jid')
CommonResult.__new__.__defaults__ = (None,)
class CommonResult(NamedTuple):
jid: Optional[JID] = None
InviteData = namedtuple('InviteData',
'muc from_ reason password type continued thread')
DeclineData = namedtuple('DeclineData', 'muc from_ reason')
class InviteData(NamedTuple):
muc: JID
from_: JID
reason: Optional[str]
password: Optional[str]
type: InviteType
continued: bool
thread: Optional[str]
CaptchaData = namedtuple('CaptchaData', 'form bob_data')
BobData = namedtuple('BobData', 'algo hash_ max_age data cid type')
class DeclineData(NamedTuple):
muc: JID
from_: JID
reason: Optional[str]
class CaptchaData(NamedTuple):
form: Any
bob_data: BobData
class BobData(NamedTuple):
algo: str
hash_: str
max_age: str
data: str
cid: str
type: str
VoiceRequest = namedtuple('VoiceRequest', 'form jid nick')
......
......@@ -317,7 +317,7 @@ def get_stream_header(domain, lang, is_websocket):
return "<?xml version='1.0'?>%s>" % str(header)[:-3]
def utf8_decode(data):
def utf8_decode(data: bytes) -> tuple[str, bytes]:
'''
Decodes utf8 byte string to unicode string
Does handle invalid utf8 sequences by splitting
......@@ -336,7 +336,7 @@ def utf8_decode(data):
raise
def get_rand_number():
def get_rand_number() -> int:
return int(binascii.hexlify(os.urandom(6)), 16)
......@@ -360,7 +360,7 @@ def get_invalid_xml_regex():
return re.compile(r)
def get_tls_error_phrase(tls_error):
def get_tls_error_phrase(tls_error: Gio.TlsCertificateFlags) -> str:
phrase = GIO_TLS_ERRORS.get(tls_error)
if phrase is None:
return GIO_TLS_ERRORS.get(Gio.TlsCertificateFlags.GENERIC_ERROR)
......
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