5 ### (c) 2005 Straylight/Edgeware
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of the Python interface to mLib.
12 ### mLib/Python is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
17 ### mLib/Python is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU General Public License for more details.
22 ### You should have received a copy of the GNU General Public License
23 ### along with mLib/Python; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 LBUF_CRLF = _LBUF_CRLF
27 LBUF_STRICTCRLF = _LBUF_STRICTCRLF
29 cdef class LineBuffer:
33 def __cinit__(me, lineproc = None, eofproc = None, *hunoz, **hukairz):
34 lbuf_init(&me.b, _lbfunc, <void *>me)
35 me._line = _checkcallable(lineproc, 'line proc')
36 me._eof = _checkcallable(eofproc, 'eof proc')
41 return _tobool(me.b.f & LBUF_ENABLE)
44 if me.b.delim == _LBUF_CRLF or me.b.delim == _LBUF_STRICTCRLF:
47 return chr(me.b.delim)
49 if d == _LBUF_CRLF or d == _LBUF_STRICTCRLF:
58 raise TypeError, 'size must be positive'
59 lbuf_setsize(&me.b, sz)
63 def __set__(me, proc):
64 me._line = _checkcallable(proc, 'line proc')
70 def __set__(me, proc):
71 me._eof = _checkcallable(proc, 'eof proc')
75 if me.b.f & LBUF_ENABLE:
76 raise ValueError, 'already enabled'
77 me.b.f = me.b.f | LBUF_ENABLE
81 if not (me.b.f & LBUF_ENABLE):
82 raise ValueError, 'already disabled'
83 me.b.f = me.b.f & ~LBUF_ENABLE
87 if not (me.b.f & LBUF_ENABLE):
88 raise ValueError, 'buffer disabled'
94 return lbuf_free(&me.b, &p)
100 PyString_AsStringAndSize(str, &p, &len)
102 n = lbuf_free(&me.b, &q)
108 if not (me.b.f & LBUF_ENABLE):
110 lbuf_flush(&me.b, q, n)
111 return PyString_FromStringAndSize(p, len)
117 return _maybecall(me._line, (line,))
119 return _maybecall(me._eof, ())
121 cdef void _lbfunc(char *s, size_t n, void *arg):
127 sb.line(PyString_FromStringAndSize(s, n))
129 ###----- That's all, folks --------------------------------------------------