Patchwork D5263: py3: add b suffix to make sure file is opened in bytes mode

login
register
mail settings
Submitter phabricator
Date Nov. 13, 2018, 6:50 p.m.
Message ID <c6d460a2a4625ed5d8cd7832722af78c@localhost.localdomain>
Download mbox | patch
Permalink /patch/36556/
State Not Applicable
Headers show

Comments

phabricator - Nov. 13, 2018, 6:50 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGaa588bf40a08: py3: add b suffix to make sure file is opened in bytes mode (authored by pulkit, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5263?vs=12520&id=12526

REVISION DETAIL
  https://phab.mercurial-scm.org/D5263

AFFECTED FILES
  hgext/remotefilelog/basepack.py
  hgext/remotefilelog/basestore.py
  hgext/remotefilelog/debugcommands.py
  hgext/remotefilelog/fileserverclient.py
  hgext/remotefilelog/remotefilelogserver.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: indygreg, mercurial-devel

Patch

diff --git a/hgext/remotefilelog/remotefilelogserver.py b/hgext/remotefilelog/remotefilelogserver.py
--- a/hgext/remotefilelog/remotefilelogserver.py
+++ b/hgext/remotefilelog/remotefilelogserver.py
@@ -234,7 +234,7 @@ 
 
             f = None
             try:
-                f = util.atomictempfile(filecachepath, "w")
+                f = util.atomictempfile(filecachepath, "wb")
                 f.write(text)
             except (IOError, OSError):
                 # Don't abort if the user only has permission to read,
@@ -246,7 +246,7 @@ 
         finally:
             os.umask(oldumask)
     else:
-        with open(filecachepath, "r") as f:
+        with open(filecachepath, "rb") as f:
             text = f.read()
     return text
 
diff --git a/hgext/remotefilelog/fileserverclient.py b/hgext/remotefilelog/fileserverclient.py
--- a/hgext/remotefilelog/fileserverclient.py
+++ b/hgext/remotefilelog/fileserverclient.py
@@ -482,7 +482,7 @@ 
 
     def close(self):
         if fetches:
-            msg = ("%s files fetched over %d fetches - " +
+            msg = ("%d files fetched over %d fetches - " +
                    "(%d misses, %0.2f%% hit ratio) over %0.2fs\n") % (
                        fetched,
                        fetches,
diff --git a/hgext/remotefilelog/debugcommands.py b/hgext/remotefilelog/debugcommands.py
--- a/hgext/remotefilelog/debugcommands.py
+++ b/hgext/remotefilelog/debugcommands.py
@@ -176,7 +176,7 @@ 
 
 def parsefileblob(path, decompress):
     raw = None
-    f = open(path, "r")
+    f = open(path, "rb")
     try:
         raw = f.read()
     finally:
diff --git a/hgext/remotefilelog/basestore.py b/hgext/remotefilelog/basestore.py
--- a/hgext/remotefilelog/basestore.py
+++ b/hgext/remotefilelog/basestore.py
@@ -255,7 +255,7 @@ 
         they want to be kept alive in the store.
         """
         repospath = os.path.join(self._path, "repos")
-        with open(repospath, 'a') as reposfile:
+        with open(repospath, 'ab') as reposfile:
             reposfile.write(os.path.dirname(path) + "\n")
 
         repospathstat = os.stat(repospath)
@@ -270,7 +270,7 @@ 
             return True
 
         if self._validatecachelog:
-            with open(self._validatecachelog, 'a+') as f:
+            with open(self._validatecachelog, 'ab+') as f:
                 f.write("corrupt %s during %s\n" % (path, action))
 
         os.rename(path, path + ".corrupt")
diff --git a/hgext/remotefilelog/basepack.py b/hgext/remotefilelog/basepack.py
--- a/hgext/remotefilelog/basepack.py
+++ b/hgext/remotefilelog/basepack.py
@@ -373,8 +373,8 @@ 
             suffix=self.PACKSUFFIX + '-tmp')
         self.idxfp, self.idxpath = opener.mkstemp(
             suffix=self.INDEXSUFFIX + '-tmp')
-        self.packfp = os.fdopen(self.packfp, r'w+')
-        self.idxfp = os.fdopen(self.idxfp, r'w+')
+        self.packfp = os.fdopen(self.packfp, r'wb+')
+        self.idxfp = os.fdopen(self.idxfp, r'wb+')
         self.sha = hashlib.sha1()
         self._closed = False