;
Ñâ"Ic               @   s8  d  Z  d Z d d l Z d d l Z d d l Z d d l Z d d l Td Z e j d e ƒ Z	 e j d e e f ƒ Z
 d „  Z Gd	 „  d
 ƒ Z d „  Z d „  e j Dƒ Z d „  Z d „  Z Gd „  d ƒ Z e d k oX d Z xK d d d d f D]7 Z e d e ƒ e d j e e e ƒ ƒ ƒ e ƒ  qõ Wn d S(   u6  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
uB   $Id: fancy_getopt.py 58495 2007-10-16 18:12:55Z guido.van.rossum $i    N(   u   *u   [a-zA-Z](?:[a-zA-Z0-9-]*)u   ^%s$u   ^(%s)=!(%s)$c             C   s   |  j  d  d ƒ S(   u   -u   _(   u   replace(   u   s(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   <lambda>   s    c             B   sª   |  Ee  Z d  Z d d „ Z d „  Z d „  Z d d d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d d d „ Z d „  Z d d „ Z d d d „ Z d S(   uÕ  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   | |  _  i  |  _ |  j  o |  j ƒ  n i  |  _ i  |  _ g  |  _ g  |  _ i  |  _ i  |  _ i  |  _	 g  |  _
 d  S(   N(   u   option_tableu   option_indexu   _build_indexu   aliasu   negative_aliasu
   short_optsu	   long_optsu
   short2longu	   attr_nameu	   takes_argu   option_order(   u   selfu   option_table(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   __init__+   s    			
							c             C   s6   |  j  j ƒ  x" |  j D] } | |  j  | d <q Wd  S(   Ni    (   u   option_indexu   clearu   option_table(   u   selfu   option(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   _build_indexS   s    
 c             C   s   | |  _  |  j ƒ  d  S(   N(   u   option_tableu   _build_index(   u   selfu   option_table(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   set_option_tableX   s    	c             C   sT   | |  j  k o t d | ƒ ‚ n- | | | f } |  j j | ƒ | |  j  | <d  S(   Nu'   option conflict: already an option '%s'(   u   option_indexu   DistutilsGetoptErroru   option_tableu   append(   u   selfu   long_optionu   short_optionu   help_stringu   option(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu
   add_option\   s    c             C   s   | |  j  k S(   uc   Return true if the option table for this parser has an
        option with long name 'long_option'.(   u   option_index(   u   selfu   long_option(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu
   has_optione   s    c             C   s
   t  | ƒ S(   u’   Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores.(   u   longopt_xlate(   u   selfu   long_option(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   get_attr_namej   s    c             C   s{   xt | j  ƒ  D]f \ } } | |  j k o t d | | | f ƒ ‚ n | |  j k o t d | | | f ƒ ‚ q q Wd  S(   Nu(   invalid %s '%s': option '%s' not definedu0   invalid %s '%s': aliased option '%s' not defined(   u   itemsu   option_indexu   DistutilsGetoptError(   u   selfu   aliasesu   whatu   aliasu   opt(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   _check_alias_dictp   s     c             C   s   |  j  | d ƒ | |  _ d S(   u'   Set the aliases for this option parser.u   aliasN(   u   _check_alias_dictu   alias(   u   selfu   alias(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   set_aliasesz   s    c             C   s   |  j  | d ƒ | |  _ d S(   uÚ   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.u   negative aliasN(   u   _check_alias_dictu   negative_alias(   u   selfu   negative_alias(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   set_negative_aliases   s    c             C   s«  g  |  _  g  |  _ |  j j ƒ  i  |  _ x||  j D]q} t | ƒ d k o | \ } } } d } n= t | ƒ d k o | \ } } } } n t d | f ƒ ‚ t | t	 ƒ p t | ƒ d k  o t
 d | ƒ ‚ n | d k p  t | t	 ƒ o t | ƒ d k p t
 d | ƒ ‚ n | |  j | <|  j  j | ƒ | d	 d
 k o6 | o | d } n | d d	 … } d |  j | <nf |  j j | ƒ } | d k	 o9 |  j | o t
 d | | f ƒ ‚ n | |  j  d	 <n d |  j | <|  j j | ƒ } | d k	 o9 |  j | |  j | k o t
 d | | f ƒ ‚ q=n t j | ƒ p t
 d | ƒ ‚ n |  j | ƒ |  j | <| o% |  j j | ƒ | |  j | d <q2 q2 Wd S(   u   Populate the various data structures that keep tabs on the
        option table.  Called by 'getopt()' before it can do anything
        worthwhile.
        i   i    i   u   invalid option tuple: %ri   u9   invalid long option '%s': must be a string of length >= 2i   u:   invalid short option '%s': must a single character or Noneiÿÿÿÿu   =u   :u>   invalid negative alias '%s': aliased option '%s' takes a valueug   invalid alias '%s': inconsistent with aliased option '%s' (one of them takes a value, the other doesn'tuE   invalid long option name '%s' (must be letters, numbers, hyphens onlyN(   u	   long_optsu
   short_optsu
   short2longu   clearu   repeatu   option_tableu   lenu
   ValueErroru
   isinstanceu   stru   DistutilsGetoptErroru   Noneu   appendu	   takes_argu   negative_aliasu   getu   aliasu
   longopt_reu   matchu   get_attr_nameu	   attr_name(   u   selfu   optionu   longu   shortu   helpu   repeatu   alias_to(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   _grok_option_table‡   s`    			
 
$# c             C   s  | d k o t j d d … } n | d k o t ƒ  } d } n d } |  j ƒ  d j |  j ƒ } y" t	 j	 | | |  j
 ƒ \ } } Wn6 t	 j k
 o' } z t | ƒ ‚ WYd d } ~ Xn Xx.| D]&\ } } t | ƒ d k o& | d d k o |  j | d } n | d d … } |  j j | ƒ }	 |	 o
 |	 } n |  j | p3 |  j j | ƒ }	 |	 o |	 } d } qd } n |  j | }
 | o3 |  j j |
 ƒ d k	 o t | |
 d ƒ d } n t | |
 | ƒ |  j j | | f ƒ qÈ W| o | | f S| Sd S(	   u  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   Nu    i   i    u   -TF(   u   Noneu   sysu   argvu   OptionDummyu   Trueu   Falseu   _grok_option_tableu   joinu
   short_optsu   getoptu	   long_optsu   erroru   DistutilsArgErroru   lenu
   short2longu   aliasu   getu	   takes_argu   negative_aliasu	   attr_nameu   repeatu   getattru   setattru   option_orderu   append(   u   selfu   argsu   objectu   created_objectu
   short_optsu   optsu   msgu   optu   valu   aliasu   attr(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   getoptÔ   sD    	

"  $


 c             C   s+   |  j  d k o t d ƒ ‚ n |  j  Sd S(   u«   Returns the list of (option, value) tuples processed by the
        previous run of 'getopt()'.  Raises RuntimeError if
        'getopt()' hasn't been called yet.
        u!   'getopt()' hasn't been called yetN(   u   option_orderu   Noneu   RuntimeError(   u   self(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   get_option_order  s    c          	   C   s   d } x‚ |  j  D]w } | d } | d } t | ƒ } | d d k o | d } n | d
 k	 o | d } n | | k o
 | } q q W| d d d } d } | | }	 d | }
 | o | g } n
 d	 g } x%|  j  D]} | d
 d … \ } } } t | |	 ƒ } | d d k o | d d … } n | d
 k oD | o" | j d | | | d f ƒ qÌ| j d | | f ƒ nK d | | f } | o" | j d | | | d f ƒ n | j d | ƒ x) | d d
 … D] } | j |
 | ƒ qÝWqÞ W| S(   uŒ   Generate help text (a list of strings, one per suggested line of
        output) from the option table for this FancyGetopt object.
        i    i   iÿÿÿÿu   =i   i   iN   u    u   Option summary:Ni   u     --%-*s  %su
     --%-*s  u   %s (-%s)u     --%-*s(   u   option_tableu   lenu   Noneu	   wrap_textu   append(   u   selfu   headeru   max_optu   optionu   longu   shortu   lu	   opt_widthu
   line_widthu
   text_widthu
   big_indentu   linesu   helpu   textu	   opt_names(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   generate_help  sL    
 



	
 "	 c             C   sI   | d  k o t j } n x( |  j | ƒ D] } | j | d ƒ q* Wd  S(   Nu   
(   u   Noneu   sysu   stdoutu   generate_helpu   write(   u   selfu   headeru   fileu   line(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu
   print_helpj  s
     N(   u   __name__u
   __module__u   __doc__u   Noneu   __init__u   _build_indexu   set_option_tableu
   add_optionu
   has_optionu   get_attr_nameu   _check_alias_dictu   set_aliasesu   set_negative_aliasesu   _grok_option_tableu   getoptu   get_option_orderu   generate_helpu
   print_help(   u
   __locals__(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   FancyGetopt   s   

(						
			M=	
Ou   FancyGetoptc             C   s)   t  |  ƒ } | j | ƒ | j | | ƒ S(   N(   u   FancyGetoptu   set_negative_aliasesu   getopt(   u   optionsu   negative_optu   objectu   argsu   parser(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   fancy_getoptq  s    c             C   s%   i  } |  ] } | d  t  | ƒ <q
 S(   u    (   u   ord(   u   .0u   _[1]u   _wschar(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu
   <dictcomp>w  s    c             C   s’  |  d k o g  St |  ƒ | k o |  g S|  j ƒ  }  |  j t ƒ }  t j d |  ƒ } d „  | Dƒ } g  } x| og  } d } x{ | os t | d ƒ } | | | k o& | j | d ƒ | d =| | } q‰ | o  | d d d k o | d =n Pq‰ W| oh | d k o7 | j | d d | … ƒ | d | d … | d <n | d d d k o | d =qsn | j d j | ƒ ƒ qs W| S(   u¶   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.
    u   ( +|-+)c             S   s&   g  } |  ] } | o | | q
 q
 S(    (    (   u   .0u   _[1]u   ch(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu
   <listcomp>‡  s    i    iÿÿÿÿu    Nu    (	   u   Noneu   lenu
   expandtabsu	   translateu   WS_TRANSu   reu   splitu   appendu   join(   u   textu   widthu   chunksu   linesu   cur_lineu   cur_lenu   l(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu	   wrap_texty  s>      c             C   s
   t  |  ƒ S(   uX   Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    (   u   longopt_xlate(   u   opt(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   translate_longopt¯  s    c             B   s    |  Ee  Z d  Z g  d „ Z d S(   u_   Dummy class just used as a place to hold command-line option
    values as instance attributes.c             C   s%   x | D] } t  |  | d ƒ q Wd S(   uk   Create a new OptionDummy instance.  The attributes listed in
        'options' will be initialized to None.N(   u   setattru   None(   u   selfu   optionsu   opt(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   __init__º  s     N(   u   __name__u
   __module__u   __doc__u   __init__(   u
   __locals__(    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   OptionDummy¶  s   
u   OptionDummyu   __main__u¢   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(   u	   width: %du   
(   u   __doc__u   __revision__u   sysu   stringu   reu   getoptu   distutils.errorsu   longopt_patu   compileu
   longopt_reu   neg_alias_reu   longopt_xlateu   FancyGetoptu   fancy_getoptu
   whitespaceu   WS_TRANSu	   wrap_textu   translate_longoptu   OptionDummyu   __name__u   textu   wu   printu   join(    (    (    u3   /mit/python/lib/python3.0/distutils/fancy_getopt.pyu   <module>	   s,   $
	ÿ S		6	 