Mercurial > public > mercurial-scm > hg-stable
diff mercurial/fancyopts.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | 70d42e2ad9b4 |
line wrap: on
line diff
--- a/mercurial/fancyopts.py Sun Oct 06 09:45:02 2019 -0400 +++ b/mercurial/fancyopts.py Sun Oct 06 09:48:39 2019 -0400 @@ -19,12 +19,12 @@ # Set of flags to not apply boolean negation logic on nevernegate = { # avoid --no-noninteractive - 'noninteractive', + b'noninteractive', # These two flags are special because they cause hg to do one # thing and then exit, and so aren't suitable for use in things # like aliases anyway. - 'help', - 'version', + b'help', + b'version', } @@ -77,18 +77,18 @@ >>> opt(b'-:foo') ('', False, '', False) """ - if arg.startswith('--'): - flag, eq, val = arg.partition('=') + if arg.startswith(b'--'): + flag, eq, val = arg.partition(b'=') if flag[2:] in namelist: return flag, bool(eq), val, False - if flag[2:] + '=' in namelist: + if flag[2:] + b'=' in namelist: return flag, bool(eq), val, True - elif arg.startswith('-') and arg != '-' and not arg.startswith('-:'): + elif arg.startswith(b'-') and arg != b'-' and not arg.startswith(b'-:'): flag, val = arg[:2], arg[2:] i = shortlist.find(flag[1:]) if i >= 0: - return flag, bool(val), val, shortlist.startswith(':', i + 1) - return '', False, '', False + return flag, bool(val), val, shortlist.startswith(b':', i + 1) + return b'', False, b'', False def earlygetopt(args, shortlist, namelist, gnu=False, keepsep=False): @@ -178,7 +178,7 @@ pos = 0 while pos < len(args): arg = args[pos] - if arg == '--': + if arg == b'--': pos += not keepsep break flag, hasval, val, takeval = _earlyoptarg(arg, shortlist, namelist) @@ -261,7 +261,7 @@ try: return int(newparam) except ValueError: - abort(_('expected int')) + abort(_(b'expected int')) def _defaultopt(default): @@ -310,7 +310,7 @@ if optaliases is None: optaliases = {} namelist = [] - shortlist = '' + shortlist = b'' argmap = {} defmap = {} negations = {} @@ -324,11 +324,11 @@ # convert opts to getopt format onames = [name] onames.extend(optaliases.get(name, [])) - name = name.replace('-', '_') + name = name.replace(b'-', b'_') - argmap['-' + short] = name + argmap[b'-' + short] = name for n in onames: - argmap['--' + n] = name + argmap[b'--' + n] = name defmap[name] = _defaultopt(default) # copy defaults to state @@ -337,20 +337,20 @@ # does it take a parameter? if not defmap[name]._isboolopt(): if short: - short += ':' - onames = [n + '=' for n in onames] + short += b':' + onames = [n + b'=' for n in onames] elif name not in nevernegate: for n in onames: - if n.startswith('no-'): + if n.startswith(b'no-'): insert = n[3:] else: - insert = 'no-' + n + insert = b'no-' + n # backout (as a practical example) has both --commit and # --no-commit options, so we don't want to allow the # negations of those flags. if insert not in alllong: - assert ('--' + n) not in negations - negations['--' + insert] = '--' + n + assert (b'--' + n) not in negations + negations[b'--' + insert] = b'--' + n namelist.append(insert) if short: shortlist += short @@ -381,7 +381,7 @@ def abort(s): raise error.Abort( - _('invalid value %r for option %s, %s') + _(b'invalid value %r for option %s, %s') % (pycompat.maybebytestr(val), opt, s) )