Patchwork [2,of,4,py3] ui: explicitly open config files in binary mode

login
register
mail settings
Submitter Augie Fackler
Date Nov. 9, 2016, 4:23 p.m.
Message ID <576e4c82886c7e5cf59f.1478708619@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/17417/
State Accepted
Headers show

Comments

Augie Fackler - Nov. 9, 2016, 4:23 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1476019069 14400
#      Sun Oct 09 09:17:49 2016 -0400
# Node ID 576e4c82886c7e5cf59f7b95b38e0f3c29932581
# Parent  6f2a1367baa59f33fcbc328aea1a637658ce345e
ui: explicitly open config files in binary mode

This has been working mostly accidentally, but now it works explicitly.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -176,7 +176,7 @@  class ui(object):
     def readconfig(self, filename, root=None, trust=False,
                    sections=None, remap=None):
         try:
-            fp = open(filename)
+            fp = open(filename, u'rb')
         except IOError:
             if not sections: # ignore unless we were looking for something
                 return
diff --git a/tests/test-check-py3-commands.t b/tests/test-check-py3-commands.t
--- a/tests/test-check-py3-commands.t
+++ b/tests/test-check-py3-commands.t
@@ -9,6 +9,6 @@  The full traceback is hidden to have a s
   >   $PYTHON3 `which hg` $cmd 2>&1 2>&1 | tail -1
   > done
   version
-  TypeError: startswith first arg must be str or a tuple of str, not bytes
+  TypeError: cannot use a string pattern on a bytes-like object
   debuginstall
-  TypeError: startswith first arg must be str or a tuple of str, not bytes
+  TypeError: cannot use a string pattern on a bytes-like object