Daniel Brötzmann pushed to branch master at gajim / gajim
Commits: ec7a7e22 by wurstsalat at 2022-05-27T00:11:43+02:00 chore: PEP: Add type annotations
- - - - - 3c844f9a by wurstsalat at 2022-05-27T00:11:56+02:00 chore: IBB: Add type annotations
- - - - - 124f7ab8 by wurstsalat at 2022-05-27T00:14:16+02:00 chore: SoftwareVersion: Add type annotations
- - - - - fba9f814 by wurstsalat at 2022-05-27T00:20:43+02:00 chore: UserLocation: Add type annotations
- - - - -
5 changed files:
- gajim/common/modules/ibb.py - gajim/common/modules/pep.py - gajim/common/modules/software_version.py - gajim/common/modules/user_location.py - pyrightconfig.json
Changes:
===================================== gajim/common/modules/ibb.py ===================================== @@ -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:
===================================== gajim/common/modules/pep.py ===================================== @@ -14,17 +14,21 @@
# XEP-0163: Personal Eventing Protocol
-from gajim.common.types import ConnectionT +from __future__ import annotations + +from nbxmpp.structs import DiscoInfo + +from gajim.common import types from gajim.common.modules.base import BaseModule
class PEP(BaseModule): - def __init__(self, con: ConnectionT) -> None: + def __init__(self, con: types.Client) -> None: BaseModule.__init__(self, con)
self.supported = False
- def pass_disco(self, info): + def pass_disco(self, info: DiscoInfo) -> None: for identity in info.identities: if identity.category == 'pubsub': if identity.type == 'pep':
===================================== gajim/common/modules/software_version.py ===================================== @@ -14,7 +14,12 @@
# XEP-0092: Software Version
+from __future__ import annotations + +from nbxmpp.protocol import JID + from gajim.common import app +from gajim.common import types from gajim.common.helpers import get_os_info from gajim.common.modules.base import BaseModule
@@ -28,10 +33,10 @@ class SoftwareVersion(BaseModule): 'disable', ]
- def __init__(self, con): + def __init__(self, con: types.Client) -> None: BaseModule.__init__(self, con)
- def set_enabled(self, enabled): + def set_enabled(self, enabled: bool) -> None: if enabled and app.settings.get_account_setting(self._account, 'send_os_info'): os_info = get_os_info() @@ -41,10 +46,10 @@ def set_enabled(self, enabled): 'Gajim', app.version, os_info) self._nbxmpp('SoftwareVersion').set_allow_reply_func(self._allow_reply)
- def _allow_reply(self, jid): + def _allow_reply(self, jid: JID) -> bool: item = self._con.get_module('Roster').get_item(jid.bare) if item is None: return False
- contact = self._get_contact(jid.bare) + contact = self._get_contact(JID.from_string(jid.bare)) return contact.is_subscribed
===================================== gajim/common/modules/user_location.py ===================================== @@ -20,10 +20,15 @@
from nbxmpp.namespaces import Namespace from nbxmpp.protocol import JID +from nbxmpp.protocol import Message from nbxmpp.structs import LocationData +from nbxmpp.structs import MessageProperties
from gajim.common import app from gajim.common import ged +from gajim.common import types +from gajim.common.events import SignedIn +from gajim.common.events import LocationChanged from gajim.common.modules.base import BaseModule from gajim.common.modules.util import event_node from gajim.common.modules.util import store_publish @@ -38,12 +43,12 @@ class UserLocation(BaseModule): 'set_location', ]
- def __init__(self, con) -> None: + def __init__(self, con: types.Client) -> None: BaseModule.__init__(self, con) self._register_pubsub_handler(self._location_received)
self._current_location: Optional[LocationData] = None - self._contact_locations: dict[JID, LocationData] = {} + self._contact_locations: dict[JID, Optional[LocationData]] = {}
def get_current_location(self) -> Optional[LocationData]: return self._current_location @@ -52,7 +57,12 @@ def get_contact_location(self, jid: JID) -> Optional[LocationData]: return self._contact_locations.get(jid)
@event_node(Namespace.LOCATION) - def _location_received(self, _con, _stanza, properties): + def _location_received(self, + _con: types.xmppClient, + _stanza: Message, + properties: MessageProperties + ) -> None: + assert properties.pubsub_event is not None if properties.pubsub_event.retracted: return
@@ -60,13 +70,17 @@ def _location_received(self, _con, _stanza, properties): if properties.is_self_message: self._current_location = data
+ assert properties.jid is not None self._contact_locations[properties.jid] = data
contact = self._get_contact(properties.jid) contact.notify('location-update', data)
@store_publish - def set_location(self, location, force=False): + def set_location(self, + location: Optional[LocationData], + force: bool = False + ) -> None: if not self._con.get_module('PEP').supported: return
@@ -81,7 +95,7 @@ def set_location(self, location, force=False): self._log.info('Send %s', location) self._nbxmpp('Location').set_location(location)
- def set_enabled(self, enable): + def set_enabled(self, enable: bool) -> None: if enable: self.register_events([ ('location-changed', ged.CORE, self._on_location_changed), @@ -96,10 +110,10 @@ def _publish_current_location(self): self.set_location(LocationListener.get().current_location)
@event_filter(['account']) - def _on_signed_in(self, _event): + def _on_signed_in(self, _event: SignedIn) -> None: self._publish_current_location()
- def _on_location_changed(self, event): + def _on_location_changed(self, event: LocationChanged) -> None: if self._current_location == event.info: return
===================================== pyrightconfig.json ===================================== @@ -30,6 +30,7 @@ "gajim/common/idle.py", "gajim/common/logging_helpers.py", "gajim/common/modules/chat_markers.py", + "gajim/common/modules/pep.py", "gajim/common/modules/register.py", "gajim/common/passwords.py", "gajim/common/regex.py",
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/59e9fffabf1c4ce46df46ec97a200e43...