# HG changeset patch # User Augie Fackler # Date 2017-03-03 17:55:11 # Node ID 99c5843b228d42c635b2771665a9eec2d0101e52 # Parent 7433b3bc55eebfa9149280339b406bd4cec64efb 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. The unusual construction using getattr is done so that StringIO/BytesIO instances can be used as well as real files. diff --git a/mercurial/config.py b/mercurial/config.py --- a/mercurial/config.py +++ b/mercurial/config.py @@ -170,5 +170,8 @@ class config(object): def read(self, path, fp=None, sections=None, remap=None): if not fp: fp = util.posixfile(path, 'rb') + assert getattr(fp, 'mode', r'rb') == r'rb', ( + 'config files must be opened in binary mode, got fp=%r mode=%r' % ( + fp, fp.mode)) self.parse(path, fp.read(), sections=sections, remap=remap, include=self.read)