summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-04-12 22:55:07 +0000
committerGuido van Rossum <guido@python.org>2007-04-12 22:55:07 +0000
commitdc0b1a106981ee204936221f4e0863bd1d7a6ba6 (patch)
tree102949af2918a30ac4da920751e994c0df4af702 /Lib
parentb6f1fdc90ca1f5826c5bd8e015a37563923144b5 (diff)
downloadcpython-git-dc0b1a106981ee204936221f4e0863bd1d7a6ba6.tar.gz
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).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/chunk.py2
-rw-r--r--Lib/io.py2
-rw-r--r--Lib/test/test_fileinput.py3
-rw-r--r--Lib/test/test_io.py4
-rw-r--r--Lib/wave.py4
5 files changed, 7 insertions, 8 deletions
diff --git a/Lib/chunk.py b/Lib/chunk.py
index a8fbc1051f..32aada8aef 100644
--- a/Lib/chunk.py
+++ b/Lib/chunk.py
@@ -62,7 +62,7 @@ class Chunk:
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:
diff --git a/Lib/io.py b/Lib/io.py
index 4465e9e9e5..8b5c958691 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -551,8 +551,6 @@ class _MemoryIOMixin(BufferedIOBase):
def truncate(self, pos=None):
if pos is None:
pos = self._pos
- else:
- self._pos = max(0, pos)
del self._buffer[pos:]
return pos
diff --git a/Lib/test/test_fileinput.py b/Lib/test/test_fileinput.py
index 2b7b255dae..b7f84c686a 100644
--- a/Lib/test/test_fileinput.py
+++ b/Lib/test/test_fileinput.py
@@ -18,7 +18,8 @@ from fileinput import FileInput, hook_encoded
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
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 737dfab36b..1f6be02ca5 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -93,7 +93,7 @@ class IOTest(unittest.TestCase):
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 @@ class IOTest(unittest.TestCase):
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")
diff --git a/Lib/wave.py b/Lib/wave.py
index 08c51ba90c..dd5a47a6ea 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -256,9 +256,9 @@ class Wave_read:
#
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,)