Mercurial > hg-stable
changeset 31186:99c5843b228d
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.
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 03 Mar 2017 12:55:11 -0500 |
parents | 7433b3bc55ee |
children | a7cabac20b62 |
files | mercurial/config.py |
diffstat | 1 files changed, 3 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/config.py Mon Mar 06 23:21:27 2017 -0800 +++ b/mercurial/config.py Fri Mar 03 12:55:11 2017 -0500 @@ -170,5 +170,8 @@ 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)