Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slixmpp-omemo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
slixmpp-omemo
Commits
153edfb5
Verified
Commit
153edfb5
authored
Sep 02, 2019
by
Maxime Buquet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Echo_bot: Use expect_problems and handle MissingBundleException
Signed-off-by:
Maxime “pep” Buquet
<
pep@bouah.net
>
parent
2dc08c9d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
3 deletions
+26
-3
examples/echo_client.py
examples/echo_client.py
+26
-3
No files found.
examples/echo_client.py
View file @
153edfb5
...
...
@@ -18,10 +18,12 @@ from getpass import getpass
from
argparse
import
ArgumentParser
from
slixmpp
import
ClientXMPP
,
JID
from
slixmpp.exceptions
import
IqTimeout
,
IqError
from
slixmpp.stanza
import
Message
import
slixmpp_omemo
from
slixmpp_omemo
import
PluginCouldNotLoad
,
MissingOwnKey
,
EncryptionPrepareException
from
slixmpp_omemo
import
UndecidedException
,
UntrustedException
,
NoAvailableSession
import
slixmpp_omemo
from
omemo.exceptions
import
MissingBundleException
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -158,6 +160,8 @@ class EchoBot(ClientXMPP):
msg
[
'eme'
][
'namespace'
]
=
self
.
eme_ns
msg
[
'eme'
][
'name'
]
=
self
[
'xep_0380'
].
mechanisms
[
self
.
eme_ns
]
expect_problems
=
{}
# type: Optional[Dict[JID, List[int]]]
while
True
:
try
:
# `encrypt_message` excepts the plaintext to be sent, a list of
...
...
@@ -171,7 +175,7 @@ class EchoBot(ClientXMPP):
#
# TODO: Document expect_problems
recipients
=
[
mto
]
encrypt
=
await
self
[
'xep_0384'
].
encrypt_message
(
body
,
recipients
)
encrypt
=
await
self
[
'xep_0384'
].
encrypt_message
(
body
,
recipients
,
expect_problems
)
msg
.
append
(
encrypt
)
return
msg
.
send
()
except
UndecidedException
as
exn
:
...
...
@@ -180,7 +184,25 @@ class EchoBot(ClientXMPP):
# This is where you prompt your user to ask what to do. In
# this bot we will automatically trust undecided recipients.
self
[
'xep_0384'
].
trust
(
exn
.
bare_jid
,
exn
.
device
,
exn
.
ik
)
# TODO: catch NoEligibleDevicesException and MissingBundleException
# TODO: catch NoEligibleDevicesException
except
EncryptionPrepareException
as
exn
:
# TODO: We might need to bail out here if errors are the same?
for
error
in
exn
.
errors
:
if
isinstance
(
error
,
MissingBundleException
):
self
.
plain_reply
(
original_msg
,
'Could not find keys for device "%d" of recipient "%s". Skipping.'
%
(
error
.
device
,
error
.
bare_jid
),
)
jid
=
JID
(
error
.
bare_jid
)
device_list
=
expect_problems
.
setdefault
(
jid
,
[])
device_list
.
append
(
error
.
device
)
except
(
IqError
,
IqTimeout
)
as
exn
:
self
.
plain_reply
(
original_msg
,
'An error occured while fetching information on a recipient.
\n
%r'
%
exn
,
)
return
None
except
Exception
as
exn
:
await
self
.
plain_reply
(
original_msg
,
...
...
@@ -190,6 +212,7 @@ class EchoBot(ClientXMPP):
return
None
if
__name__
==
'__main__'
:
# Setup the command line arguments.
parser
=
ArgumentParser
(
description
=
EchoBot
.
__doc__
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment