# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1487596242 -19800 # Node ID 2912b06905dceb4fd668cd0a8d815ac9a001664b # Parent 2cf1e5207fdfb3beac255dbacf74b8ac03e5125d 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. diff -r 2cf1e5207fdf -r 2912b06905dc mercurial/debugcommands.py --- a/mercurial/debugcommands.py Wed Feb 22 10:14:18 2017 -0800 +++ b/mercurial/debugcommands.py Mon Feb 20 18:40:42 2017 +0530 @@ -692,7 +692,7 @@ fm = ui.formatter('debugextensions', opts) for extname, extmod in sorted(exts, key=operator.itemgetter(0)): isinternal = extensions.ismoduleinternal(extmod) - extsource = extmod.__file__ + extsource = pycompat.fsencode(extmod.__file__) if isinternal: exttestedwith = [] # never expose magic string to users else: @@ -970,7 +970,7 @@ fm.write('hgmodulepolicy', _("checking module policy (%s)\n"), policy.policy) fm.write('hgmodules', _("checking installed modules (%s)...\n"), - os.path.dirname(__file__)) + os.path.dirname(pycompat.fsencode(__file__))) err = None try: diff -r 2cf1e5207fdf -r 2912b06905dc mercurial/extensions.py --- a/mercurial/extensions.py Wed Feb 22 10:14:18 2017 -0800 +++ b/mercurial/extensions.py Mon Feb 20 18:40:42 2017 +0530 @@ -362,7 +362,8 @@ '''find paths of disabled extensions. returns a dict of {name: path} removes /__init__.py from packages if strip_init is True''' import hgext - extpath = os.path.dirname(os.path.abspath(hgext.__file__)) + extpath = os.path.dirname( + os.path.abspath(pycompat.fsencode(hgext.__file__))) try: # might not be a filesystem path files = os.listdir(extpath) except OSError: diff -r 2cf1e5207fdf -r 2912b06905dc mercurial/i18n.py --- a/mercurial/i18n.py Wed Feb 22 10:14:18 2017 -0800 +++ b/mercurial/i18n.py Mon Feb 20 18:40:42 2017 +0530 @@ -21,7 +21,7 @@ if getattr(sys, 'frozen', None) is not None: module = pycompat.sysexecutable else: - module = __file__ + module = pycompat.fsencode(__file__) try: unicode diff -r 2cf1e5207fdf -r 2912b06905dc mercurial/sslutil.py --- a/mercurial/sslutil.py Wed Feb 22 10:14:18 2017 -0800 +++ b/mercurial/sslutil.py Mon Feb 20 18:40:42 2017 +0530 @@ -720,7 +720,8 @@ # to load the system CA store. If we're running on Apple Python, use this # trick. if _plainapplepython(): - dummycert = os.path.join(os.path.dirname(__file__), 'dummycert.pem') + dummycert = os.path.join( + os.path.dirname(pycompat.fsencode(__file__)), 'dummycert.pem') if os.path.exists(dummycert): return dummycert diff -r 2cf1e5207fdf -r 2912b06905dc mercurial/statprof.py --- a/mercurial/statprof.py Wed Feb 22 10:14:18 2017 -0800 +++ b/mercurial/statprof.py Mon Feb 20 18:40:42 2017 +0530 @@ -724,7 +724,7 @@ if path in _pathcache: return _pathcache[path] - hgpath = encoding.__file__.rsplit(os.sep, 2)[0] + hgpath = pycompat.fsencode(encoding.__file__).rsplit(os.sep, 2)[0] for p in [hgpath] + sys.path: prefix = p + os.sep if path.startswith(prefix): diff -r 2cf1e5207fdf -r 2912b06905dc mercurial/util.py --- 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)