5 # Selecting line-buffers
7 # (c) 2005 Straylight/Edgeware
10 #----- Licensing notice -----------------------------------------------------
12 # This file is part of the Python interface to mLib.
14 # mLib/Python is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # mLib/Python is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with mLib/Python; if not, write to the Free Software Foundation,
26 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 cdef class SelLineBuffer:
32 def __new__(me, fd, lineproc = None, eofproc = None, *hunoz, **hukairz):
33 selbuf_init(&me.b, &_sel, _getfd(fd), _selbfunc, <void *>me)
35 me._line = _checkcallable(lineproc, 'line proc')
36 me._eof = _checkcallable(eofproc, 'eof proc')
41 return _tobool(me.b.b.f & LBUF_ENABLE)
47 if me.b.b.delim == _LBUF_CRLF or me.b.b.delim == _LBUF_STRICTCRLF:
50 return chr(me.b.b.delim)
52 if d == _LBUF_CRLF or d == _LBUF_STRICTCRLF:
61 raise TypeError, 'size must be positive'
62 selbuf_setsize(&me.b, sz)
66 def __set__(me, proc):
67 me._line = _checkcallable(proc, 'line proc')
73 def __set__(me, proc):
74 me._eof = _checkcallable(proc, 'eof proc')
78 if me.b.b.f & LBUF_ENABLE:
79 raise ValueError, 'already enabled'
84 if not (me.b.b.f & LBUF_ENABLE):
85 raise ValueError, 'already disabled'
94 return _maybecall(me._line, (line,))
96 return _maybecall(me._eof, ())
98 cdef void _selbfunc(char *s, size_t n, void *arg):
100 sb = <SelLineBuffer>arg
104 sb.line(PyString_FromStringAndSize(s, n))
106 #----- That's all, folks ----------------------------------------------------