util_win32: implement posixfile_nt.readlines()
authorPatrick Mezard <pmezard@gmail.com>
Tue, 18 Nov 2008 13:20:55 +0100
changeset 7390 0d1c770c6be1
parent 7389 72f0e4ebd9e6
child 7391 27d304c8cc03
util_win32: implement posixfile_nt.readlines()
mercurial/util_win32.py
--- a/mercurial/util_win32.py	Wed Nov 19 13:27:57 2008 +0100
+++ b/mercurial/util_win32.py	Tue Nov 18 13:20:55 2008 +0100
@@ -292,7 +292,7 @@
             raise WinIOError(err, name)
 
     def __iter__(self):
-        for line in self.read().splitlines(True):
+        for line in self.readlines():
             yield line
 
     def read(self, count=-1):
@@ -311,6 +311,11 @@
         except pywintypes.error, err:
             raise WinIOError(err)
 
+    def readlines(self, sizehint=None):
+        # splitlines() splits on single '\r' while readlines()
+        # does not. cStringIO has a well behaving readlines() and is fast.
+        return cStringIO.StringIO(self.read()).readlines()
+
     def write(self, data):
         try:
             if 'a' in self.mode: