Browse Source

change the Python API to follow the engine API after ENGINE-959

The decrypt method of the message class now returns a tuple of three elements
instead of four:
* message
* keys
* flags
There is no more rating among the results, as the rating is now a property of
the message -- and can be easily accessed as message.rating .

Update examples and tests.
lucasaiu/message-struct-change
Luca Saiu 1 month ago
parent
commit
b41ca61b91
9 changed files with 17 additions and 18 deletions
  1. +2
    -2
      examples/simple_xml_msgformat.py
  2. +1
    -1
      src/pEp/_pEp/message_api.cc
  3. +0
    -1
      src/pEp/_pEp/pEpmodule.cc
  4. +1
    -1
      test/codec_doctest.py
  5. +2
    -2
      test/pyadpt-81.py
  6. +2
    -2
      test/sync_handshake.py
  7. +4
    -4
      tests/test_basic.py
  8. +4
    -4
      tests/test_message.py
  9. +1
    -1
      utils/pEp

+ 2
- 2
examples/simple_xml_msgformat.py View File

@ -127,5 +127,5 @@ def parse_serialized_message(transport_message):
pEp_attachs.append(
pEp.Blob(attach.text.encode(), TAG2CT[tagname]))
msg1.attachments = pEp_attachs
msg2, keys, rating, flags = msg1.decrypt()
return msg2, rating
msg2, keys, flags = msg1.decrypt()
return msg2, msg2.rating

+ 1
- 1
src/pEp/_pEp/message_api.cc View File

@ -62,7 +62,7 @@ namespace pEp {
Message dst = _dst ? Message(_dst) : Message(src);
PEP_rating _rating = dst.rating ();
return boost::python::make_tuple(dst, keylist, _rating, _flags);
return boost::python::make_tuple(dst, keylist, _flags);
}
PEP_color _color(int rating) {


+ 0
- 1
src/pEp/_pEp/pEpmodule.cc View File

@ -514,7 +514,6 @@ namespace pEp {
"\n"
" msg the decrypted p≡p message\n"
" keys a list of keys being used\n"
" rating the rating of the message as integer\n"
" flags flags set while decryption\n"
)
.add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")


+ 1
- 1
test/codec_doctest.py View File

@ -4,7 +4,7 @@
"""
>>> import pEp
>>> def message_to_send(msg):
... m, keys, rating, flags = msg.decrypt()
... m, keys, flags = msg.decrypt()
... try:
... m.attachments[0].decode()
... print("decode successfull")


+ 2
- 2
test/pyadpt-81.py View File

@ -6,7 +6,7 @@ import time
def message_to_send(msg):
print("User defined message_to_send() called")
m, keys, rating, flags = msg.decrypt()
m, keys, flags = msg.decrypt()
try:
print(m.attachments[0].decode())
except UnicodeDecodeError as e:
@ -44,4 +44,4 @@ start_stop_sync(1)
# print("is_sync_active: {}".format(pEp.is_sync_active()))
# time.sleep(3)
# pEp.key_reset_all_own_keys()
# time.sleep(3)
# time.sleep(3)

+ 2
- 2
test/sync_handshake.py View File

@ -103,7 +103,7 @@ def messageImapToSend(msg):
def add_debug_info(msg):
if msg.enc_format:
m, keys, rating, flags = msg.decrypt(DONT_TRIGGER_SYNC)
m, keys, flags = msg.decrypt(DONT_TRIGGER_SYNC)
else:
m = msg
try:
@ -212,7 +212,7 @@ def run(name, color=None, imap=False, own_ident=1, leave=False):
msg = pEp.Message(m)
output("*** Reading")
print_msg(msg)
msg2, keys, rating, flags = msg.decrypt()
msg2, keys, flags = msg.decrypt()
except KeyboardInterrupt:
shutdown_sync()


+ 4
- 4
tests/test_basic.py View File

@ -20,8 +20,8 @@ import pytest
# >>> m.longmsg = "Please call me back"
# >>> m2 = m.encrypt()
# >>> print(m2)
# >>> m3, keys, rating, flags = m2.decrypt()
# >>> rating
# >>> m3, keys, flags = m2.decrypt()
# >>> m3.rating
# pEp.rating.reliable
# """
#
@ -50,6 +50,6 @@ def test_basic(pEp, model):
m.longmsg = constants.BODY
#TODO: encrypt needs to return message type
m2 = m.encrypt()
m3, keys, rating, flags = m2.decrypt()
m3, keys, flags = m2.decrypt()
#TODO: fix pEp.rating
# assert rating == pEp.
# assert m3.rating == pEp.

+ 4
- 4
tests/test_message.py View File

@ -35,13 +35,13 @@ def test_msg_enc_dec_roundtrip(pEp, model, import_ident_alice_as_own_ident, impo
assert enc_msg.longmsg == "this message was encrypted with p≡p https://pEp-project.org"
# Decrypt message.
dec_msg, key_list, rating, r = enc_msg.decrypt()
dec_msg, key_list, r = enc_msg.decrypt()
assert r == 0
# pEp version 2.2 throws this error:
# AttributeError: module 'pEp' has no attribute 'PEP_rating'
# assert rating == pEp.PEP_rating.PEP_rating_reliable
# assert dec_msg.rating == pEp.PEP_rating.PEP_rating_reliable
# It seems to have changed to the following.
assert rating == pEp._pEp.rating.reliable
assert dec_msg.rating == pEp._pEp.rating.reliable
# The first 2 keys are Alice's ones, the last is Bob's one.
assert key_list[0] == key_list[1] == model.alice.fpr
@ -123,7 +123,7 @@ def test_dec_msg_len(pEp, import_ident_alice_as_own_ident, import_ident_bob):
enc_msg = msg.encrypt()
# Decrypt message.
dec_msg, _key_list, _rating, _r = enc_msg.decrypt()
dec_msg, _key_list, _r = enc_msg.decrypt()
dec_msg_len = len(str(dec_msg))
assert dec_msg.longmsg.replace("\r", "") == constants.BODY # msg.longmsg


+ 1
- 1
utils/pEp View File

@ -77,7 +77,7 @@ try:
dst = src.encrypt()
else:
src.dir = 0
dst, keys, rating, flags = src.decrypt()
dst, keys, flags = src.decrypt()
print(str(dst))


Loading…
Cancel
Save