ó
È”Mc           @   sæ   d  d l  m Z d  d l m Z m Z d  d l Z d  d l Z d  d l Z d d d g Z y( e d ƒ e j	 _
 e d ƒ e j _
 Wn e k
 r e e _ n Xe j Z d	 e j f d
 „  ƒ  YZ d e j f d „  ƒ  YZ d „  Z d S(   iÿÿÿÿ(   t   optparse(   t   Errort   _Nt   OptionParsert   OptionValueErrort
   append_alls   show this help message and exits&   show program's version number and exitt   HelpFormatterc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s    t  j j |  d d d d ƒ d  S(   Ni   i   iO   i   (   R    R   t   __init__(   t   self(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR   -   s    c         C   s   t  d ƒ | S(   Ns
   Usage: %s
(   R   (   R   t   usage(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyt   format_usage0   s    c         C   s0   t  | ƒ } d |  j d | j ƒ  f St  d ƒ (   Ns   
%*s%s:
t    t   options(   R   t   current_indentt
   capitalize(   R   t   heading(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyt   format_heading3   s    c         C   s
   | j  ƒ  S(   N(   t   strip(   R   t   description(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyt   format_description8   s    c         C   sC   | j  } | r! | j ƒ  | _  n  t j j |  | ƒ } | | _  | S(   N(   t   helpR   R    R   t   format_option(   R   t   optionR   t   result(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR   ;   s    		(   t   __name__t
   __module__R   R
   R   R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR   +   s
   				c           B   sD   e  Z d d d e d  „ Z d d „ Z d „  Z d „  Z d „  Z RS(   c         K   sQ   d | k r t  ƒ  | d <n  t j j |  | |  | |  _ | |  _ | |  _ d  S(   Nt	   formatter(   R   R    R   R   t   _override_helpt	   _examplest   _skipunknown(   R   R	   R   t   examplest   skipunknownt   kwargs(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR   E   s    		c         C   sî   | d  k r |  j } n  |  j r= |  j j ƒ  } | d 7} n£ t j j |  | ƒ } | j ƒ  } | d 7} |  j rà | | j t	 d ƒ ƒ 7} | j
 ƒ  x< |  j j ƒ  j ƒ  D]% } | d | j 7} | | d 7} qª W| j ƒ  n  | d 7} | S(   Ns   
R   t    (   t   NoneR   R   R   R    R   t   format_helpR   R   R   t   indentt
   splitlinesR   t   dedent(   R   R   R   t   line(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR#   N   s"    	
	

c         C   s   t  | ‚ d  S(   N(   R   (   R   t   msg(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyt   errorb   s    c         C   s;  x4| r6| d } | d k r* | d =d S| d d !d k r£ y |  j  | | ƒ Wq3t j k
 rŸ |  j ss ‚  n  | j | ƒ d | k r  | j d ƒ q  q3Xq | d  d k rt | ƒ d k ry |  j | | ƒ Wq3t j k
 r|  j sû ‚  n  | j | ƒ q3Xq |  j r/| j | ƒ | d =q d Sq Wd S(   s˜  _process_args(largs : [string],
                         rargs : [string],
                         values : Values)

        Process command-line arguments and populate 'values', consuming
        options and arguments from 'rargs'.  If 'allow_interspersed_args' is
        false, stop at the first non-option argument.  If true, accumulate any
        interspersed non-option arguments in 'largs'.
        i    s   --Ni   t   =i   t   -(	   t   _process_long_optR    t   BadOptionErrorR   t   appendt   popt   lent   _process_short_optst   allow_interspersed_args(   R   t   largst   rargst   valuest   arg(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyt   _process_argse   s2    
	
	"		
c         C   sy  | j  d ƒ } t } d } xW| d D]K} d | } |  j j | ƒ } | d 7} | sq t j t d ƒ | ‚ n  | j ƒ  rK| t | ƒ k  r¬ | j	 d | | ƒ t
 } n  | j }	 t | ƒ |	 k  r|	 d k rí |  j t d ƒ | ƒ qH|  j t d ƒ | |	 f ƒ qQ|	 d k r+| j  d ƒ }
 qQt | d |	 !ƒ }
 | d |	 5n d  }
 | j | |
 | |  ƒ | r& Pq& q& Wd  S(   Ni    i   R+   s   no such option: %ss   %s option requires an arguments   %s option requires %d arguments(   R/   t   Falset
   _short_optt   getR    R-   R   t   takes_valueR0   t   insertt   Truet   nargsR)   t   tupleR"   t   process(   R   R4   R5   R6   t   stopt   it   cht   optR   R>   t   value(    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR1   ”   s6    

		N(	   R   R   R"   R8   R   R#   R)   R7   R1   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR   C   s
   			/c         C   së   |  j  d  k rE | |  _  x* |  j  d d k rA |  j  d |  _  q Wn  |  j  j d d ƒ } t | j | ƒ } t | ƒ t k	 rš g  } t | j | | ƒ n  | j } xA | ræ | d ræ | d d d k ræ | j	 | j j
 d ƒ ƒ q¦ Wd  S(   Ni    R+   i   R   (   t   destR"   t   replacet   getattrR5   t   typet   listt   setattrR4   R.   R/   (   R   RD   RE   t   parserRF   t   lstR4   (    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyR   ¾   s    		'(   t
   smart.utilR    t   smartR   R   t   textwrapt   syst   ost   __all__t   STD_HELP_OPTIONR   t   STD_VERSION_OPTIONt   AttributeErrorR   R   R   R   (    (    (    s0   /usr/lib/python2.7/dist-packages/smart/option.pyt   <module>   s   	{