* Included fdpass, fwatch and fdflags.
* Picked up new daemonize and versioncmp functions.
cdef extern from 'Python.h':
+ ctypedef struct PyObject:
+ pass
+ ctypedef struct PyTypeObject:
+ pass
+
object PyString_FromStringAndSize(char *p, int len)
int PyString_AsStringAndSize(obj, char **p, int *len) except -1
int PyObject_AsReadBuffer(obj, void **buf, int *len) except -1
int PyObject_TypeCheck(obj, ty)
object PyInt_FromLong(long i)
object PyLong_FromUnsignedLong(unsigned long i)
+ char *PyString_AS_STRING(string)
+ int _PyString_Resize(PyObject **string, int size) except -1
- ctypedef struct PyObject:
- pass
- ctypedef struct PyTypeObject:
- pass
void Py_INCREF(PyObject *obj)
void Py_DECREF(PyObject *obj)
int str_matchx(char *p, char *s, unsigned f)
void str_sanitize(char *d, char *p, size_t sz)
+cdef extern from 'mLib/versioncmp.h':
+ int _versioncmp "versioncmp"(char *va, char *vb)
+
#----- Form-urlencoding functions -------------------------------------------
cdef extern from 'mLib/url.h':
cdef extern from 'mLib/quis.h':
void _ego "ego"(char *prog)
char *_quis "quis"()
+
cdef extern from 'mLib/report.h':
void _moan "moan"(char *f, char *msg)
+#----- File comparison ------------------------------------------------------
+
+cdef extern from 'mLib/fwatch.h':
+ ctypedef struct fwatch:
+ pass
+ void fwatch_init(fwatch *f, char *name)
+ void fwatch_initfd(fwatch *f, int fd)
+ int fwatch_update(fwatch *f, char *name)
+ int fwatch_updatefd(fwatch *f, int fd)
+
+#----- File descriptor hacking ----------------------------------------------
+
+cdef extern from 'mLib/fdflags.h':
+ int _fdflags "fdflags"(int fd,
+ unsigned fbic, unsigned fxor,
+ unsigned fdbic, unsigned fdxor)
+
+cdef extern from 'mLib/fdpass.h':
+ int fdpass_send(int sock, int fd, void *p, size_t sz)
+ int fdpass_recv(int sock, int *fd, void *p, size_t sz)
+
+#----- Daemon utilities -----------------------------------------------------
+
+cdef extern from 'mLib/daemonize.h':
+ int _daemonize "daemonize"()
+ void _detachtty "detachtty"()
+
#----- Internal utilities ---------------------------------------------------
cdef extern from 'grim.h':
--- /dev/null
+# -*-pyrex-*-
+#
+# $Id$
+#
+# Messing with file descriptors
+#
+# (c) 2007 Straylight/Edgeware
+#
+
+#----- Licensing notice -----------------------------------------------------
+#
+# This file is part of the Python interface to mLib.
+#
+# mLib/Python is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# mLib/Python is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mLib/Python; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+def fdflags(file,
+ unsigned fbic = 0, unsigned fxor = 0,
+ unsigned fdbic = 0, unsigned fdxor = 0):
+ cdef int rc
+ rc = _fdflags(_getfd(fd), fbix, fxor, fdbic, fdxor)
+ if rc < 0:
+ _oserror()
+ return rc
+
+def fdsend(sock, file, buffer):
+ cdef void *p
+ cdef int len
+ cdef int rc
+ PyObject_AsReadBuffer(buffer, &p, &len)
+ rc = fdpass_send(_getfd(sock), _getfd(file), p, len)
+ if rc < 0:
+ _oserror()
+ return rc
+
+def fdrecv(sock, unsigned size):
+ cdef void *p
+ cdef buf
+ cdef int len
+ cdef PyObject *obj
+ cdef int fd
+ buf = PyString_FromStringAndSize(NULL, len)
+ p = PyString_AS_STRING(buf)
+ len = fdpass_recv(_getfd(sock), &fd, p, size)
+ if len < 0:
+ _oserror()
+ obj = <PyObject *>buf
+ _PyString_Resize(&obj, len)
+ return fd, <object>obj
+
+#----- That's all, folks ----------------------------------------------------
--- /dev/null
+# -*-pyrex-*-
+#
+# $Id$
+#
+# Watching files for changes
+#
+# (c) 2007 Straylight/Edgeware
+#
+
+#----- Licensing notice -----------------------------------------------------
+#
+# This file is part of the Python interface to mLib.
+#
+# mLib/Python is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# mLib/Python is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mLib/Python; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+cdef class FWatch:
+ cdef fwatch fw
+ cdef file
+ def __new__(me, file):
+ _init(me, file)
+ def __init__(me, file):
+ _init(me, file)
+ cdef _init(me, file):
+ if isinstance(file, str):
+ fwatch_init(&me.fw, file)
+ else:
+ fwatch_initfd(&me.fw, _getfd(file))
+ me.file = file
+ def update(me):
+ if isinstance(me.file, str):
+ fwatch_update(&me.fw, me.file)
+ else:
+ fwatch_initfd(&me.fw, _getfd(me.file))
+
+#----- That's all, folks ----------------------------------------------------
include 'report.pyx'
+# --- File utilities ---
+
+include 'fwatch.pyx'
+include 'fdutils.pyx'
+
+# --- Other useful stuff ---
+
+include 'stuff.pyx'
+
# --- Buffering ---
include 'lbuf.pyx'
d = buf
xfree(buf)
return d
-
+
+def versioncmp(char *va, char *vb):
+ return _versioncmp(va, vb)
#----- That's all, folks ----------------------------------------------------
--- /dev/null
+# -*-pyrex-*-
+#
+# $Id$
+#
+# Various small things
+#
+# (c) 2007 Straylight/Edgeware
+#
+
+#----- Licensing notice -----------------------------------------------------
+#
+# This file is part of the Python interface to mLib.
+#
+# mLib/Python is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# mLib/Python is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with mLib/Python; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+def detachtty():
+ _detachtty()
+
+def daemonize():
+ if _daemonize():
+ _oserror()
+
+#----- That's all, folks ----------------------------------------------------