[Python-Dev] Extended Buffer Interface/Protocol (original) (raw)
Neil Hodgson nyamatongwe at gmail.com
Sat Mar 24 07:08:06 CET 2007
- Previous message: [Python-Dev] Extended Buffer Interface/Protocol
- Next message: [Python-Dev] Extended Buffer Interface/Protocol
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I have developed a split vector type that implements the buffer protocol at http://scintilla.sourceforge.net/splitvector-1.0.zip
It acts as a mutable string implementing most of the sequence protocol as well as the buffer protocol. splitvector.SplitVector('c') creates a vector containing 8 bit characters and splitvector.SplitVector('u') is for Unicode.
A writable attribute bufferAppearence can be set to 0 (default) to respond to buffer protocol calls by moving the gap to the end and returning the address of all of the data. Setting bufferAppearence to 1 responds as a two segment buffer. I haven't found any code that understands responding with two segments. sre and file.write handle SplitVector fine when it responds as a single segment:
import re, splitvector x = splitvector.SplitVector("c") x[:] = "The life of brian" r = re.compile("l[a-z]*", re.M) print x y = r.search(x) print y.group(0) x.bufferAppearence = 1 y = r.search(x) print y.group(0)
produces
The life of brian life Traceback (most recent call last): File "qt.py", line 9, in y = r.search(x) TypeError: expected string or buffer
It is likely that adding multi-segment ability to sre would complexify and slow it down. OTOH multi-segment buffers may be well-suited to scatter/gather I/O calls like writev.
Neil
- Previous message: [Python-Dev] Extended Buffer Interface/Protocol
- Next message: [Python-Dev] Extended Buffer Interface/Protocol
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]