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

chore: Search: Add type annotations

parent 0760b9f5
No related branches found
No related tags found
No related merge requests found
...@@ -14,10 +14,17 @@ ...@@ -14,10 +14,17 @@
# XEP-0055: Jabber Search # XEP-0055: Jabber Search
from __future__ import annotations
from typing import Any
import nbxmpp import nbxmpp
from nbxmpp.modules.dataforms import SimpleDataForm
from nbxmpp.namespaces import Namespace from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import Iq
from gajim.common import app from gajim.common import app
from gajim.common import types
from gajim.common.events import SearchFormReceivedEvent from gajim.common.events import SearchFormReceivedEvent
from gajim.common.events import SearchResultReceivedEvent from gajim.common.events import SearchResultReceivedEvent
...@@ -25,15 +32,18 @@ ...@@ -25,15 +32,18 @@
class Search(BaseModule): class Search(BaseModule):
def __init__(self, con): def __init__(self, con: types.Client) -> None:
BaseModule.__init__(self, con) BaseModule.__init__(self, con)
def request_search_fields(self, jid): def request_search_fields(self, jid: str) -> None:
self._log.info('Request search fields from %s', jid) self._log.info('Request search fields from %s', jid)
iq = nbxmpp.Iq(typ='get', to=jid, queryNS=Namespace.SEARCH) iq = nbxmpp.Iq(typ='get', to=jid, queryNS=Namespace.SEARCH)
self._con.connection.SendAndCallForResponse(iq, self._fields_received) self._con.connection.SendAndCallForResponse(iq, self._fields_received)
def _fields_received(self, _nbxmpp_client, stanza): def _fields_received(self,
_nbxmpp_client: types.xmppClient,
stanza: Iq
) -> None:
data = None data = None
is_dataform = False is_dataform = False
...@@ -60,7 +70,11 @@ def _fields_received(self, _nbxmpp_client, stanza): ...@@ -60,7 +70,11 @@ def _fields_received(self, _nbxmpp_client, stanza):
is_dataform=is_dataform, is_dataform=is_dataform,
data=data)) data=data))
def send_search_form(self, jid, form, is_form): def send_search_form(self,
jid: str,
form: SimpleDataForm,
is_form: bool
) -> None:
iq = nbxmpp.Iq(typ='set', to=jid, queryNS=Namespace.SEARCH) iq = nbxmpp.Iq(typ='set', to=jid, queryNS=Namespace.SEARCH)
item = iq.setQuery() item = iq.setQuery()
if is_form: if is_form:
...@@ -71,7 +85,10 @@ def send_search_form(self, jid, form, is_form): ...@@ -71,7 +85,10 @@ def send_search_form(self, jid, form, is_form):
self._con.connection.SendAndCallForResponse(iq, self._received_result) self._con.connection.SendAndCallForResponse(iq, self._received_result)
def _received_result(self, _nbxmpp_client, stanza): def _received_result(self,
_nbxmpp_client: types.xmppClient,
stanza: Iq
) -> None:
data = None data = None
is_dataform = False is_dataform = False
...@@ -86,7 +103,7 @@ def _received_result(self, _nbxmpp_client, stanza): ...@@ -86,7 +103,7 @@ def _received_result(self, _nbxmpp_client, stanza):
if data is not None: if data is not None:
is_dataform = True is_dataform = True
else: else:
data = [] data: list[Any] = []
for item in tag.getTags('item'): for item in tag.getTags('item'):
# We also show attributes. jid is there # We also show attributes. jid is there
field = item.attrs field = item.attrs
......
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