Ñò
$8Zc           @   sS  d  Z  d Z d d k Z d d k Z d d k Z d d k Td d k Z d 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 x> 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$iÿÿÿÿN(   t   *s   [a-zA-Z](?:[a-zA-Z0-9-]*)s   ^%s$s   ^(%s)=!(%s)$t   -t   _t   FancyGetoptc           B   s¤   e  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 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(   t   option_tablet   option_indext   _build_indext   aliast   negative_aliast
   short_optst	   long_optst
   short2longt	   attr_namet	   takes_argt   option_order(   t   selfR   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   __init__.   s    
		
							c         C   s6   |  i  i ƒ  x" |  i D] } | |  i  | d <q Wd  S(   Ni    (   R   t   clearR   (   R   t   option(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyR   Z   s    
 c         C   s   | |  _  |  i ƒ  d  S(   N(   R   R   (   R   R   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   set_option_table_   s    	c         C   sQ   | |  i  j o t d | ‚ n- | | | f } |  i i | ƒ | |  i  | <d  S(   Ns'   option conflict: already an option '%s'(   R   t   DistutilsGetoptErrorR   t   append(   R   t   long_optiont   short_optiont   help_stringR   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt
   add_optionc   s    c         C   s   | |  i  j S(   sc   Return true if the option table for this parser has an
        option with long name 'long_option'.(   R   (   R   R   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt
   has_optionm   s    c         C   s   t  i | t ƒ S(   s’   Translate long option name 'long_option' to the form it
        has as an attribute of some object: ie., translate hyphens
        to underscores.(   t   stringt	   translatet   longopt_xlate(   R   R   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   get_attr_namer   s    c         C   s   t  | ƒ t j p t ‚ xn | i ƒ  D]` \ } } | |  i j o t d | | | f ‚ n | |  i j o t d | | | f ‚ q' q' Wd  S(   Ns(   invalid %s '%s': option '%s' not defineds0   invalid %s '%s': aliased option '%s' not defined(   t   typet   DictionaryTypet   AssertionErrort   itemsR   R   (   R   t   aliasest   whatR   t   opt(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   _check_alias_dicty   s     c         C   s   |  i  | d ƒ | |  _ d S(   s'   Set the aliases for this option parser.R   N(   R&   R   (   R   R   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   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(   R&   R   (   R   R   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   set_negative_aliasesŠ   s    c         C   s¬  g  |  _  g  |  _ |  i i ƒ  h  |  _ x}|  i D]r} t | ƒ d j o | \ } } } d } n: t | ƒ d j o | \ } } } } n t d | f ‚ t | ƒ t	 j	 p t | ƒ d j  o t
 d | ‚ n | d j p# t | ƒ t	 j o t | ƒ d j p t
 d | ‚ n | |  i | <|  i  i | ƒ | d	 d
 j o3 | o | d } n | d d	 !} d |  i | <np |  i i | ƒ } | d j	 oC |  i | o t
 d | | f ‚ n | |  i  d	 <d |  i | <n d |  i | <|  i i | ƒ } | d j	 o6 |  i | |  i | j o t
 d | | f ‚ q=n t i | ƒ p 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   s   invalid option tuple: %ri   s9   invalid long option '%s': must be a string of length >= 2i   s:   invalid short option '%s': must a single character or Noneiÿÿÿÿt   =t   :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(   R
   R	   R   R   t   repeatR   t   lent
   ValueErrorR   t
   StringTypeR   t   NoneR   R   R   t   getR   t
   longopt_ret   matchR   R   (   R   R   t   longt   shortt   helpR+   t   alias_to(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   _grok_option_table“   sf    			
 
&& c         C   s-  | d j o t i d } n | d j o t ƒ  } d } n d } |  i ƒ  t i |  i ƒ } y" t i | | |  i	 ƒ \ } } Wn! t i
 j
 o } t | ‚ n Xxj| D]b\ } } t | ƒ d j o& | d d j o |  i | d } n6 t | ƒ d j o | d  d j p t ‚ | d } |  i i | ƒ }	 |	 o
 |	 } n |  i | pJ | d j p
 t d ‚ |  i i | ƒ }	 |	 o |	 } d } q¢d } n |  i | }
 | o3 |  i i |
 ƒ d j	 o t | |
 d ƒ d } n t | |
 | ƒ |  i i | | f ƒ q­ W| o | | f S| 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   R   s   --t    s   boolean option can't have valueN(   R/   t   syst   argvt   OptionDummyR7   R   t   joinR	   t   getoptR
   t   errort   DistutilsArgErrorR,   R   R!   R   R0   R   R   R   R+   t   getattrt   setattrR   R   (   R   t   argst   objectt   created_objectR	   t   optst   msgR%   t   valR   t   attr(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyR=   ë   sH    	

" $+



 c         C   s(   |  i  d 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(   R   R/   t   RuntimeError(   R   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   get_option_order+  s    c         C   sñ  d } x‚ |  i  D]w } | d } | d } t | ƒ } | d d j o | d } n | d 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 | d 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| 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ÿÿÿÿR)   i   i   iN   t    s   Option summary:i   s     --%-*s  %ss
     --%-*s  s   %s (-%s)s     --%-*sN(   R   R,   R/   t	   wrap_textR   (   R   t   headert   max_optR   R3   R4   t   lt	   opt_widtht
   line_widtht
   text_widtht
   big_indentt   linesR5   t   textt	   opt_names(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   generate_help6  sL    
 



	
 "	 c         C   sI   | d  j o t i } n x( |  i | ƒ D] } | i | d ƒ q* Wd  S(   Ns   
(   R/   R9   t   stdoutRW   t   write(   R   RM   t   filet   line(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt
   print_helpŠ  s
     N(   t   __name__t
   __module__t   __doc__R/   R   R   R   R   R   R   R&   R'   R(   R7   R=   RJ   RW   R\   (    (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyR   "   s   
,		
							X@	Tc         C   s)   t  |  ƒ } | i | ƒ | i | | ƒ S(   N(   R   R(   R=   (   t   optionst   negative_optRC   RB   t   parser(    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   fancy_getopt“  s    RK   c         C   s‘  |  d j o g  St |  ƒ | j o |  g St i |  ƒ }  t i |  t ƒ }  t i d |  ƒ } t d | ƒ } 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 =qon | i	 t i
 | d ƒ ƒ qx W| 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ÿÿÿÿRK   R8   N(   R/   R,   R   t
   expandtabsR   t   WS_TRANSt   ret   splitt   filterR   R<   (   RU   t   widtht   chunksRT   t   cur_linet   cur_lenRO   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyRL   ›  s>      c         C   s   t  i |  t ƒ S(   sX   Convert a long option name to a valid Python identifier by
    changing "-" to "_".
    (   R   R   R   (   R%   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   translate_longoptØ  s    R;   c           B   s   e  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  |  | d ƒ q Wd S(   sk   Create a new OptionDummy instance.  The attributes listed in
        'options' will be initialized to None.N(   RA   R/   (   R   R`   R%   (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyR   ã  s     (   R]   R^   R_   R   (    (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyR;   ß  s   t   __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   
(   R_   t   __revision__R9   R   Rf   t   typesR=   t   distutils.errorst   longopt_patt   compileR1   t   neg_alias_ret	   maketransR   R   Rc   t
   whitespaceR,   Re   RL   Rm   R;   R]   RU   t   wR<   (    (    (    s,   /usr/lib/python2.6/distutils/fancy_getopt.pyt   <module>	   s.   $

ÿ r	"	=	 	