Merged revisions 56020-56124 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/branches/p3yk

................
  r56037 | georg.brandl | 2007-06-19 05:33:20 -0700 (Tue, 19 Jun 2007) | 2 lines

  Patch #1739659: don't slice dict.keys() in pydoc.
................
  r56060 | martin.v.loewis | 2007-06-21 13:00:02 -0700 (Thu, 21 Jun 2007) | 2 lines

  Regenerate to add True, False, None.
................
  r56069 | neal.norwitz | 2007-06-21 22:31:56 -0700 (Thu, 21 Jun 2007) | 1 line

  Get the doctest working again after adding None, True, and False as kewyords.
................
  r56070 | neal.norwitz | 2007-06-21 23:25:33 -0700 (Thu, 21 Jun 2007) | 1 line

  Add space to error message.
................
  r56071 | neal.norwitz | 2007-06-21 23:40:04 -0700 (Thu, 21 Jun 2007) | 6 lines

  Get pybench working, primarily
   * Use print function
   * Stop using string module
   * Use sorted instead of assuming dict methods return lists
   * Convert range result to a list
................
  r56089 | collin.winter | 2007-06-26 10:31:48 -0700 (Tue, 26 Jun 2007) | 1 line

  Fix AttributeError in distutils/dir_util.py.
................
  r56124 | guido.van.rossum | 2007-06-29 18:04:31 -0700 (Fri, 29 Jun 2007) | 30 lines

  Merged revisions 56014-56123 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r56019 | lars.gustaebel | 2007-06-18 04:42:11 -0700 (Mon, 18 Jun 2007) | 2 lines

    Added exclude keyword argument to the TarFile.add() method.
  ........
    r56023 | lars.gustaebel | 2007-06-18 13:05:55 -0700 (Mon, 18 Jun 2007) | 3 lines

    Added missing \versionchanged tag for the new exclude
    parameter.
  ........
    r56038 | georg.brandl | 2007-06-19 05:36:00 -0700 (Tue, 19 Jun 2007) | 2 lines

    Bug #1737864: allow empty message in logging format routines.
  ........
    r56040 | georg.brandl | 2007-06-19 05:38:20 -0700 (Tue, 19 Jun 2007) | 2 lines

    Bug #1739115: make shutil.rmtree docs clear wrt. file deletion.
  ........
    r56084 | georg.brandl | 2007-06-25 08:21:23 -0700 (Mon, 25 Jun 2007) | 2 lines

    Bug #1742901: document None behavior of shlex.split.
  ........
    r56091 | georg.brandl | 2007-06-27 07:09:56 -0700 (Wed, 27 Jun 2007) | 2 lines

    Fix a variable name in winreg docs.
  ........
................
This commit is contained in:
Guido van Rossum 2007-06-30 05:01:58 +00:00
parent 8ddff70822
commit 486364b821
20 changed files with 286 additions and 253 deletions

View file

@ -20,7 +20,7 @@ or contact the author. All Rights Reserved.
__version__ = '1.2'
import sys, getopt, string, glob, os, re, exceptions, traceback
import sys, getopt, glob, os, re, traceback
### Helpers
@ -44,7 +44,7 @@ def _getopt_flags(options):
l.append(o.name+'=')
else:
l.append(o.name)
return string.join(s,''),l
return ''.join(s), l
def invisible_input(prompt='>>> '):
@ -102,7 +102,7 @@ _integerRangeRE = re.compile('\s*(-?\d+)\s*-\s*(-?\d+)\s*$')
def srange(s,
split=string.split,integer=_integerRE,
integer=_integerRE,
integerRange=_integerRangeRE):
""" Converts a textual representation of integer numbers and ranges
@ -116,7 +116,7 @@ def srange(s,
"""
l = []
append = l.append
for entry in split(s,','):
for entry in s.split(','):
m = integer.match(entry)
if m:
append(int(m.groups()[0]))
@ -293,7 +293,7 @@ class Application:
verbose = 0
# Internal errors to catch
InternalError = exceptions.Exception
InternalError = BaseException
# Instance variables:
values = None # Dictionary of passed options (or default values)
@ -353,20 +353,20 @@ class Application:
pass
except KeyboardInterrupt:
print
print '* User Break'
print
print()
print('* User Break')
print()
rc = 1
except self.InternalError:
print
print '* Internal Error (use --debug to display the traceback)'
print()
print('* Internal Error (use --debug to display the traceback)')
if self.debug:
print
print()
traceback.print_exc(20, sys.stdout)
elif self.verbose:
print ' %s: %s' % sys.exc_info()[:2]
print
print(' %s: %s' % sys.exc_info()[:2])
print()
rc = 1
raise SystemExit(rc)
@ -449,13 +449,13 @@ class Application:
# Try to convert value to integer
try:
value = string.atoi(value)
value = int(value)
except ValueError:
pass
# Find handler and call it (or count the number of option
# instances on the command line)
handlername = 'handle' + string.replace(optionname, '-', '_')
handlername = 'handle' + optionname.replace('-', '_')
try:
handler = getattr(self, handlername)
except AttributeError:
@ -494,54 +494,55 @@ class Application:
self.print_header()
if self.synopsis:
print 'Synopsis:'
print('Synopsis:')
# To remain backward compatible:
try:
synopsis = self.synopsis % self.name
except (NameError, KeyError, TypeError):
synopsis = self.synopsis % self.__dict__
print ' ' + synopsis
print
print(' ' + synopsis)
print()
self.print_options()
if self.version:
print 'Version:'
print ' %s' % self.version
print
print('Version:')
print(' %s' % self.version)
print()
if self.about:
print string.strip(self.about % self.__dict__)
print
about = self.about % self.__dict__
print(about.strip())
print()
if note:
print '-'*72
print 'Note:',note
print
print('-'*72)
print('Note:',note)
print()
def notice(self,note):
print '-'*72
print 'Note:',note
print '-'*72
print
print('-'*72)
print('Note:',note)
print('-'*72)
print()
def print_header(self):
print '-'*72
print self.header % self.__dict__
print '-'*72
print
print('-'*72)
print(self.header % self.__dict__)
print('-'*72)
print()
def print_options(self):
options = self.options
print 'Options and default settings:'
print('Options and default settings:')
if not options:
print ' None'
print(' None')
return
long = filter(lambda x: x.prefix == '--', options)
short = filter(lambda x: x.prefix == '-', options)
items = short + long
for o in options:
print ' ',o
print
print(' ',o)
print()
#
# Example handlers:
@ -579,26 +580,29 @@ class Application:
self.debug = 1
# We don't want to catch internal errors:
self.InternalError = None
class NoErrorToCatch(Exception): pass
self.InternalError = NoErrorToCatch
def handle__copyright(self,arg):
self.print_header()
print string.strip(self.copyright % self.__dict__)
print
copyright = self.copyright % self.__dict__
print(copyright.strip())
print()
return 0
def handle__examples(self,arg):
self.print_header()
if self.examples:
print 'Examples:'
print
print string.strip(self.examples % self.__dict__)
print
print('Examples:')
print()
examples = self.examples % self.__dict__
print(examples.strip())
print()
else:
print 'No examples available.'
print
print('No examples available.')
print()
return 0
def main(self):
@ -624,13 +628,13 @@ def _test():
options = [Option('-v','verbose')]
def handle_v(self,arg):
print 'VERBOSE, Yeah !'
print('VERBOSE, Yeah !')
cmd = MyApplication()
if not cmd.values['-h']:
cmd.help()
print 'files:',cmd.files
print 'Bye...'
print('files:',cmd.files)
print('Bye...')
if __name__ == '__main__':
_test()