Hey. I just had a bit of a semi insight into what might be causing the random webcit failouts on certain mails.

I just noticed that sometimes pine on the same machine also occasionally barfs out with a sig 11 when certain mails , invariably unicoded spam, turns up.

Would the locale conversion be using perhaps some lib on my machine that pine is also using that might be hosed?

Anyway, onto pythonic matters. One of the nice little advantages of python (and I suppose perl) is the monster library that it has. It makes it *really* easy to
build fairly diverse "modules" , by just dragging in some of those libraries and using em. For instance , an XML-RPC interface to citadel might be as simple as building an object in python with a bunch of neato methods for tweezling the server and then exposing it to the xmlrpc lib. Or soap lib. etc.

My take would be that there would need to be a way to register a script with the server, preferably stored outside the server (ie not in mailfolders, as that'd likely pose a security risk) and then associated with various triggers. For instance a message being routed-> route.py (if it exists) , user details change -> userchange.py, server timer ticks over -> tick.py and so on.

Looking at the documentation here;- http://www.python.org/doc/2.3.5/ext/embedding.html it seems the actual embedding is fairly straight forward.

(note all this code shameless ripped off from that documentation)

import it, run something like this to get it in memory;-
    
Py_Initialize();
pName = PyString_FromString(scriptName);
pModule = PyImport_Import(pName);

Then you get a pointer to the function to call;-

pFunc = PyObject_GetAttrString(pModule, functionName);
/* pFunc is a new reference */

if (pFunc && PyCallable_Check(pFunc)) {
...
}
Py_XDECREF(pFunc);
Then call the sucker;-
    pValue = PyObject_CallObject(pFunc, pArgs); 

with pValue being a return code and pArgs being arguments to send the function.

And thats it. Theres a bunch of string conversions in there.

From what I gather, looking at the examples , adding functions to python is like this;-
(this code from the examples just creates a python funtion that returns application argument lines)
static int numargs=0;

/* Return the number of arguments of the application command line */
static PyObject*
emb_numargs(PyObject *self, PyObject *args)
{
if(!PyArg_ParseTuple(args, ":numargs"))
return NULL;
return Py_BuildValue("i", numargs);
}

Then this;-

static PyMethodDef EmbMethods[] = {
{"numargs", emb_numargs, METH_VARARGS,
"Return the number of arguments received by the process."},
{NULL, NULL, 0, NULL}
}
which defines the methods the module would have,

then just after initialising, add this;-

numargs = argc;
Py_InitModule("emb", EmbMethods);


*Disclaimer. I just really pulled that all out of the manual to shake it into my own head more fully, but also , to show its fairly straightforward.







Reply via email to