diff mercurial/util_win32.py @ 7390:0d1c770c6be1

util_win32: implement posixfile_nt.readlines()
author Patrick Mezard <pmezard@gmail.com>
date Tue, 18 Nov 2008 13:20:55 +0100
parents d2375bbee6d4
children f21e3d0e335b
line wrap: on
line diff
--- 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: