Back to index

python3.2  3.2.2
Classes | Functions | Variables
distutils.fancy_getopt Namespace Reference

Classes

class  FancyGetopt
class  OptionDummy

Functions

def fancy_getopt
def wrap_text
def translate_longopt

Variables

string longopt_pat = r'[a-zA-Z](?:[a-zA-Z0-9-]*)'
tuple longopt_re = re.compile(r'^%s$' % longopt_pat)
tuple neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))
tuple longopt_xlate = str.maketrans('-', '_')
dictionary WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}
string text

Detailed Description

distutils.fancy_getopt

Wrapper around the standard getopt module that provides the following
additional features:
  * short and long options are tied together
  * options have help strings, so fancy_getopt could potentially
    create a complete usage summary
  * options set attributes of a passed-in object

Function Documentation

def distutils.fancy_getopt.fancy_getopt (   options,
  negative_opt,
  object,
  args 
)

Definition at line 367 of file fancy_getopt.py.

00367 
00368 def fancy_getopt(options, negative_opt, object, args):
00369     parser = FancyGetopt(options)
00370     parser.set_negative_aliases(negative_opt)
00371     return parser.getopt(args, object)
00372 

Convert a long option name to a valid Python identifier by
changing "-" to "_".

Definition at line 429 of file fancy_getopt.py.

00429 
00430 def translate_longopt(opt):
00431     """Convert a long option name to a valid Python identifier by
00432     changing "-" to "_".
00433     """
00434     return opt.translate(longopt_xlate)
00435 

Here is the caller graph for this function:

def distutils.fancy_getopt.wrap_text (   text,
  width 
)
wrap_text(text : string, width : int) -> [string]

Split 'text' into multiple lines of no more than 'width' characters
each, and return the list of strings that results.

Definition at line 375 of file fancy_getopt.py.

00375 
00376 def wrap_text(text, width):
00377     """wrap_text(text : string, width : int) -> [string]
00378 
00379     Split 'text' into multiple lines of no more than 'width' characters
00380     each, and return the list of strings that results.
00381     """
00382     if text is None:
00383         return []
00384     if len(text) <= width:
00385         return [text]
00386 
00387     text = text.expandtabs()
00388     text = text.translate(WS_TRANS)
00389     chunks = re.split(r'( +|-+)', text)
00390     chunks = [ch for ch in chunks if ch] # ' - ' results in empty strings
00391     lines = []
00392 
00393     while chunks:
00394         cur_line = []                   # list of chunks (to-be-joined)
00395         cur_len = 0                     # length of current line
00396 
00397         while chunks:
00398             l = len(chunks[0])
00399             if cur_len + l <= width:    # can squeeze (at least) this chunk in
00400                 cur_line.append(chunks[0])
00401                 del chunks[0]
00402                 cur_len = cur_len + l
00403             else:                       # this line is full
00404                 # drop last chunk if all space
00405                 if cur_line and cur_line[-1][0] == ' ':
00406                     del cur_line[-1]
00407                 break
00408 
00409         if chunks:                      # any chunks left to process?
00410             # if the current line is still empty, then we had a single
00411             # chunk that's too big too fit on a line -- so we break
00412             # down and break it up at the line width
00413             if cur_len == 0:
00414                 cur_line.append(chunks[0][0:width])
00415                 chunks[0] = chunks[0][width:]
00416 
00417             # all-whitespace chunks at the end of a line can be discarded
00418             # (and we know from the re.split above that if a chunk has
00419             # *any* whitespace, it is *all* whitespace)
00420             if chunks[0][0] == ' ':
00421                 del chunks[0]
00422 
00423         # and store this line in the list-of-all-lines -- as a single
00424         # string, of course!
00425         lines.append(''.join(cur_line))
00426 
00427     return lines
00428 

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

string distutils.fancy_getopt.longopt_pat = r'[a-zA-Z](?:[a-zA-Z0-9-]*)'

Definition at line 19 of file fancy_getopt.py.

Definition at line 20 of file fancy_getopt.py.

tuple distutils.fancy_getopt.longopt_xlate = str.maketrans('-', '_')

Definition at line 27 of file fancy_getopt.py.

tuple distutils.fancy_getopt.neg_alias_re = re.compile("^(%s)=!(%s)$" % (longopt_pat, longopt_pat))

Definition at line 23 of file fancy_getopt.py.

Initial value:
00001 """\
00002 Tra-la-la, supercalifragilisticexpialidocious.
00003 How *do* you spell that odd word, anyways?
00004 (Someone ask Mary -- she'll know [or she'll
00005 say, "How should I know?"].)"""

Definition at line 448 of file fancy_getopt.py.

dictionary distutils.fancy_getopt.WS_TRANS = {ord(_wschar) : ' ' for _wschar in string.whitespace}

Definition at line 373 of file fancy_getopt.py.