[PATCH 2 of 6 py3] config: add sanity assert that files are opened as binary

Augie Fackler raf at durin42.com
Fri Mar 3 14:30:05 EST 2017


# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1488563711 18000
#      Fri Mar 03 12:55:11 2017 -0500
# Node ID 0034a661fbdc1e29e51fe8e2877467204282f669
# Parent  2a02a4ec5147f8bd6685a609ce9499b1266cc6db
config: add sanity assert that files are opened as binary

This helps with some debugging in Python 3, and shouldn't hurt
anything in Python 2.

diff --git a/mercurial/config.py b/mercurial/config.py
--- a/mercurial/config.py
+++ b/mercurial/config.py
@@ -170,4 +170,7 @@ class config(object):
     def read(self, path, fp=None, sections=None, remap=None):
         if not fp:
             fp = util.posixfile(path, r'rb')
+        assert fp.mode == r'rb', ('config files must be opened'
+                                  ' in binary mode, got fp=%r mode=%r' % (
+                                      fp, fp.mode))
         self.parse(path, fp.read(), sections, remap, self.read)


More information about the Mercurial-devel mailing list