;ň
ü?c           @   sA  d  Z  d Z d k Z d k Z d k Z d k Td k Z d k Td Z e i	 d e  Z
 e i	 d e e f  Z e i d d  Z d	 f  d
     YZ d   Z e i e i d e e i   Z d   Z d   Z d f  d     YZ e d j oK d Z xB d d d d f D]* Z d e GHe i e e e  d  GHHqWn d S(   s6  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
s?   $Id: fancy_getopt.py,v 1.27 2002/11/19 13:12:27 akuchling Exp $N(   s   *s   [a-zA-Z](?:[a-zA-Z0-9-]*)s   ^%s$s   ^(%s)=!(%s)$s   -s   _s   FancyGetoptc           B   s¤   t  Z d  Z e d  Z d   Z d   Z e e d  Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z e e d  Z d   Z e d  Z e e d  Z RS(   sŐ  Wrapper around the standard 'getopt()' module that provides some
    handy extra functionality:
      * short and long options are tied together
      * options have help strings, and help text can be assembled
        from them
      * options set attributes of a passed-in object
      * boolean options can have "negative aliases" -- eg. if
        --quiet is the "negative alias" of --verbose, then "--quiet"
        on the command line sets 'verbose' to false
    c         C   sv   | |  _  h  |  _ |  i  o |  i   n h  |  _ h  |  _ g  |  _ g  |  _ h  |  _ h  |  _	 h  |  _
 g  |  _ d  S(   N(   s   option_tables   selfs   option_indexs   _build_indexs   aliass   negative_aliass
   short_optss	   long_optss
   short2longs	   attr_names	   takes_args   option_order(   s   selfs   option_table(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   __init__.   s    			
							c         C   s6   |  i i   x" |  i D] } | |  i | d <q Wd  S(   Ni    (   s   selfs   option_indexs   clears   option_tables   option(   s   selfs   option(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   _build_indexY   s    
 c         C   s   | |  _  |  i   d  S(   N(   s   option_tables   selfs   _build_index(   s   selfs   option_table(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   set_option_table^   s    	c         C   sT   |  i i |  o t d |  n- | | | f } |  i i	 |  | |  i | <d  S(   Ns'   option conflict: already an option '%s'(
   s   selfs   option_indexs   has_keys   long_options   DistutilsGetoptErrors   short_options   help_strings   options   option_tables   append(   s   selfs   long_options   short_options   help_strings   option(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys
   add_optionb   s
    c         C   s   |  i i |  Sd S(   sc   Return true if the option table for this parser has an
        option with long name 'long_option'.N(   s   selfs   option_indexs   has_keys   long_option(   s   selfs   long_option(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys
   has_optionl   s     c         C   s   t  i | t  Sd S(   s   Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores.N(   s   strings	   translates   long_options   longopt_xlate(   s   selfs   long_option(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   get_attr_nameq   s     c         C   s}   xv | i   D]h \ } } |  i i |  o t d | | | f  n |  i i |  o t d | | | f  q q Wd  S(   Ns(   invalid %s '%s': option '%s' not defineds0   invalid %s '%s': aliased option '%s' not defined(	   s   aliasess   itemss   aliass   opts   selfs   option_indexs   has_keys   DistutilsGetoptErrors   what(   s   selfs   aliasess   whats   opts   alias(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   _check_alias_dictx   s      c         C   s   |  i | d  | |  _ d S(   s'   Set the aliases for this option parser.s   aliasN(   s   selfs   _check_alias_dicts   alias(   s   selfs   alias(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   set_aliases   s     c         C   s   |  i | d  | |  _ d S(   sÚ   Set the negative aliases for this option parser.
        'negative_alias' should be a dictionary mapping option names to
        option names, both the key and value must already be defined
        in the option table.s   negative aliasN(   s   selfs   _check_alias_dicts   negative_alias(   s   selfs   negative_alias(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   set_negative_aliases   s     c         C   s  g  |  _ g  |  _ |  i i   h  |  _ xo|  i D]d} t |  d j o | \ } } } d } n* t |  d j o | \ } } } } n t |  t j	 p t |  d j  o t d |  n | t j p# t |  t j o t |  d j o t d |  n | |  i | <|  i i |  | d d	 j o3 | o | d
 } n | d d !} d |  i | <np |  i i |  } | t j	 oC |  i | o t d | | f  n | |  i d <d |  i | <n d |  i | <|  i i |  } | t j	 o6 |  i | |  i | j o t d | | f  q.n t i |  o t d d |  n |  i |  |  i | <| o% |  i i |  | |  i | d <q2 q2 Wd S(   s   Populate the various data structures that keep tabs on the
        option table.  Called by 'getopt()' before it can do anything
        worthwhile.
        i   i    i   i   s9   invalid long option '%s': must be a string of length >= 2i   s:   invalid short option '%s': must a single character or Nonei˙˙˙˙s   =s   :s>   invalid negative alias '%s': aliased option '%s' takes a valuesg   invalid alias '%s': inconsistent with aliased option '%s' (one of them takes a value, the other doesn'ts   invalid long option name '%s' s'   (must be letters, numbers, hyphens onlyN(   s   selfs	   long_optss
   short_optss
   short2longs   clears   repeats   option_tables   options   lens   longs   shorts   helps   types
   StringTypes   DistutilsGetoptErrors   Nones   appends	   takes_args   negative_aliass   gets   alias_tos   aliass
   longopt_res   matchs   get_attr_names	   attr_name(   s   selfs   shorts   helps   longs   alias_tos   repeats   option(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   _grok_option_table   sR     			
 
 &4 
c         C   sď  | t j o t i d } n | t j o t   } d } n d } |  i   t	 i
 |  i  } y" t i | | |  i  \ }	 } Wn! t i j
 o } t |  n Xx)|	 D]!\ } } t |  d j o | d d j o |  i | d } n | d } |  i i |  } | o
 | } n |  i | o3 |  i i |  } | o | } d } qad } n |  i | }
 | o |  i i |
  t j	 o t | |
 d  d } n t | |
 |  |  i i  | | f  q­ W| o | | f Sn | Sd S(   s  Parse command-line options in args. Store as attributes on object.

        If 'args' is None or not supplied, uses 'sys.argv[1:]'.  If
        'object' is None or not supplied, creates a new OptionDummy
        object, stores option values there, and returns a tuple (args,
        object).  If 'object' is supplied, it is modified in place and
        'getopt()' just returns 'args'; in both cases, the returned
        'args' is a modified copy of the passed-in 'args' list, which
        is left untouched.
        i   i    i   s   -N(!   s   argss   Nones   syss   argvs   objects   OptionDummys   created_objects   selfs   _grok_option_tables   strings   joins
   short_optss   getopts	   long_optss   optss   errors   msgs   DistutilsArgErrors   opts   vals   lens
   short2longs   aliass   gets	   takes_args   negative_aliass	   attr_names   attrs   repeats   getattrs   setattrs   option_orders   append(   s   selfs   argss   objects   opts   aliass   msgs   vals   created_objects
   short_optss   optss   attr(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   getoptę   sJ    
 	

" $ 

 

 c         C   s(   |  i t j o t d  n |  i Sd S(   sŤ   Returns the list of (option, value) tuples processed by the
        previous run of 'getopt()'.  Raises RuntimeError if
        'getopt()' hasn't been called yet.
        s!   'getopt()' hasn't been called yetN(   s   selfs   option_orders   Nones   RuntimeError(   s   self(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   get_option_order*  s     c         C   ső  d } x |  i D]w } | d }
 | d } t |
  }	 |
 d d j o |	 d }	 n | t j	 o |	 d }	 n |	 | j o
 |	 } q q W| d d d } d } | | } d | } | o | g } n
 d	 g } x|  i D]} | d
  \ }
 } } t | |  } |
 d d j o |
 d d !}
 n | t j oD | o" | i d | |
 | d f  qĂ| i d | |
 f  nK d |
 | f } | o" | i d | | | d f  n | i d |  x# | d D] }	 | i | |	  qÎWqŢ W| Sd S(   s   Generate help text (a list of strings, one per suggested line of
        output) from the option table for this FancyGetopt object.
        i    i   i˙˙˙˙s   =i   i   iN   s    s   Option summary:i   s     --%-*s  %ss
     --%-*s  s   %s (-%s)s     --%-*sN(   s   max_opts   selfs   option_tables   options   longs   shorts   lens   ls   Nones	   opt_widths
   line_widths
   text_widths
   big_indents   headers   liness   helps	   wrap_texts   texts   appends	   opt_names(   s   selfs   headers
   line_widths   shorts   options	   opt_namess
   big_indents   texts   liness   ls   longs   max_opts	   opt_widths
   text_widths   help(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   generate_help5  sL     
 



	
 "" c         C   sI   | t j o t i } n x( |  i |  D] } | i | d  q* Wd  S(   Ns   
(	   s   files   Nones   syss   stdouts   selfs   generate_helps   headers   lines   write(   s   selfs   headers   files   line(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys
   print_help  s
     (   s   __name__s
   __module__s   __doc__s   Nones   __init__s   _build_indexs   set_option_tables
   add_options
   has_options   get_attr_names   _check_alias_dicts   set_aliasess   set_negative_aliasess   _grok_option_tables   getopts   get_option_orders   generate_helps
   print_help(    (    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   FancyGetopt"   s   
 +		
							X@	Tc         C   s-   t  |   } | i |  | i | |  Sd  S(   N(   s   FancyGetopts   optionss   parsers   set_negative_aliasess   negative_opts   getopts   argss   object(   s   optionss   negative_opts   objects   argss   parser(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   fancy_getopt  s    s    c         C   s  |  t j o g  Sn t |   | j o |  g Sn t i |   }  t i |  t  }  t i	 d |   } t t |  } g  } x| og  } d } x{ | os t | d  } | | | j o& | i | d  | d =| | } q | o | d d d j o | d =n Pq W| o_ | d j o. | i | d d | ! | d | | d <n | d d d j o | d =qun | i t i | d   q~ W| Sd S(   sś   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.
    s   ( +|-+)i    i˙˙˙˙s    s    N(   s   texts   Nones   lens   widths   strings
   expandtabss	   translates   WS_TRANSs   res   splits   chunkss   filters   liness   cur_lines   cur_lens   ls   appends   join(   s   texts   widths   liness   ls   cur_lines   chunkss   cur_len(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys	   wrap_text  s@       c         C   s   t  i |  t  Sd S(   sX   Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    N(   s   strings	   translates   opts   longopt_xlate(   s   opt(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   translate_longopt×  s     s   OptionDummyc           B   s   t  Z d  Z g  d  Z RS(   s_   Dummy class just used as a place to hold command-line option
    values as instance attributes.c         C   s%   x | D] } t |  | t  q Wd S(   sk   Create a new OptionDummy instance.  The attributes listed in
        'options' will be initialized to None.N(   s   optionss   opts   setattrs   selfs   None(   s   selfs   optionss   opt(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   __init__â  s      (   s   __name__s
   __module__s   __doc__s   __init__(    (    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   OptionDummyŢ  s    s   __main__s˘   Tra-la-la, supercalifragilisticexpialidocious.
How *do* you spell that odd word, anyways?
(Someone ask Mary -- she'll know [or she'll
say, "How should I know?"].)i
   i   i   i(   s	   width: %ds   
(   s   __doc__s   __revision__s   syss   strings   res   typess   getopts   distutils.errorss   longopt_pats   compiles
   longopt_res   neg_alias_res	   maketranss   longopt_xlates   FancyGetopts   fancy_getopts
   whitespaces   lens   WS_TRANSs	   wrap_texts   translate_longopts   OptionDummys   __name__s   texts   ws   join(   s   WS_TRANSs   __revision__s   strings   OptionDummys
   longopt_res   texts   translate_longopts   syss   res   FancyGetopts   longopt_pats   neg_alias_res   ws   longopt_xlates   getopts	   wrap_texts   fancy_getopt(    (    s3   /mit/python/lib/python2.3/distutils/fancy_getopt.pys   ?	   s.   	˙ q	"	=	 	