Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pycompat.py @ 35235:5b569d512fbd
fancyopts: use getopt.gnu_getopt()
The issue described in the docstring has been fixed since Python 20ab2260dc93,
which is in 2.7.
https://hg.python.org/cpython/rev/20ab2260dc93
https://bugs.python.org/issue4458
This fixes the handling of '--' value.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Fri, 24 Nov 2017 01:09:00 +0900 |
parents | c0a6c19690ff |
children | e66d6e938d2d |
line wrap: on
line diff
--- a/mercurial/pycompat.py Thu Nov 23 23:18:56 2017 +0900 +++ b/mercurial/pycompat.py Fri Nov 24 01:09:00 2017 +0900 @@ -214,7 +214,7 @@ def open(name, mode='r', buffering=-1): return builtins.open(name, sysstr(mode), buffering) - def getoptb(args, shortlist, namelist): + def _getoptbwrapper(orig, args, shortlist, namelist): """ Takes bytes arguments, converts them to unicode, pass them to getopt.getopt(), convert the returned values back to bytes and then @@ -224,7 +224,7 @@ args = [a.decode('latin-1') for a in args] shortlist = shortlist.decode('latin-1') namelist = [a.decode('latin-1') for a in namelist] - opts, args = getopt.getopt(args, shortlist, namelist) + opts, args = orig(args, shortlist, namelist) opts = [(a[0].encode('latin-1'), a[1].encode('latin-1')) for a in opts] args = [a.encode('latin-1') for a in args] @@ -291,8 +291,8 @@ def getdoc(obj): return getattr(obj, '__doc__', None) - def getoptb(args, shortlist, namelist): - return getopt.getopt(args, shortlist, namelist) + def _getoptbwrapper(orig, args, shortlist, namelist): + return orig(args, shortlist, namelist) strkwargs = identity byteskwargs = identity @@ -320,3 +320,9 @@ isdarwin = sysplatform == 'darwin' isposix = osname == 'posix' iswindows = osname == 'nt' + +def getoptb(args, shortlist, namelist): + return _getoptbwrapper(getopt.getopt, args, shortlist, namelist) + +def gnugetoptb(args, shortlist, namelist): + return _getoptbwrapper(getopt.gnu_getopt, args, shortlist, namelist)