Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/config.py @ 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 | 8266802f0fa4 |
children | c920efa9d34b |
comparison
equal
deleted
inserted
replaced
31185:7433b3bc55ee | 31186:99c5843b228d |
---|---|
168 raise error.ParseError(l.rstrip(), ("%s:%s" % (src, line))) | 168 raise error.ParseError(l.rstrip(), ("%s:%s" % (src, line))) |
169 | 169 |
170 def read(self, path, fp=None, sections=None, remap=None): | 170 def read(self, path, fp=None, sections=None, remap=None): |
171 if not fp: | 171 if not fp: |
172 fp = util.posixfile(path, 'rb') | 172 fp = util.posixfile(path, 'rb') |
173 assert getattr(fp, 'mode', r'rb') == r'rb', ( | |
174 'config files must be opened in binary mode, got fp=%r mode=%r' % ( | |
175 fp, fp.mode)) | |
173 self.parse(path, fp.read(), | 176 self.parse(path, fp.read(), |
174 sections=sections, remap=remap, include=self.read) | 177 sections=sections, remap=remap, include=self.read) |