From b41ca61b913e6de77c4f526855c38b99b623529c Mon Sep 17 00:00:00 2001 From: Luca Saiu Date: Fri, 24 Sep 2021 11:35:18 +0200 Subject: [PATCH] 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. --- examples/simple_xml_msgformat.py | 4 ++-- src/pEp/_pEp/message_api.cc | 2 +- src/pEp/_pEp/pEpmodule.cc | 1 - test/codec_doctest.py | 2 +- test/pyadpt-81.py | 4 ++-- test/sync_handshake.py | 4 ++-- tests/test_basic.py | 8 ++++---- tests/test_message.py | 8 ++++---- utils/pEp | 2 +- 9 files changed, 17 insertions(+), 18 deletions(-) diff --git a/examples/simple_xml_msgformat.py b/examples/simple_xml_msgformat.py index 878ca2d..4523a1a 100644 --- a/examples/simple_xml_msgformat.py +++ b/examples/simple_xml_msgformat.py @@ -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 diff --git a/src/pEp/_pEp/message_api.cc b/src/pEp/_pEp/message_api.cc index 3e0d115..37759d2 100644 --- a/src/pEp/_pEp/message_api.cc +++ b/src/pEp/_pEp/message_api.cc @@ -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) { diff --git a/src/pEp/_pEp/pEpmodule.cc b/src/pEp/_pEp/pEpmodule.cc index e3872f3..caf1306 100644 --- a/src/pEp/_pEp/pEpmodule.cc +++ b/src/pEp/_pEp/pEpmodule.cc @@ -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") diff --git a/test/codec_doctest.py b/test/codec_doctest.py index e876826..e0b16b7 100755 --- a/test/codec_doctest.py +++ b/test/codec_doctest.py @@ -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") diff --git a/test/pyadpt-81.py b/test/pyadpt-81.py index 973125b..c8429af 100644 --- a/test/pyadpt-81.py +++ b/test/pyadpt-81.py @@ -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) \ No newline at end of file +# time.sleep(3) diff --git a/test/sync_handshake.py b/test/sync_handshake.py index fa05121..5909be3 100755 --- a/test/sync_handshake.py +++ b/test/sync_handshake.py @@ -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() diff --git a/tests/test_basic.py b/tests/test_basic.py index 06dc60b..33586ae 100755 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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. diff --git a/tests/test_message.py b/tests/test_message.py index 58b99f2..3a3f185 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -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 diff --git a/utils/pEp b/utils/pEp index 1710163..92fb4a6 100755 --- a/utils/pEp +++ b/utils/pEp @@ -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))