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 @@ ...@@ -14,15 +14,22 @@
# XEP-0047: In-Band Bytestreams # XEP-0047: In-Band Bytestreams
from __future__ import annotations
import time import time
import nbxmpp import nbxmpp
from nbxmpp.errors import StanzaError
from nbxmpp.namespaces import Namespace from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Iq
from nbxmpp.protocol import NodeProcessed from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import IqProperties
from nbxmpp.structs import StanzaHandler from nbxmpp.structs import StanzaHandler
from nbxmpp.errors import StanzaError from nbxmpp.task import Task
from gajim.common import app 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.helpers import to_user_string
from gajim.common.modules.base import BaseModule from gajim.common.modules.base import BaseModule
from gajim.common.file_props import FilesProp from gajim.common.file_props import FilesProp
...@@ -38,7 +45,7 @@ class IBB(BaseModule): ...@@ -38,7 +45,7 @@ class IBB(BaseModule):
'send_reply', 'send_reply',
] ]
def __init__(self, con): def __init__(self, con: types.Client) -> None:
BaseModule.__init__(self, con) BaseModule.__init__(self, con)
self.handlers = [ self.handlers = [
...@@ -47,7 +54,11 @@ def __init__(self, con): ...@@ -47,7 +54,11 @@ def __init__(self, con):
ns=Namespace.IBB), 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: if not properties.is_ibb:
return return
...@@ -106,7 +117,11 @@ def _ibb_received(self, _con, stanza, properties): ...@@ -106,7 +117,11 @@ def _ibb_received(self, _con, stanza, properties):
raise NodeProcessed 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 ibb = properties.ibb
if ibb.seq != file_props.seq: if ibb.seq != file_props.seq:
self.send_reply(stanza, nbxmpp.ERR_UNEXPECTED_REQUEST) self.send_reply(stanza, nbxmpp.ERR_UNEXPECTED_REQUEST)
...@@ -127,7 +142,7 @@ def _on_data_received(self, stanza, file_props, properties): ...@@ -127,7 +142,7 @@ def _on_data_received(self, stanza, file_props, properties):
if file_props.received_len >= file_props.size: if file_props.received_len >= file_props.size:
file_props.completed = True 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) self._log.info('Send open to %s, sid: %s', to, sid)
file_props = FilesProp.getFilePropBySid(sid) file_props = FilesProp.getFilePropBySid(sid)
file_props.direction = '>' file_props.direction = '>'
...@@ -149,7 +164,7 @@ def send_open(self, to, sid, fp): ...@@ -149,7 +164,7 @@ def send_open(self, to, sid, fp):
user_data=file_props) user_data=file_props)
return file_props return file_props
def _on_open_result(self, task): def _on_open_result(self, task: Task) -> None:
try: try:
task.finish() task.finish()
except StanzaError as error: except StanzaError as error:
...@@ -160,7 +175,7 @@ def _on_open_result(self, task): ...@@ -160,7 +175,7 @@ def _on_open_result(self, task):
file_props = task.get_user_data() file_props = task.get_user_data()
self.send_data(file_props) 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.connected = False
file_props.fp.close() file_props.fp.close()
file_props.stopped = True file_props.stopped = True
...@@ -187,7 +202,7 @@ def send_close(self, file_props): ...@@ -187,7 +202,7 @@ def send_close(self, file_props):
if session.weinitiate: if session.weinitiate:
session.cancel_session() session.cancel_session()
def _on_close_result(self, task): def _on_close_result(self, task: Task) -> None:
try: try:
task.finish() task.finish()
except StanzaError as error: except StanzaError as error:
...@@ -195,7 +210,7 @@ def _on_close_result(self, task): ...@@ -195,7 +210,7 @@ def _on_close_result(self, task):
self._log.warning(error) self._log.warning(error)
return return
def send_data(self, file_props): def send_data(self, file_props: FileProp) -> None:
if file_props.completed: if file_props.completed:
self.send_close(file_props) self.send_close(file_props)
return return
...@@ -223,7 +238,7 @@ def send_data(self, file_props): ...@@ -223,7 +238,7 @@ def send_data(self, file_props):
file_props.completed = True file_props.completed = True
app.socks5queue.progress_transfer_cb(self._account, file_props) app.socks5queue.progress_transfer_cb(self._account, file_props)
def _on_data_result(self, task): def _on_data_result(self, task: Task) -> None:
try: try:
task.finish() task.finish()
except StanzaError as error: 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