[PATCH 2 of 4] util & scmutil: adapt read/write helpers as request by mpm

Dan Villiom Podlaski Christiansen danchr at gmail.com
Mon May 2 03:11:47 CDT 2011


# HG changeset patch
# User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
# Date 1304323865 -7200
# Node ID 294ea357cbce0b0ad2c08e8b4b7c8148bcd3bc5d
# Parent  479f03d74bf9a4509c20ed42051d059c0f11e42c
util & scmutil: adapt read/write helpers as request by mpm

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -139,15 +139,22 @@ class abstractopener(object):
         '''Prevent instantiation; don't call this from subclasses.'''
         raise NotImplementedError('attempted instantiating ' + str(type(self)))
 
-    def read(self, *args, **kwargs):
-        fp = self(*args, **kwargs)
+    def read(self, path):
+        fp = self(path, 'rb')
         try:
             return fp.read()
         finally:
             fp.close()
 
-    def write(self, data, *args, **kwargs):
-        fp = self(*args, **kwargs)
+    def write(self, path, data):
+        fp = self(path, 'wb')
+        try:
+            return fp.write(data)
+        finally:
+            fp.close()
+
+    def append(self, path, data):
+        fp = self(path, 'ab')
         try:
             return fp.write(data)
         finally:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -778,8 +778,15 @@ def readfile(path):
     finally:
         fp.close()
 
-def writefile(path, mode, text):
-    fp = open(path, mode)
+def writefile(path, text):
+    fp = open(path, 'wb')
+    try:
+        fp.write(text)
+    finally:
+        fp.close()
+
+def appendfile(path, text):
+    fp = open(path, 'ab')
     try:
         fp.write(text)
     finally:


More information about the Mercurial-devel mailing list