Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mesonium
gajim
Commits
581c5775
Commit
581c5775
authored
2 years ago
by
Daniel Brötzmann
Browse files
Options
Downloads
Patches
Plain Diff
chore: Search: Add type annotations
parent
0760b9f5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gajim/common/modules/search.py
+23
-6
23 additions, 6 deletions
gajim/common/modules/search.py
with
23 additions
and
6 deletions
gajim/common/modules/search.py
+
23
−
6
View file @
581c5775
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment