Merge pull request #589 from datamachine/master

New Python Binding Changes
This commit is contained in:
vysheng 2015-06-02 13:01:09 +03:00
commit 5f7b5e4068
2 changed files with 135 additions and 16 deletions

View File

@ -774,16 +774,21 @@ void py_do_all (void) {
int preview = 0;
int reply_id = 0;
unsigned long long flags = 0;
Py_ssize_t i;
tgl_user_id_t *ids;
struct tgl_message *M;
int len, len1, len2, len3;
int limit, offset;
long msg_id = 0;
PyObject *pyObj1 = NULL;
PyObject *pyObj2 = NULL;
PyObject *cb_extra = NULL;
PyObject *msg = NULL;
PyObject *peer = NULL;
PyObject *peer1 = NULL;
@ -877,33 +882,40 @@ void py_do_all (void) {
else
PyErr_Print();
break;
/* case pq_load_photo:
case pq_load_photo:
case pq_load_video:
case pq_load_audio:
case pq_load_document:
M = py_ptr[p + 1];
if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_photo_encr && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) {
py_file_cb (TLS, py_ptr[p], 0, 0);
} else {
, limit, offse, limit, offsettif (M->media.type == tgl_message_media_photo) {
tgl_do_load_photo (TLS, &M->media.photo, py_file_cb, py_ptr[p]);
} else if (M->media.type == tgl_message_media_document) {
tgl_do_load_document (TLS, &M->media.document, py_file_cb, py_ptr[p]);
if(PyArg_ParseTuple(args, "O!O", &tgl_MsgType, &msg, &cb_extra))
{
M = ((tgl_Msg*)msg)->msg;
if (!M || (M->media.type != tgl_message_media_photo && M->media.type != tgl_message_media_document && M->media.type != tgl_message_media_document_encr)) {
py_file_cb (TLS, cb_extra, 0, 0);
} else {
tgl_do_load_encr_document (TLS, &M->media.encr_document, py_file_cb, py_ptr[p]);
if (M->media.type == tgl_message_media_photo) {
assert (M->media.photo);
tgl_do_load_photo (TLS, M->media.photo, py_file_cb, cb_extra);
} else if (M->media.type == tgl_message_media_document) {
tgl_do_load_document (TLS, M->media.document, py_file_cb, cb_extra);
} else {
tgl_do_load_encr_document (TLS, M->media.encr_document, py_file_cb, cb_extra);
}
}
}
break;
case pq_load_video_thumb:
case pq_load_document_thumb:
M = py_ptr[p + 1];
if (!M || (M->media.type != tgl_message_media_document)) {
py_file_cb (TLS, py_ptr[p], 0, 0);
} else {
tgl_do_load_document_thumb (TLS, &M->media.document, py_file_cb, py_ptr[p]);
if(PyArg_ParseTuple(args, "O!O", &tgl_MsgType, &msg, &cb_extra))
{
M = ((tgl_Msg*)msg)->msg;
if (!M || (M->media.type != tgl_message_media_document)) {
py_file_cb (TLS, cb_extra, 0, 0);
} else {
tgl_do_load_document_thumb (TLS, M->media.document, py_file_cb, cb_extra);
}
}
break;
*/
case pq_fwd:
if(PyArg_ParseTuple(args, "O!l|O", &tgl_PeerType, &peer, &msg_id, &cb_extra))
tgl_do_forward_message (TLS, PY_PEER_ID(peer), msg_id, 0, py_msg_cb, cb_extra);
@ -1234,6 +1246,41 @@ static PyMethodDef py_tgl_methods[] = {
{ NULL, NULL, 0, NULL }
};
void py_add_action_enums(PyObject *m)
{
PyModule_AddIntConstant(m, "ACTION_NONE", tgl_message_action_none);
PyModule_AddIntConstant(m, "ACTION_GEO_CHAT_CREATE", tgl_message_action_geo_chat_create);
PyModule_AddIntConstant(m, "ACTION_GEO_CHAT_CHECKIN", tgl_message_action_geo_chat_checkin);
PyModule_AddIntConstant(m, "ACTION_CHAT_CREATE", tgl_message_action_chat_create);
PyModule_AddIntConstant(m, "ACTION_CHAT_EDIT_TITLE", tgl_message_action_chat_edit_title);
PyModule_AddIntConstant(m, "ACTION_CHAT_EDIT_PHOTO", tgl_message_action_chat_edit_photo);
PyModule_AddIntConstant(m, "ACTION_CHAT_DELETE_PHOTO", tgl_message_action_chat_delete_photo);
PyModule_AddIntConstant(m, "ACTION_CHAT_ADD_USER", tgl_message_action_chat_add_user);
PyModule_AddIntConstant(m, "ACTION_CHAT_ADD_USER_BY_LINK", tgl_message_action_chat_add_user_by_link);
PyModule_AddIntConstant(m, "ACTION_CHAT_DELETE_USER", tgl_message_action_chat_delete_user);
PyModule_AddIntConstant(m, "ACTION_SET_MESSAGE_TTL", tgl_message_action_set_message_ttl);
PyModule_AddIntConstant(m, "ACTION_READ_MESSAGES", tgl_message_action_read_messages);
PyModule_AddIntConstant(m, "ACTION_DELETE_MESSAGES", tgl_message_action_delete_messages);
PyModule_AddIntConstant(m, "ACTION_SCREENSHOT_MESSAGES", tgl_message_action_screenshot_messages);
PyModule_AddIntConstant(m, "ACTION_FLUSH_HISTORY", tgl_message_action_flush_history);
PyModule_AddIntConstant(m, "ACTION_RESEND", tgl_message_action_resend);
PyModule_AddIntConstant(m, "ACTION_NOTIFY_LAYER", tgl_message_action_notify_layer);
PyModule_AddIntConstant(m, "ACTION_TYPING", tgl_message_action_typing);
PyModule_AddIntConstant(m, "ACTION_NOOP", tgl_message_action_noop);
PyModule_AddIntConstant(m, "ACTION_COMMIT_KEY", tgl_message_action_commit_key);
PyModule_AddIntConstant(m, "ACTION_ABORT_KEY", tgl_message_action_abort_key);
PyModule_AddIntConstant(m, "ACTION_REQUEST_KEY", tgl_message_action_request_key);
PyModule_AddIntConstant(m, "ACTION_ACCEPT_KEY", tgl_message_action_accept_key);
}
void py_add_peer_type_enums(PyObject *m)
{
PyModule_AddIntConstant(m, "PEER_USER", TGL_PEER_USER);
PyModule_AddIntConstant(m, "PEER_USER", TGL_PEER_CHAT);
PyModule_AddIntConstant(m, "PEER_ENCR_CHAT", TGL_PEER_ENCR_CHAT);
}
MOD_INIT(tgl)
{
PyObject *m;
@ -1243,6 +1290,9 @@ MOD_INIT(tgl)
if (m == NULL)
return MOD_ERROR_VAL;
py_add_action_enums(m);
py_add_peer_type_enums(m);
if (PyType_Ready(&tgl_PeerType) < 0)
return MOD_ERROR_VAL;

View File

@ -1151,6 +1151,17 @@ tgl_Msg_getservice (tgl_Msg *self, void *closure)
return ret;
}
static PyObject *
tgl_Msg_getaction (tgl_Msg *self, void *closure)
{
PyObject *ret;
ret = PyLong_FromLong(self->msg->action.type);
Py_XINCREF(ret);
return ret;
}
static PyObject *
tgl_Msg_getsrc (tgl_Msg *self, void *closure)
@ -1210,6 +1221,8 @@ tgl_Msg_gettext (tgl_Msg *self, void *closure)
return ret;
}
static PyObject *
tgl_Msg_getmedia (tgl_Msg *self, void *closure)
{
@ -1357,6 +1370,55 @@ tgl_Msg_getreply_id (tgl_Msg *self, void *closure)
return ret;
}
// All load methods are implemented the same, just alias load_document
static PyObject *
tgl_Msg_load_document (tgl_Msg *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"callback", NULL};
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &callback)) {
PyObject *api_call;
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_load_document(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Msg_load_document_thumb (tgl_Msg *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"callback", NULL};
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "O", kwlist, &callback)) {
PyObject *api_call;
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_load_document_thumb(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Msg_repr(tgl_Msg *self)
{
@ -1400,6 +1462,7 @@ static PyGetSetDef tgl_Msg_getseters[] = {
{"fwd_date", (getter)tgl_Msg_getfwd_date, NULL, "", NULL},
{"reply", (getter)tgl_Msg_getreply, NULL, "", NULL},
{"reply_id", (getter)tgl_Msg_getreply_id, NULL, "", NULL},
{"action", (getter)tgl_Msg_getaction, NULL, "", NULL},
{NULL} /* Sentinel */
};
@ -1410,6 +1473,12 @@ static PyMemberDef tgl_Msg_members[] = {
static PyMethodDef tgl_Msg_methods[] = {
{"load_document", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_photo", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_audio", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_video", (PyCFunction)tgl_Msg_load_document, METH_VARARGS | METH_KEYWORDS, ""},
{"load_document_thumb", (PyCFunction)tgl_Msg_load_document_thumb, METH_VARARGS | METH_KEYWORDS, ""},
{"load_video_thumb", (PyCFunction)tgl_Msg_load_document_thumb, METH_VARARGS | METH_KEYWORDS, ""},
{NULL} /* Sentinel */
};