[Python-checkins] r46451 - in sandbox/trunk/hotbuffer: Modules/_hotbuf.c README.txt test_hotbuf.py
martin.blais
python-checkins at python.org
Sat May 27 13:53:45 CEST 2006
Author: martin.blais
Date: Sat May 27 13:53:45 2006
New Revision: 46451
Modified:
sandbox/trunk/hotbuffer/Modules/_hotbuf.c
sandbox/trunk/hotbuffer/README.txt
sandbox/trunk/hotbuffer/test_hotbuf.py
Log:
Fixed a few bugs and line delimited use case.
Modified: sandbox/trunk/hotbuffer/Modules/_hotbuf.c
==============================================================================
--- sandbox/trunk/hotbuffer/Modules/_hotbuf.c (original)
+++ sandbox/trunk/hotbuffer/Modules/_hotbuf.c Sat May 27 13:53:45 2006
@@ -466,13 +466,14 @@
This does then not increment the position.");
static PyObject*
-hotbuf_getbyterel(PyHotbufObject *self, PyObject* args)
+hotbuf_getbyterel(PyHotbufObject *self, PyObject* arg)
{
- Py_ssize_t offset;
+ Py_ssize_t offset = -1;
Py_ssize_t read_position;
/* Extract the offset */
- if (!PyArg_ParseTuple(args, "n:hotbuf", &offset))
+ offset = PyInt_AsSsize_t(arg);
+ if (offset == -1 && PyErr_Occurred())
return NULL;
/* Validate position */
@@ -480,7 +481,7 @@
CHECK_LIMIT_RETURN(read_position, NULL);
/* Note that we do not increment, on purpose. */
- return PyInt_FromLong(*(unsigned char*)(read_position));
+ return PyInt_FromLong(*(unsigned char*)(self->b_ptr + read_position));
}
Modified: sandbox/trunk/hotbuffer/README.txt
==============================================================================
--- sandbox/trunk/hotbuffer/README.txt (original)
+++ sandbox/trunk/hotbuffer/README.txt Sat May 27 13:53:45 2006
@@ -21,6 +21,11 @@
TODO
====
+* Should getbyterel() implement getting negative offsets from the end of the
+ window?
+
+ - BTW getbyterel() should be implemented using the slicing operators
+
* Remove the advbytes argument to pop(), it is confusing.
* Remove the mark, save() and restore().
Modified: sandbox/trunk/hotbuffer/test_hotbuf.py
==============================================================================
--- sandbox/trunk/hotbuffer/test_hotbuf.py (original)
+++ sandbox/trunk/hotbuffer/test_hotbuf.py Sat May 27 13:53:45 2006
@@ -402,6 +402,7 @@
# Initiallly put some data into the buffer.
hot.putstr(read(len(hot)))
+ hot.flip()
# Look over the entire input.
while 1:
@@ -409,23 +410,16 @@
abslimit = hot.limit
mark_position = hot.position # setmark
- print 1, repr(hot)
-
-
# Loop over the current buffer contents
while hot:
# Save the starting position
start = hot.position
- print 2, repr(hot)
-
## FIXME we need to replace what follows by the hot.find method, the
## overhead of funcall for every char is too high
# Loop over all characters
while 1:
- print 3, repr(hot)
-
# If we got to the end of the line
if hot.getbyte() == newline:
# Process the line we found
@@ -434,9 +428,10 @@
# backup to remove the EOL marker
end = hot.position
backup = 1
+
# Make sure we don't look before the first char
if end - start > 1:
- if hot.getbyte(end - 2) == cr:
+ if hot.getbyterel(-2) == cr:
backup = 2
# Restrict the window to the current line
@@ -448,8 +443,8 @@
# Advance the buffer window to the rest of the
# buffer after the line
+ hot.limit = abslimit
mark_position = hot.position = end
- hot.limit(abslimit)
break
@@ -457,8 +452,6 @@
if not hot:
break
- print 4, repr(hot)
-
# Set the position to the last marker
hot.position = mark_position # reset
@@ -470,6 +463,7 @@
if not s:
break # Finished the input, exit.
hot.putstr(s)
+ hot.flip()
def test_newline_delim_data( self ):
"""
@@ -481,8 +475,7 @@
lineidx = [0]
def assert_lines( hot ):
"Assert the lines we process are the ones we expect."
- print hot
- self.assertEquals(hot, self.lines1[lineidx[0]])
+ self.assertEquals(str(hot), self.lines1[lineidx[0]])
lineidx[0] += 1
self.parse_newline_delim(hot, inp.read, assert_lines)
@@ -647,7 +640,7 @@
#
def test_main():
test_support.run_unittest(HotbufTestCase)
- #test_support.run_unittest(HotbufUseCases)
+ test_support.run_unittest(HotbufUseCases)
if __name__ == "__main__":
test_main()
More information about the Python-checkins
mailing list