[Python-3000-checkins] r54798 - in python/branches/p3yk: Lib/chunk.py Lib/io.py Lib/test/test_fileinput.py Lib/test/test_io.py Lib/wave.py Modules/_fileio.c
guido.van.rossum
python-3000-checkins at python.org
Fri Apr 13 00:55:14 CEST 2007
Author: guido.van.rossum
Date: Fri Apr 13 00:55:07 2007
New Revision: 54798
Modified:
python/branches/p3yk/Lib/chunk.py
python/branches/p3yk/Lib/io.py
python/branches/p3yk/Lib/test/test_fileinput.py
python/branches/p3yk/Lib/test/test_io.py
python/branches/p3yk/Lib/wave.py
python/branches/p3yk/Modules/_fileio.c
Log:
Make a few more tests pass with the new I/O library.
Fix the truncate() semantics -- it should not affect the current position.
Switch wave.py/chunk.py to struct.unpack_from() to support bytes.
Don't use writelines() on binary files (test_fileinput.py).
Modified: python/branches/p3yk/Lib/chunk.py
==============================================================================
--- python/branches/p3yk/Lib/chunk.py (original)
+++ python/branches/p3yk/Lib/chunk.py Fri Apr 13 00:55:07 2007
@@ -62,7 +62,7 @@
if len(self.chunkname) < 4:
raise EOFError
try:
- self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]
+ self.chunksize = struct.unpack_from(strflag+'L', file.read(4))[0]
except struct.error:
raise EOFError
if inclheader:
Modified: python/branches/p3yk/Lib/io.py
==============================================================================
--- python/branches/p3yk/Lib/io.py (original)
+++ python/branches/p3yk/Lib/io.py Fri Apr 13 00:55:07 2007
@@ -551,8 +551,6 @@
def truncate(self, pos=None):
if pos is None:
pos = self._pos
- else:
- self._pos = max(0, pos)
del self._buffer[pos:]
return pos
Modified: python/branches/p3yk/Lib/test/test_fileinput.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_fileinput.py (original)
+++ python/branches/p3yk/Lib/test/test_fileinput.py Fri Apr 13 00:55:07 2007
@@ -18,7 +18,8 @@
def writeTmp(i, lines, mode='w'): # opening in text mode is the default
name = TESTFN + str(i)
f = open(name, mode)
- f.writelines(lines)
+ for line in lines:
+ f.write(line)
f.close()
return name
Modified: python/branches/p3yk/Lib/test/test_io.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_io.py (original)
+++ python/branches/p3yk/Lib/test/test_io.py Fri Apr 13 00:55:07 2007
@@ -93,7 +93,7 @@
self.assertEqual(f.seek(-1, 2), 13)
self.assertEqual(f.tell(), 13)
self.assertEqual(f.truncate(12), 12)
- self.assertEqual(f.tell(), 12)
+ self.assertEqual(f.tell(), 13)
def read_ops(self, f, buffered=False):
data = f.read(5)
@@ -135,7 +135,7 @@
self.assertEqual(f.tell(), self.LARGE + 2)
self.assertEqual(f.seek(0, 2), self.LARGE + 2)
self.assertEqual(f.truncate(self.LARGE + 1), self.LARGE + 1)
- self.assertEqual(f.tell(), self.LARGE + 1)
+ self.assertEqual(f.tell(), self.LARGE + 2)
self.assertEqual(f.seek(0, 2), self.LARGE + 1)
self.assertEqual(f.seek(-1, 2), self.LARGE)
self.assertEqual(f.read(2), b"x")
Modified: python/branches/p3yk/Lib/wave.py
==============================================================================
--- python/branches/p3yk/Lib/wave.py (original)
+++ python/branches/p3yk/Lib/wave.py Fri Apr 13 00:55:07 2007
@@ -256,9 +256,9 @@
#
def _read_fmt_chunk(self, chunk):
- wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack('<hhllh', chunk.read(14))
+ wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<hhllh', chunk.read(14))
if wFormatTag == WAVE_FORMAT_PCM:
- sampwidth = struct.unpack('<h', chunk.read(2))[0]
+ sampwidth = struct.unpack_from('<h', chunk.read(2))[0]
self._sampwidth = (sampwidth + 7) // 8
else:
raise Error, 'unknown format: %r' % (wFormatTag,)
Modified: python/branches/p3yk/Modules/_fileio.c
==============================================================================
--- python/branches/p3yk/Modules/_fileio.c (original)
+++ python/branches/p3yk/Modules/_fileio.c Fri Apr 13 00:55:07 2007
@@ -519,7 +519,7 @@
{
PyObject *posobj = NULL;
Py_off_t pos;
- int fd, whence;
+ int fd;
fd = self->fd;
if (fd < 0)
@@ -530,17 +530,14 @@
if (!PyArg_ParseTuple(args, "|O", &posobj))
return NULL;
- if (posobj == Py_None)
- posobj = NULL;
-
- if (posobj == NULL)
- whence = 1;
- else
- whence = 0;
-
- posobj = portable_lseek(fd, posobj, whence);
- if (posobj == NULL)
- return NULL;
+ if (posobj == Py_None || posobj == NULL) {
+ posobj = portable_lseek(fd, NULL, 1);
+ if (posobj == NULL)
+ return NULL;
+ }
+ else {
+ Py_INCREF(posobj);
+ }
#if !defined(HAVE_LARGEFILE_SUPPORT)
pos = PyInt_AsLong(posobj);
More information about the Python-3000-checkins
mailing list