mirror of
https://github.com/jorisvink/kore
synced 2025-03-09 20:49:01 -04:00
Improve python websocket handling a bit.
Convert the data parameter to a string if the op was WEBSOCKET_OP_TEXT or convert to bytes if op was WEBSOCKET_OP_BINARY so the callee does not have to do this anymore.
This commit is contained in:
parent
0b84a9c1d4
commit
4a56424842
14
src/python.c
14
src/python.c
@ -377,8 +377,18 @@ python_runtime_wsmessage(void *addr, struct connection *c, u_int8_t op,
|
||||
if ((pyop = PyLong_FromLong((long)op)) == NULL)
|
||||
fatal("python_runtime_wsmessage: PyLong_FromLong failed");
|
||||
|
||||
if ((pydata = PyBytes_FromStringAndSize(data, len)) == NULL)
|
||||
fatal("python_runtime_wsmessage: PyBytes_FromString failed");
|
||||
switch (op) {
|
||||
case WEBSOCKET_OP_TEXT:
|
||||
if ((pydata = PyUnicode_FromStringAndSize(data, len)) == NULL)
|
||||
fatal("wsmessage: PyUnicode_AsUTF8AndSize failed");
|
||||
break;
|
||||
case WEBSOCKET_OP_BINARY:
|
||||
if ((pydata = PyBytes_FromStringAndSize(data, len)) == NULL)
|
||||
fatal("wsmessage: PyBytes_FromString failed");
|
||||
break;
|
||||
default:
|
||||
fatal("python_runtime_wsmessage: invalid op");
|
||||
}
|
||||
|
||||
if ((args = PyTuple_New(3)) == NULL)
|
||||
fatal("python_runtime_wsmessage: PyTuple_New failed");
|
||||
|
Loading…
x
Reference in New Issue
Block a user