Mercurial > public > mercurial-scm > hg-stable
diff mercurial/util.py @ 31091:2912b06905dc
py3: use pycompat.fsencode() to convert __file__ to bytes
__file__ returns unicodes on Python 3. This patch uses pycompat.fsencode() to
convert them to bytes.
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 20 Feb 2017 18:40:42 +0530 |
parents | d194f0dba7ac |
children | 3f8f53190d6a |
line wrap: on
line diff
--- a/mercurial/util.py Wed Feb 22 10:14:18 2017 -0800 +++ b/mercurial/util.py Mon Feb 20 18:40:42 2017 +0530 @@ -955,10 +955,7 @@ # executable version (py2exe) doesn't support __file__ datapath = os.path.dirname(pycompat.sysexecutable) else: - datapath = os.path.dirname(__file__) - -if not isinstance(datapath, bytes): - datapath = pycompat.fsencode(datapath) + datapath = os.path.dirname(pycompat.fsencode(__file__)) i18n.setdatapath(datapath) @@ -980,8 +977,9 @@ _sethgexecutable(encoding.environ['EXECUTABLEPATH']) else: _sethgexecutable(pycompat.sysexecutable) - elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg': - _sethgexecutable(mainmod.__file__) + elif (os.path.basename( + pycompat.fsencode(getattr(mainmod, '__file__', ''))) == 'hg'): + _sethgexecutable(pycompat.fsencode(mainmod.__file__)) else: exe = findexe('hg') or os.path.basename(sys.argv[0]) _sethgexecutable(exe)