forked from pEp.foundation/pEpPythonAdapter
intgration into Python's codecs system
parent
4da84cfdd5
commit
711f012c48
|
@ -110,7 +110,7 @@ namespace pEp {
|
|||
{
|
||||
if (encoding == "") {
|
||||
if (string(_bl->mime_type) == "application/pEp")
|
||||
encoding = "sync";
|
||||
encoding = "pep-sync";
|
||||
else
|
||||
encoding = "ascii";
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace pEp {
|
|||
::config_keep_sync_msg(session, enabled);
|
||||
}
|
||||
|
||||
string sync_decode(object buffer)
|
||||
boost::python::tuple sync_decode(object buffer)
|
||||
{
|
||||
Py_buffer src;
|
||||
int result = PyObject_GetBuffer(buffer.ptr(), &src, PyBUF_CONTIG_RO);
|
||||
|
@ -80,10 +80,10 @@ namespace pEp {
|
|||
|
||||
string _dst(dst);
|
||||
free(dst);
|
||||
return _dst;
|
||||
return boost::python::make_tuple(_dst, 0);
|
||||
}
|
||||
|
||||
object sync_encode(string text)
|
||||
static boost::python::tuple sync_encode(string text)
|
||||
{
|
||||
char *data = NULL;
|
||||
size_t size = 0;
|
||||
|
@ -95,7 +95,23 @@ namespace pEp {
|
|||
if (!ba)
|
||||
throw bad_alloc();
|
||||
|
||||
return object(handle<>(ba));
|
||||
return boost::python::make_tuple(object(handle<>(ba)), 0);
|
||||
}
|
||||
|
||||
object sync_search(string name)
|
||||
{
|
||||
if (name != "pep-sync") {
|
||||
return object();
|
||||
}
|
||||
else {
|
||||
object codecs = import("codecs");
|
||||
object CodecInfo = codecs.attr("CodecInfo");
|
||||
|
||||
object _sync_decode = make_function(sync_decode);
|
||||
object _sync_encode = make_function(sync_encode);
|
||||
|
||||
return call< object >(CodecInfo.ptr(), _sync_encode, _sync_decode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,7 @@ namespace pEp {
|
|||
boost::python::tuple decrypt_message(Message src);
|
||||
int _color(int rating);
|
||||
void _config_keep_sync_msg(bool enabled);
|
||||
string sync_decode(object buffer);
|
||||
object sync_encode(string text);
|
||||
object sync_search(string name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -207,8 +207,6 @@ BOOST_PYTHON_MODULE(pEp)
|
|||
def("color", &_color, "calculate color value out of rating");
|
||||
def("trustwords", &_trustwords, "calculate trustwords for two Identities");
|
||||
def("config_keep_sync_msg", &_config_keep_sync_msg, "configure if sync messages are being kept or not");
|
||||
def("sync_decode", &sync_decode, "decode sync message to XER/XML text");
|
||||
def("sync_encode", &sync_encode, "encode sync message from XER/XML text");
|
||||
|
||||
// key sync API
|
||||
|
||||
|
@ -223,6 +221,10 @@ BOOST_PYTHON_MODULE(pEp)
|
|||
.def("deliverHandshakeResult", &SyncMixIn::deliverHandshakeResult,
|
||||
"call to deliver the handshake result");
|
||||
|
||||
// codecs
|
||||
|
||||
call< object >(((object)(import("codecs").attr("register"))).ptr(), make_function(sync_search));
|
||||
|
||||
// init() and release()
|
||||
|
||||
PyModuleDef * _def = PyModule_GetDef(scope().ptr());
|
||||
|
|
|
@ -27,21 +27,5 @@ def process(path):
|
|||
return Message(text)
|
||||
|
||||
|
||||
def sync_search(name):
|
||||
def _sync_decode(input, errors='strict'):
|
||||
return sync_decode(input), 0
|
||||
|
||||
def _sync_encode(input, errors='strict'):
|
||||
return sync_encode(input), 0
|
||||
|
||||
if name != "sync":
|
||||
return None
|
||||
else:
|
||||
return codecs.CodecInfo(_sync_encode, _sync_decode)
|
||||
|
||||
|
||||
codecs.register(sync_search)
|
||||
|
||||
|
||||
# this is an interactive test, so start it with python -i
|
||||
|
||||
|
|
Loading…
Reference in New Issue