@@ -67,7 +67,7 @@ def set_columns(cols=None):
6767 if cols is None :
6868 if os .path .exists (STTY ):
6969 try :
70- proc = subprocess .run (['/usr/bin/stty' , 'size' ], stdout = subprocess .PIPE )
70+ proc = subprocess .run (['/usr/bin/stty' , 'size' ], stdout = subprocess .PIPE , stderr = subprocess . DEVNULL )
7171 cols = str (proc .stdout .splitlines ()[0 ].decode ('utf-8' ).split (' ' )[1 ])
7272 except (AttributeError , IndexError , OSError , ValueError ):
7373 # do nothing
@@ -189,12 +189,12 @@ class ExtOption(CompleterOption):
189189
190190 def __init__ (self , * args , ** kwargs ):
191191 """Add logger to init"""
192- CompleterOption .__init__ (self , * args , ** kwargs )
192+ super () .__init__ (* args , ** kwargs )
193193 self .log = getLogger (self .__class__ .__name__ )
194194
195195 def _set_attrs (self , attrs ):
196196 """overwrite _set_attrs to allow store_or callbacks"""
197- Option ._set_attrs (self , attrs )
197+ super () ._set_attrs (attrs )
198198 if self .action == 'extend' :
199199 # alias
200200 self .action = 'add'
@@ -240,15 +240,15 @@ def process(self, opt, value, values, parser):
240240 self .log .raiseException ("%s. Use '%s%s' if the value is correct." % (errmsg , prefix , value ),
241241 exception = OptionValueError )
242242
243- return Option .process (self , opt , value , values , parser )
243+ return super () .process (opt , value , values , parser )
244244
245245 def take_action (self , action , dest , opt , value , values , parser ):
246246 """Extended take_action"""
247247 orig_action = action # keep copy
248248
249249 # dest is None for actions like shorthelp and confighelp
250250 if dest and getattr (parser ._long_opt .get ('--' + dest , '' ), 'store_or' , '' ) == 'help' :
251- Option .take_action (self , action , dest , opt , value , values , parser )
251+ super () .take_action (action , dest , opt , value , values , parser )
252252 fn = getattr (parser , 'print_%shelp' % values .help , None )
253253 if fn is None :
254254 self .log .raiseException ("Unsupported output format for help: %s" % value .help , exception = ValueError )
@@ -284,7 +284,7 @@ def take_action(self, action, dest, opt, value, values, parser):
284284 if hasattr (values , '_logaction_taken' ):
285285 values ._logaction_taken [dest ] = True
286286
287- Option .take_action (self , action , dest , opt , value , values , parser )
287+ super () .take_action (action , dest , opt , value , values , parser )
288288
289289 elif action in self .EXTOPTION_EXTRA_OPTIONS :
290290 if action in ("add" , "add_first" , "add_flex" ,):
@@ -328,7 +328,7 @@ def take_action(self, action, dest, opt, value, values, parser):
328328 self .log .raiseException (msg % (action , self .EXTOPTION_EXTRA_OPTIONS ))
329329 setattr (values , dest , lvalue )
330330 else :
331- Option .take_action (self , action , dest , opt , value , values , parser )
331+ super () .take_action (action , dest , opt , value , values , parser )
332332
333333 # set flag to mark as passed by action (ie not by default)
334334 # - distinguish from setting default value through option
@@ -345,12 +345,12 @@ class PassThroughOptionParser(OptionParser):
345345 from http://www.koders.com/python/fid9DFF5006AF4F52BA6483C4F654E26E6A20DBC73C.aspx?s=add+one#L27
346346 """
347347 def __init__ (self ):
348- OptionParser .__init__ (self , add_help_option = False , usage = SUPPRESS_USAGE )
348+ super () .__init__ (add_help_option = False , usage = SUPPRESS_USAGE )
349349
350350 def _process_long_opt (self , rargs , values ):
351351 """Extend optparse code with catch of unknown long options error"""
352352 try :
353- OptionParser ._process_long_opt (self , rargs , values )
353+ super () ._process_long_opt (rargs , values )
354354 except BadOptionError as err :
355355 self .largs .append (err .opt_str )
356356
@@ -411,13 +411,14 @@ def __init__(self, *args, **kwargs):
411411 if section_name in self .RESERVED_SECTIONS :
412412 self .log .raiseException ('Cannot use reserved name %s for section name.' % section_name )
413413
414- OptionGroup .__init__ (self , * args , ** kwargs )
414+ super ().__init__ (* args , ** kwargs )
415+
415416 self .section_name = section_name
416417 self .section_options = []
417418
418419 def add_option (self , * args , ** kwargs ):
419420 """Extract configfile section info"""
420- option = OptionGroup .add_option (self , * args , ** kwargs )
421+ option = super () .add_option (* args , ** kwargs )
421422 self .section_options .append (option )
422423
423424 return option
@@ -478,16 +479,9 @@ def __init__(self, *args, **kwargs):
478479 self .error_env_options = kwargs .pop ('error_env_options' , False )
479480 self .error_env_option_method = kwargs .pop ('error_env_option_method' , self .log .error )
480481
481- # py2.4 epilog compatibilty with py2.7 / optparse 1.5.3
482- self .epilog = kwargs .pop ('epilog' , None )
483-
484482 if 'option_class' not in kwargs :
485483 kwargs ['option_class' ] = ExtOption
486- OptionParser .__init__ (self , * args , ** kwargs )
487-
488- # redefine formatter for py2.4 compat
489- if not hasattr (self .formatter , 'format_epilog' ):
490- setattr (self .formatter , 'format_epilog' , self .formatter .format_description )
484+ super ().__init__ (* args , ** kwargs )
491485
492486 if self .epilog is None :
493487 self .epilog = []
@@ -609,7 +603,7 @@ def format_description(self, formatter):
609603
610604 def set_usage (self , usage ):
611605 """Return usage and set try to set autogenerated description."""
612- OptionParser .set_usage (self , usage )
606+ super () .set_usage (usage )
613607
614608 if self .description is None :
615609 self .description = 'NONE_AND_NOT_NONE'
@@ -623,7 +617,7 @@ def get_default_values(self):
623617 - only works by using reference to object
624618 - same for _logaction_taken
625619 """
626- values = OptionParser .get_default_values (self )
620+ values = super () .get_default_values ()
627621
628622 class ExtValues (self .VALUES_CLASS ):
629623 _action_taken = {}
@@ -633,19 +627,6 @@ class ExtValues(self.VALUES_CLASS):
633627 newvalues .__dict__ = values .__dict__ .copy ()
634628 return newvalues
635629
636- def format_help (self , formatter = None ):
637- """For py2.4 compatibility reasons (missing epilog). This is the py2.7 / optparse 1.5.3 code"""
638- if formatter is None :
639- formatter = self .formatter
640- result = []
641- if self .usage :
642- result .append (self .get_usage () + "\n " )
643- if self .description :
644- result .append (self .format_description (formatter ) + "\n " )
645- result .append (self .format_option_help (formatter ))
646- result .append (self .format_epilog (formatter ))
647- return "" .join (result )
648-
649630 def format_epilog (self , formatter ):
650631 """Allow multiple epilog parts"""
651632 res = []
@@ -694,7 +675,7 @@ def _is_enable_disable(x):
694675 def print_help (self , fh = None ):
695676 """Intercept print to file to print to string and remove the ENABLE/DISABLE options from help"""
696677 fh = self .check_help (fh )
697- OptionParser .print_help (self , fh )
678+ super () .print_help (fh )
698679
699680 def print_rsthelp (self , fh = None ):
700681 """ Print help in rst format """
@@ -797,7 +778,7 @@ def _add_help_option(self):
797778
798779 def _get_args (self , args ):
799780 """Prepend the options set through the environment"""
800- self .commandline_arguments = OptionParser ._get_args (self , args )
781+ self .commandline_arguments = super () ._get_args (args )
801782 self .get_env_options ()
802783 return self .environment_arguments + self .commandline_arguments # prepend the environment options as longopts
803784
0 commit comments