Merge of branch PYADPT-55 (Expose enum _PEP_color)

sync
heck 3 years ago
commit 9bb419c96b

@ -125,7 +125,7 @@ namespace pEp {
return (int) rating;
}
int Identity::color()
PEP_color Identity::color()
{
return _color(rating());
}

@ -5,6 +5,7 @@
#include <boost/python.hpp>
#include <pEp/pEpEngine.h>
#include <pEp/message_api.h>
#include <string>
#include <memory>
#include <cstddef>
@ -57,7 +58,7 @@ namespace pEp {
void flags(identity_flags_t flags) { _ident->flags = flags; }
int rating();
int color();
PEP_color color();
Identity copy();
Identity deepcopy(dict& memo);

@ -333,7 +333,7 @@ namespace pEp {
return (int) rating;
}
int Message::outgoing_color()
PEP_color Message::outgoing_color()
{
return _color(outgoing_rating());
}

@ -6,6 +6,7 @@
#include <boost/python.hpp>
#include <boost/lexical_cast.hpp>
#include <pEp/message.h>
#include <pEp/message_api.h>
#include <string>
#include "str_attr.hh"
#include "identity.hh"
@ -132,7 +133,7 @@ namespace pEp {
boost::python::tuple decrypt(int flags=0);
int outgoing_rating();
int outgoing_color();
PEP_color outgoing_color();
Message deepcopy(dict& memo);
Message copy();
};

@ -62,9 +62,9 @@ namespace pEp {
return boost::python::make_tuple(dst, keylist, _rating, _flags);
}
int _color(int rating)
PEP_color _color(int rating)
{
return (int) ::color_from_rating((PEP_rating) rating);
return ::color_from_rating((PEP_rating) rating);
}
boost::python::tuple sync_decode(object buffer)

@ -10,7 +10,7 @@ namespace pEp {
Message encrypt_message(Message src, boost::python::list extra = boost::python::list(),
int enc_format = 4, int flags = 0);
boost::python::tuple decrypt_message(Message src, int flags=0);
int _color(int rating);
PEP_color _color(int rating);
object sync_search(string name);
object distribution_search(string name);
}

@ -241,7 +241,7 @@ BOOST_PYTHON_MODULE(pEp)
(void(pEp::PythonAdapter::Identity::*)(identity_flags_t)) &pEp::PythonAdapter::Identity::flags,
"flags (p≡p internal)")
.add_property("rating", &pEp::PythonAdapter::Identity::rating, "rating of Identity")
.add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity")
.add_property("color", &pEp::PythonAdapter::Identity::color, "color of Identity as PEP_color")
.add_property("is_pEp_user", &pEp::PythonAdapter::Identity::is_pEp_user, "True if this is an identity of a pEp user")
.def("__deepcopy__", &pEp::PythonAdapter::Identity::deepcopy)
.def("update", &pEp::PythonAdapter::Identity::update, "update Identity")
@ -391,7 +391,7 @@ BOOST_PYTHON_MODULE(pEp)
" flags flags set while decryption\n"
)
.add_property("outgoing_rating", &Message::outgoing_rating, "rating outgoing message will have")
.add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have")
.add_property("outgoing_color", &Message::outgoing_color, "color outgoing message will have as PEP_color")
.def("__deepcopy__", &Message::deepcopy)
.def("__copy__", &Message::copy);
@ -477,6 +477,13 @@ BOOST_PYTHON_MODULE(pEp)
.value("PEP_rating_b0rken", PEP_rating_b0rken)
.value("PEP_rating_under_attack", PEP_rating_under_attack);
enum_<PEP_color>("PEP_color")
.value("PEP_color_no_color", PEP_color_no_color)
.value("PEP_color_yellow", PEP_color_yellow)
.value("PEP_color_green", PEP_color_green)
.value("PEP_color_red", PEP_color_red);
def("incoming_message", &incoming_message,
"msg = incoming_message(mime_text)\n"
"\n"
@ -490,7 +497,7 @@ BOOST_PYTHON_MODULE(pEp)
def("color", &_color,
"c = color(rating)\n"
"\n"
"calculate color value out of rating"
"calculate color value out of rating. Returns PEP_color"
);
def("trustwords", &_trustwords,
"text = trustwords(ident_own, ident_partner)\n"

@ -0,0 +1,50 @@
# Regression test against API breakage
# colors used to be represented as a simple int
# NEW: colors are represented by PEP_color enum
# Test for equal resolution of colors using int (OLD) vs using PEP_color (NEW)
"""
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_no_color)
True
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_yellow)
True
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_green)
True
>>> resolveOLDvsNEW(pEp.PEP_color.PEP_color_red)
True
"""
import pEp
# resolves a color represented as int, the OLD way
# returns PEP_color
def resolveColorOLD(col):
ret = pEp.PEP_color()
c = pEp.PEP_color(col)
if(c == 0):
ret = pEp.PEP_color.PEP_color_no_color
if(c == 1):
ret = pEp.PEP_color.PEP_color_yellow
if(c == 2):
ret = pEp.PEP_color.PEP_color_green
if(c == -1):
ret = pEp.PEP_color.PEP_color_red
return ret
# resolves a color represented as PEP_color, the NEW way
# returns PEP_color
def resolveColorNEW(col):
c = pEp.PEP_color(col)
return col
# Compare color resolution OLD vs NEW way
# return True if results are equal
def resolveOLDvsNEW(col):
return resolveColorOLD(col) == resolveColorNEW(col)
if __name__ == "__main__":
import doctest
doctest.testmod()
Loading…
Cancel
Save