[pypy-svn] r49408 - pypy/branch/pypy-interp-file/module/_file
arigo at codespeak.net
arigo at codespeak.net
Wed Dec 5 19:56:08 CET 2007
Author: arigo
Date: Wed Dec 5 19:56:08 2007
New Revision: 49408
Modified:
pypy/branch/pypy-interp-file/module/_file/interp_file.py
Log:
Iteration.
Modified: pypy/branch/pypy-interp-file/module/_file/interp_file.py
==============================================================================
--- pypy/branch/pypy-interp-file/module/_file/interp_file.py (original)
+++ pypy/branch/pypy-interp-file/module/_file/interp_file.py Wed Dec 5 19:56:08 2007
@@ -90,6 +90,12 @@
pass
stream.close()
+ def direct_next(self):
+ line = self.getstream().readline()
+ if line == '':
+ raise OperationError(self.space.w_StopIteration, self.space.w_None)
+ return line
+
def direct_read(self, n=-1):
stream = self.getstream()
if n < 0:
@@ -158,6 +164,11 @@
def direct_write(self, data):
self.getstream().write(data)
+ def direct___iter__(self):
+ self.getstream()
+ return self
+ direct_xreadlines = direct___iter__
+
# ____________________________________________________________
#
# The 'file_' methods are the one exposed to app-level.
@@ -230,6 +241,9 @@
# NB. close() need to use the stream lock to avoid double-closes or
# close-while-another-thread-uses-it.
+ _decl(locals(), "next", ['self'],
+ """next() -> the next line in the file, or raise StopIteration""")
+
_decl(locals(), "read", ['self', int],
"""read([size]) -> read at most size bytes, returned as a string.
@@ -273,6 +287,16 @@
Note that due to buffering, flush() or close() may be needed before
the file on disk reflects the data written.""")
+ _decl(locals(), "__iter__", ['self'],
+ """Iterating over files, as in 'for line in f:', returns each line of
+the file one by one.""")
+
+ _decl(locals(), "xreadlines", ['self'],
+ """xreadlines() -> returns self.
+
+For backward compatibility. File objects now include the performance
+optimizations previously implemented in the xreadlines module.""")
+
# ____________________________________________________________
More information about the Pypy-commit
mailing list