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
3c844f9a
Commit
3c844f9a
authored
2 years ago
by
Daniel Brötzmann
Browse files
Options
Downloads
Patches
Plain Diff
chore: IBB: Add type annotations
parent
ec7a7e22
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/ibb.py
+25
-10
25 additions, 10 deletions
gajim/common/modules/ibb.py
with
25 additions
and
10 deletions
gajim/common/modules/ibb.py
+
25
−
10
View file @
3c844f9a
...
...
@@ -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
:
...
...
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