|
|
|
@ -46,7 +46,7 @@ type: bool
|
|
|
|
|
}
|
|
|
|
|
%% to_pyobj
|
|
|
|
|
{
|
|
|
|
|
return PyInt_FromLong(val ? 1 : 0);
|
|
|
|
|
return PyLong_FromLong(val ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
@ -69,9 +69,9 @@ type:int
|
|
|
|
|
%doc as int i
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
if (!PyInt_Check(obj)) return false;
|
|
|
|
|
if (!PyLong_Check(obj)) return false;
|
|
|
|
|
if (str) {
|
|
|
|
|
(*str) << (TQ_INT32)PyInt_AsLong(obj);
|
|
|
|
|
(*str) << (TQ_INT32)PyLong_AsLong(obj);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -79,7 +79,7 @@ type:int
|
|
|
|
|
{
|
|
|
|
|
TQ_INT32 i;
|
|
|
|
|
(*str) >> i;
|
|
|
|
|
return PyInt_FromLong( (long)i );
|
|
|
|
|
return PyLong_FromLong( (long)i );
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -87,9 +87,9 @@ type:uint
|
|
|
|
|
%doc as int i
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
if (!PyInt_Check(obj)) return false;
|
|
|
|
|
if (!PyLong_Check(obj)) return false;
|
|
|
|
|
if (str) {
|
|
|
|
|
(*str) << (TQ_INT32)PyInt_AsLong(obj);
|
|
|
|
|
(*str) << (TQ_INT32)PyLong_AsLong(obj);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -97,7 +97,7 @@ type:uint
|
|
|
|
|
{
|
|
|
|
|
TQ_INT32 i;
|
|
|
|
|
(*str) >> i;
|
|
|
|
|
return PyInt_FromLong( (long)i );
|
|
|
|
|
return PyLong_FromLong( (long)i );
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -124,17 +124,17 @@ type:uchar
|
|
|
|
|
%doc as int c
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
if (PyString_Check(obj) && PyString_Size(obj)==1) {
|
|
|
|
|
if (PyBytes_Check(obj) && PyBytes_Size(obj)==1) {
|
|
|
|
|
if (str) {
|
|
|
|
|
char *c = PyString_AsString(obj);
|
|
|
|
|
char *c = PyBytes_AS_STRING(obj);
|
|
|
|
|
(*str) << (*c);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PyInt_Check(obj)) {
|
|
|
|
|
if (PyLong_Check(obj)) {
|
|
|
|
|
if (str) {
|
|
|
|
|
long l = PyInt_AsLong(obj);
|
|
|
|
|
long l = PyLong_AsLong(obj);
|
|
|
|
|
TQ_UINT8 c = (TQ_UINT8)(l & 0xff);
|
|
|
|
|
(*str) << c;
|
|
|
|
|
}
|
|
|
|
@ -147,7 +147,7 @@ type:uchar
|
|
|
|
|
{
|
|
|
|
|
TQ_UINT8 c;
|
|
|
|
|
(*str) >> c;
|
|
|
|
|
return PyString_FromStringAndSize((const char *)(&c),1);
|
|
|
|
|
return PyBytes_FromStringAndSize((const char *)(&c),1);
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -155,9 +155,9 @@ type:char
|
|
|
|
|
%doc as int c
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
if (PyInt_Check(obj)) {
|
|
|
|
|
if (PyLong_Check(obj)) {
|
|
|
|
|
if (str) {
|
|
|
|
|
long l = PyInt_AsLong(obj);
|
|
|
|
|
long l = PyLong_AsLong(obj);
|
|
|
|
|
TQ_INT8 c = (TQ_INT8)(l & 0xff);
|
|
|
|
|
(*str) << c;
|
|
|
|
|
}
|
|
|
|
@ -170,7 +170,7 @@ type:char
|
|
|
|
|
{
|
|
|
|
|
TQ_INT8 c;
|
|
|
|
|
(*str) >> c;
|
|
|
|
|
return PyInt_FromLong((long)c);
|
|
|
|
|
return PyLong_FromLong((long)c);
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -178,38 +178,30 @@ type:char
|
|
|
|
|
type:TQByteArray
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;
|
|
|
|
|
|
|
|
|
|
if ( pb && pb->bf_getreadbuffer && pb->bf_getsegcount )
|
|
|
|
|
Py_buffer view;
|
|
|
|
|
if (PyObject_GetBuffer(obj, &view, PyBUF_WRITABLE|PyBUF_SIMPLE))
|
|
|
|
|
{
|
|
|
|
|
// Get the number of buffer segments
|
|
|
|
|
int seg_count = (pb->bf_getsegcount)(obj, 0);
|
|
|
|
|
|
|
|
|
|
if ( seg_count != 1 )
|
|
|
|
|
// Can't handle more (or less) than 1 buffer segment
|
|
|
|
|
// at the moment
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get buffer size and data
|
|
|
|
|
void *data;
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
if ( (size = (pb->bf_getreadbuffer)(obj, 0, &data)) < 0 )
|
|
|
|
|
int size = view.len;
|
|
|
|
|
if (size < 0)
|
|
|
|
|
{
|
|
|
|
|
PyBuffer_Release(&view);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (str) {
|
|
|
|
|
if (str)
|
|
|
|
|
{
|
|
|
|
|
TQByteArray a;
|
|
|
|
|
a.setRawData( (const char*)data, size );
|
|
|
|
|
a.setRawData((const char*)view.buf, size);
|
|
|
|
|
(*str) << a;
|
|
|
|
|
a.resetRawData( (const char*)data, size );
|
|
|
|
|
a.resetRawData((const char*)view.buf, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyBuffer_Release(&view);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
// obj does not implement the buffer interface
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
%% demarshal
|
|
|
|
|
{
|
|
|
|
|
// Demarshal to a writable buffer object
|
|
|
|
@ -219,25 +211,8 @@ type:TQByteArray
|
|
|
|
|
uint size = a.size();
|
|
|
|
|
char *data = a.data();
|
|
|
|
|
|
|
|
|
|
// Create a new buffer object and copy the data.
|
|
|
|
|
// Don't use PyBuffer_FromMemory() and the likes since
|
|
|
|
|
// that wouldn't give correct allocation and deallocation.
|
|
|
|
|
|
|
|
|
|
PyObject *buffer_obj = PyBuffer_New( size );
|
|
|
|
|
|
|
|
|
|
if ( !buffer_obj )
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
PyBufferProcs *pb = buffer_obj->ob_type->tp_as_buffer;
|
|
|
|
|
|
|
|
|
|
void *buffer_data;
|
|
|
|
|
|
|
|
|
|
(pb->bf_getwritebuffer)( buffer_obj, 0, &buffer_data );
|
|
|
|
|
|
|
|
|
|
for ( uint i = 0; i < size; i++ )
|
|
|
|
|
((char*)buffer_data)[i] = data[i];
|
|
|
|
|
|
|
|
|
|
return buffer_obj;
|
|
|
|
|
// Demarshal to a writable buffer object
|
|
|
|
|
return PyBytes_FromStringAndSize(data, size);
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -245,9 +220,9 @@ type:TQString
|
|
|
|
|
%doc as str s
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
if (!PyString_Check(obj)) return false;
|
|
|
|
|
if (!PyBytes_Check(obj)) return false;
|
|
|
|
|
if (str) {
|
|
|
|
|
TQString s( PyString_AsString(obj) );
|
|
|
|
|
TQString s = TQString::fromUtf8(PyBytes_AS_STRING(obj));
|
|
|
|
|
(*str) << s;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -256,7 +231,7 @@ type:TQString
|
|
|
|
|
{
|
|
|
|
|
TQString s;
|
|
|
|
|
(*str) >> s;
|
|
|
|
|
return PyString_FromString( s.utf8().data() );
|
|
|
|
|
return PyBytes_FromString( s.utf8().data() );
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -264,9 +239,9 @@ type:TQCString
|
|
|
|
|
%doc as str s
|
|
|
|
|
%% marshal
|
|
|
|
|
{
|
|
|
|
|
if (!PyString_Check(obj)) return false;
|
|
|
|
|
if (!PyBytes_Check(obj)) return false;
|
|
|
|
|
if (str) {
|
|
|
|
|
TQCString s( PyString_AsString(obj) );
|
|
|
|
|
TQCString s( PyBytes_AS_STRING(obj) );
|
|
|
|
|
(*str) << s;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -275,7 +250,7 @@ type:TQCString
|
|
|
|
|
{
|
|
|
|
|
TQCString s;
|
|
|
|
|
(*str) >> s;
|
|
|
|
|
return PyString_FromString( s.data() );
|
|
|
|
|
return PyBytes_FromString( s.data() );
|
|
|
|
|
}
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
@ -473,13 +448,6 @@ type:TQDateTime
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PyInt_Check(obj)) {
|
|
|
|
|
*ok=true;
|
|
|
|
|
TQDateTime dt;
|
|
|
|
|
dt.setTime_t( (uint)PyInt_AsLong(obj) );
|
|
|
|
|
return dt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PyObject *date_tuple, *time_tuple;
|
|
|
|
|
if (PyArg_ParseTuple(obj, (char*)"OO", &date_tuple, &time_tuple)) {
|
|
|
|
|
TQDateTime dt;
|
|
|
|
@ -507,13 +475,13 @@ type:KURL
|
|
|
|
|
%% from_pyobj
|
|
|
|
|
{
|
|
|
|
|
*ok=false;
|
|
|
|
|
if (!PyString_Check(obj)) return KURL();
|
|
|
|
|
if (!PyBytes_Check(obj)) return KURL();
|
|
|
|
|
*ok=true;
|
|
|
|
|
return KURL( TQString(PyString_AsString(obj)) );
|
|
|
|
|
return KURL( TQString::fromUtf8(PyBytes_AS_STRING(obj)) );
|
|
|
|
|
}
|
|
|
|
|
%% to_pyobj
|
|
|
|
|
{
|
|
|
|
|
return PyString_FromString( val.prettyURL().utf8().data() );
|
|
|
|
|
return PyBytes_FromString( val.prettyURL().utf8().data() );
|
|
|
|
|
}
|
|
|
|
|
%% marshal
|
|
|
|
|
%defaultcode
|
|
|
|
@ -524,14 +492,14 @@ type:KURL
|
|
|
|
|
type:DCOPRef
|
|
|
|
|
%% from_pyobj
|
|
|
|
|
{
|
|
|
|
|
if (PyInstance_Check(obj) &&
|
|
|
|
|
if (PyType_Check(obj) &&
|
|
|
|
|
PyObject_HasAttrString(obj, (char*)"appname") &&
|
|
|
|
|
PyObject_HasAttrString(obj, (char*)"name")) {
|
|
|
|
|
PyObject *appname = PyObject_GetAttrString(obj, (char*)"appname");
|
|
|
|
|
PyObject *name = PyObject_GetAttrString(obj, (char*)"name");
|
|
|
|
|
if (PyString_Check(appname) && PyString_Check(name)) {
|
|
|
|
|
char *c_appname = PyString_AsString(appname);
|
|
|
|
|
char *c_name = PyString_AsString(name);
|
|
|
|
|
if (PyBytes_Check(appname) && PyBytes_Check(name)) {
|
|
|
|
|
char *c_appname = PyBytes_AS_STRING(appname);
|
|
|
|
|
char *c_name = PyBytes_AS_STRING(name);
|
|
|
|
|
DCOPRef ref;
|
|
|
|
|
ref.setRef(TQCString(c_appname), TQCString(c_name) );
|
|
|
|
|
Py_DECREF(appname);
|
|
|
|
|