Skip to content
Snippets Groups Projects
Commit 3c844f9a authored by Daniel Brötzmann's avatar Daniel Brötzmann
Browse files

chore: IBB: Add type annotations

parent ec7a7e22
No related branches found
No related tags found
No related merge requests found
......@@ -14,15 +14,22 @@
# XEP-0047: In-Band Bytestreams
from __future__ import annotations
import time
import nbxmpp
from nbxmpp.errors import StanzaError
from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Iq
from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import IqProperties
from nbxmpp.structs import StanzaHandler
from nbxmpp.errors import StanzaError
from nbxmpp.task import Task
from gajim.common import app
from gajim.common import types
from gajim.common.file_props import FileProp
from gajim.common.helpers import to_user_string
from gajim.common.modules.base import BaseModule
from gajim.common.file_props import FilesProp
......@@ -38,7 +45,7 @@ class IBB(BaseModule):
'send_reply',
]
def __init__(self, con):
def __init__(self, con: types.Client) -> None:
BaseModule.__init__(self, con)
self.handlers = [
......@@ -47,7 +54,11 @@ def __init__(self, con):
ns=Namespace.IBB),
]
def _ibb_received(self, _con, stanza, properties):
def _ibb_received(self,
_con: types.xmppClient,
stanza: Iq,
properties: IqProperties
) -> None:
if not properties.is_ibb:
return
......@@ -106,7 +117,11 @@ def _ibb_received(self, _con, stanza, properties):
raise NodeProcessed
def _on_data_received(self, stanza, file_props, properties):
def _on_data_received(self,
stanza: Iq,
file_props: FileProp,
properties: IqProperties
) -> None:
ibb = properties.ibb
if ibb.seq != file_props.seq:
self.send_reply(stanza, nbxmpp.ERR_UNEXPECTED_REQUEST)
......@@ -127,7 +142,7 @@ def _on_data_received(self, stanza, file_props, properties):
if file_props.received_len >= file_props.size:
file_props.completed = True
def send_open(self, to, sid, fp):
def send_open(self, to: str, sid: str, fp: FileProp) -> FileProp:
self._log.info('Send open to %s, sid: %s', to, sid)
file_props = FilesProp.getFilePropBySid(sid)
file_props.direction = '>'
......@@ -149,7 +164,7 @@ def send_open(self, to, sid, fp):
user_data=file_props)
return file_props
def _on_open_result(self, task):
def _on_open_result(self, task: Task) -> None:
try:
task.finish()
except StanzaError as error:
......@@ -160,7 +175,7 @@ def _on_open_result(self, task):
file_props = task.get_user_data()
self.send_data(file_props)
def send_close(self, file_props):
def send_close(self, file_props: FileProp) -> None:
file_props.connected = False
file_props.fp.close()
file_props.stopped = True
......@@ -187,7 +202,7 @@ def send_close(self, file_props):
if session.weinitiate:
session.cancel_session()
def _on_close_result(self, task):
def _on_close_result(self, task: Task) -> None:
try:
task.finish()
except StanzaError as error:
......@@ -195,7 +210,7 @@ def _on_close_result(self, task):
self._log.warning(error)
return
def send_data(self, file_props):
def send_data(self, file_props: FileProp) -> None:
if file_props.completed:
self.send_close(file_props)
return
......@@ -223,7 +238,7 @@ def send_data(self, file_props):
file_props.completed = True
app.socks5queue.progress_transfer_cb(self._account, file_props)
def _on_data_result(self, task):
def _on_data_result(self, task: Task) -> None:
try:
task.finish()
except StanzaError as error:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment