[pypy-svn] pypy default: file.writelines should raise when its closed, even if the iterable has no items.
alex_gaynor
commits-noreply at bitbucket.org
Fri Feb 11 06:18:49 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41807:24c33ac7e91a
Date: 2011-02-11 00:18 -0500
http://bitbucket.org/pypy/pypy/changeset/24c33ac7e91a/
Log: file.writelines should raise when its closed, even if the iterable
has no items.
diff --git a/pypy/module/_file/interp_file.py b/pypy/module/_file/interp_file.py
--- a/pypy/module/_file/interp_file.py
+++ b/pypy/module/_file/interp_file.py
@@ -58,15 +58,17 @@
raise operationerrfmt(space.w_ValueError,
"invalid mode: '%s'", mode)
+ def check_closed(self):
+ if self.stream is None:
+ raise OperationError(self.space.w_ValueError,
+ self.space.wrap("I/O operation on closed file")
+ )
+
def getstream(self):
"""Return self.stream or raise an app-level ValueError if missing
(i.e. if the file is closed)."""
- stream = self.stream
- if stream is None:
- space = self.space
- raise OperationError(space.w_ValueError,
- space.wrap('I/O operation on closed file'))
- return stream
+ self.check_closed()
+ return self.stream
def _when_reading_first_flush(self, otherfile):
"""Flush otherfile before reading from self."""
@@ -399,6 +401,7 @@
producing strings. This is equivalent to calling write() for each string."""
space = self.space
+ self.check_closed()
w_iterator = space.iter(w_lines)
while True:
try:
More information about the Pypy-commit
mailing list