diff mercurial/fancyopts.py @ 30583:c6ce11f2ee50

py3: make a bytes version of getopt.getopt() getopt.getopt() deals with unicodes on Python 3 internally and if bytes arguments are passed, then it will return TypeError. So we have now pycompat.getoptb() which takes bytes arguments, convert them to unicode, call getopt.getopt() and then convert the returned value back to bytes and then return those value. All the instances of getopt.getopt() are replaced with pycompat.getoptb().
author Pulkit Goyal <7895pulkit@gmail.com>
date Tue, 06 Dec 2016 06:36:36 +0530
parents e1f0ec0b7d2d
children bd872f64a8ba
line wrap: on
line diff
--- a/mercurial/fancyopts.py	Tue Dec 06 11:44:49 2016 +0000
+++ b/mercurial/fancyopts.py	Tue Dec 06 06:36:36 2016 +0530
@@ -7,10 +7,11 @@
 
 from __future__ import absolute_import
 
-import getopt
-
 from .i18n import _
-from . import error
+from . import (
+    error,
+    pycompat,
+)
 
 # Set of flags to not apply boolean negation logic on
 nevernegate = set([
@@ -34,13 +35,14 @@
         stopindex = args.index('--')
         extraargs = args[stopindex + 1:]
         args = args[:stopindex]
-    opts, parseargs = getopt.getopt(args, options, longoptions)
+    opts, parseargs = pycompat.getoptb(args, options, longoptions)
     args = []
     while parseargs:
         arg = parseargs.pop(0)
         if arg and arg[0] == '-' and len(arg) > 1:
             parseargs.insert(0, arg)
-            topts, newparseargs = getopt.getopt(parseargs, options, longoptions)
+            topts, newparseargs = pycompat.getoptb(parseargs,\
+                                            options, longoptions)
             opts = opts + topts
             parseargs = newparseargs
         else:
@@ -125,7 +127,7 @@
     if gnu:
         parse = gnugetopt
     else:
-        parse = getopt.getopt
+        parse = pycompat.getoptb
     opts, args = parse(args, shortlist, namelist)
 
     # transfer result to state