ó
á™xTc           @   sr  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l m Z m Z m	 Z	 d d l
 m Z d d l m Z m Z m Z m Z m Z d d d	 d
 d d g Z d d Z d d Z y e e f Wn# e k
 rí d d f \ Z Z n Xd „  Z d	 f  d „  ƒ  YZ d
 f  d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d f  d „  ƒ  YZ  d S(   sC   optik.option_parser

Provides the OptionParser and Values classes.
iÿÿÿÿ(   t   divisionN(   t   Optiont
   NO_DEFAULTt   _repr(   t   IndentedHelpFormatter(   t   gettextt   OptionConflictErrort   BadOptionErrort   OptionValueErrort   AmbiguousOptionErrort   SUPPRESS_HELPt   SUPPRESS_USAGEt   Valuest   OptionContainert   OptionGroupt   OptionParsert   SUPPRESSt   HELPt   USAGEi   i    c         C   s"   t  |  t j ƒ p! t  |  t j ƒ S(   N(   t
   isinstancet   typest
   StringTypet   UnicodeType(   t   x(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   isbasestring   s    c           B   sh   e  Z d
 d  „ Z d „  Z e Z d „  Z d „  Z d „  Z	 d „  Z
 d d „ Z d d „ Z d	 „  Z RS(   c         C   s:   | r6 x- | j  ƒ  D] \ } } t |  | | ƒ q Wn  d  S(   N(   t   itemst   setattr(   t   selft   defaultst   attrt   val(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   __init__$   s    c         C   s   t  |  j ƒ S(   N(   t   strt   __dict__(   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   __str__)   s    c         C   sL   t  | t ƒ r" t |  j | j ƒ St  | t j ƒ rD t |  j | ƒ Sd Sd  S(   Niÿÿÿÿ(   R   R   t   cmpR!   R   t   DictType(   R   t   other(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   __cmp__.   s
    c         C   sV   xO t  |  ƒ D]A } | j | ƒ r | | } | d k	 rN t |  | | ƒ qN q q Wd S(   sû   
        Update the option values from an arbitrary dictionary, but only
        use keys from dict that already have a corresponding attribute
        in self.  Any keys in dict without a corresponding attribute
        are silently ignored.
        N(   t   dirt   has_keyt   NoneR   (   R   t   dictR   t   dval(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _update_careful6   s
    
c         C   s   |  j  j | ƒ d S(   sÅ   
        Update the option values from an arbitrary dictionary,
        using all keys from the dictionary regardless of whether
        they have a corresponding attribute in self or not.
        N(   R!   t   update(   R   R*   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _update_looseC   s    c         C   sI   | d k r |  j  | ƒ n) | d k r8 |  j | ƒ n t d | ‚ d  S(   Nt   carefult   looses   invalid update mode: %r(   R,   R.   t
   ValueError(   R   R*   t   mode(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _updateK   s
    R/   c         C   s1   t  | ƒ t j | } |  j t | ƒ | ƒ d  S(   N(   t
   __import__t   syst   modulesR3   t   vars(   R   t   modnameR2   t   mod(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   read_moduleS   s    
c         C   s'   i  } t  | | ƒ |  j | | ƒ d  S(   N(   t   execfileR3   (   R   t   filenameR2   R7   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt	   read_fileX   s    c         C   sE   t  |  | ƒ s% t |  | ƒ d  k r8 t |  | | ƒ n  t |  | ƒ S(   N(   t   hasattrt   getattrR)   R   (   R   R   t   value(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   ensure_value]   s    %N(   t   __name__t
   __module__R)   R   R"   R   t   __repr__R&   R,   R.   R3   R:   R=   RA   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   "   s   					c           B   sž   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s“  
    Abstract base class.

    Class attributes:
      standard_option_list : [Option]
        list of standard options that will be accepted by all instances
        of this parser class (intended to be overridden by subclasses).

    Instance attributes:
      option_list : [Option]
        the list of Option objects contained by this OptionContainer
      _short_opt : { string : Option }
        dictionary mapping short option strings, eg. "-f" or "-X",
        to the Option instances that implement them.  If an Option
        has multiple short option strings, it will appears in this
        dictionary multiple times. [1]
      _long_opt : { string : Option }
        dictionary mapping long option strings, eg. "--file" or
        "--exclude", to the Option instances that implement them.
        Again, a given Option can occur multiple times in this
        dictionary. [1]
      defaults : { string : any }
        dictionary mapping option destination names to default
        values for each destination [1]

    [1] These mappings are common to (shared by) all components of the
        controlling OptionParser, where they are initially created.

    c         C   s1   |  j  ƒ  | |  _ |  j | ƒ |  j | ƒ d  S(   N(   t   _create_option_listt   option_classt   set_conflict_handlert   set_description(   R   RF   t   conflict_handlert   description(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   ƒ   s    
	c         C   s"   i  |  _  t ƒ  |  _ i  |  _ d  S(   N(   t
   _short_optt   _long_opt_dictt	   _long_optR   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _create_option_mappingsŽ   s    	c         C   s(   | j  |  _  | j |  _ | j |  _ d  S(   N(   RK   RM   R   (   R   t   parser(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _share_option_mappings—   s    c         C   s)   | d k r t  d | ‚ n  | |  _ d  S(   Nt   errort   resolves$   invalid conflict_resolution value %r(   s   errorRR   (   R1   RI   (   R   t   handler(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRG   ž   s    c         C   s   | |  _  d  S(   N(   RJ   (   R   RJ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRH   £   s    c         C   s   |  j  S(   N(   RJ   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   get_description¦   s    c         C   s   |  `  |  ` |  ` d S(   s   see OptionParser.destroy().N(   RK   RM   R   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   destroyª   s    c         C   sx  g  } x@ | j  D]5 } |  j j | ƒ r | j | |  j | f ƒ q q Wx@ | j D]5 } |  j j | ƒ rS | j | |  j | f ƒ qS qS W| rt|  j } | d k rÝ t d d j g  | D] } | d ^ qº ƒ | ƒ ‚ qt| d k rtx… | D]z \ } } | j	 d ƒ r(| j j
 | ƒ |  j | =n | j  j
 | ƒ |  j | =| j  pQ| j sð | j j j
 | ƒ qð qð Wqtn  d  S(   NRQ   s    conflicting option string(s): %ss   , i    RR   s   --(   t   _short_optsRK   R(   t   appendt
   _long_optsRM   RI   R   t   joint
   startswitht   removet	   containert   option_list(   R   t   optiont   conflict_optst   optRS   t   cot   c_option(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _check_conflict³   s.    !!	$
c         O   sG  t  | d ƒ t j k r. |  j | | Ž  } nN t | ƒ d k rs | rs | d } t | t ƒ s| t d | ‚ q| n	 t d ‚ |  j | ƒ |  j	 j
 | ƒ |  | _ x | j D] } | |  j | <q¬ Wx | j D] } | |  j | <qÍ W| j d k	 rC| j t k	 r| j |  j | j <qC|  j j | j ƒ sCd |  j | j <qCn  | S(   sO   add_option(Option)
           add_option(opt_str, ..., kwarg=val, ...)
        i    i   s   not an Option instance: %rs   invalid argumentsN(   t   typeR   R   RF   t   lenR   R   t	   TypeErrorRc   R]   RW   R\   RV   RK   RX   RM   t   destR)   t   defaultR   R   R(   (   R   t   argst   kwargsR^   R`   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt
   add_optionÎ   s(    
		c         C   s"   x | D] } |  j  | ƒ q Wd  S(   N(   Rk   (   R   R]   R^   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   add_optionsì   s    c         C   s"   |  j  j | ƒ p! |  j j | ƒ S(   N(   RK   t   getRM   (   R   t   opt_str(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt
   get_optionò   s    c         C   s"   |  j  j | ƒ p! |  j j | ƒ S(   N(   RK   R(   RM   (   R   Rn   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt
   has_optionö   s    c         C   s¥   |  j  j | ƒ } | d  k r3 |  j j | ƒ } n  | d  k rR t d | ƒ ‚ n  x | j D] } |  j  | =q\ Wx | j D] } |  j | =qz W| j j j	 | ƒ d  S(   Ns   no such option %r(
   RK   Rm   R)   RM   R1   RV   RX   R\   R]   R[   (   R   Rn   R^   R`   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   remove_optionú   s    c         C   s\   |  j  s d Sg  } x9 |  j  D]. } | j t k	 r | j | j | ƒ ƒ q q Wd j | ƒ S(   Nt    (   R]   t   helpR
   RW   t   format_optionRY   (   R   t	   formattert   resultR^   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   format_option_help
  s    	c         C   s   | j  |  j ƒ  ƒ S(   N(   t   format_descriptionRT   (   R   Ru   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRx     s    c         C   sW   g  } |  j  r( | j |  j | ƒ ƒ n  |  j rJ | j |  j | ƒ ƒ n  d j | ƒ S(   Ns   
(   RJ   RW   Rx   R]   Rw   RY   (   R   Ru   Rv   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   format_help  s    		(   RB   RC   t   __doc__R   RN   RP   RG   RH   RT   RU   Rc   Rk   Rl   Ro   Rp   Rq   Rw   Rx   Ry   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   c   s"   																		c           B   s8   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s2   | |  _  t j |  | j | j | ƒ | |  _ d  S(   N(   RO   R   R   RF   RI   t   title(   R   RO   R{   RJ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   !  s    	c         C   s   g  |  _  |  j |  j ƒ d  S(   N(   R]   RP   RO   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRE   '  s    	c         C   s   | |  _  d  S(   N(   R{   (   R   R{   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt	   set_title+  s    c         C   s   t  j |  ƒ |  ` d S(   s   see OptionParser.destroy().N(   R   RU   R]   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRU   .  s    c         C   s@   | j  |  j ƒ } | j ƒ  | t j |  | ƒ 7} | j ƒ  | S(   N(   t   format_headingR{   t   indentR   Ry   t   dedent(   R   Ru   Rv   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRy   5  s
    

N(   RB   RC   R)   R   RE   R|   RU   Ry   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR     s
   			c           B   s�  e  Z d  Z g  Z d( d( e d( d d( d( e d( d( d „
 Z d „  Z d „  Z	 d „  Z
 d „  Z e d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d( d( d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d d( d „ Z" d „  Z# d  „  Z$ d( d! „ Z% d" „  Z& d( d# „ Z' d( d$ „ Z( d% „  Z) d( d& „ Z* d( d' „ Z+ RS()   s  
    Class attributes:
      standard_option_list : [Option]
        list of standard options that will be accepted by all instances
        of this parser class (intended to be overridden by subclasses).

    Instance attributes:
      usage : string
        a usage string for your program.  Before it is displayed
        to the user, "%prog" will be expanded to the name of
        your program (self.prog or os.path.basename(sys.argv[0])).
      prog : string
        the name of the current program (to override
        os.path.basename(sys.argv[0])).
      epilog : string
        paragraph of help text to print after option help

      option_groups : [OptionGroup]
        list of option groups in this parser (option groups are
        irrelevant for parsing the command-line, but very useful
        for generating help)

      allow_interspersed_args : bool = true
        if true, positional arguments may be interspersed with options.
        Assuming -a and -b each take a single argument, the command-line
          -ablah foo bar -bboo baz
        will be interpreted the same as
          -ablah -bboo -- foo bar baz
        If this flag were false, that command line would be interpreted as
          -ablah -- foo bar -bboo baz
        -- ie. we stop processing options as soon as we see the first
        non-option argument.  (This is the tradition followed by
        Python's getopt module, Perl's Getopt::Std, and other argument-
        parsing libraries, but it is generally annoying to users.)

      process_default_values : bool = true
        if true, option default values are processed similarly to option
        values from the command line: that is, they are passed to the
        type-checking function for the option's type (as long as the
        default value is a string).  (This really only matters if you
        have defined custom types; see SF bug #955889.)  Set it to false
        to restore the behaviour of Optik 1.4.1 and earlier.

      rargs : [string]
        the argument list currently being parsed.  Only set when
        parse_args() is active, and continually trimmed down as
        we consume arguments.  Mainly there for the benefit of
        callback options.
      largs : [string]
        the list of leftover arguments that we have skipped while
        parsing options.  If allow_interspersed_args is false, this
        list is always empty.
      values : Values
        the set of option values currently being accumulated.  Only
        set when parse_args() is active.  Also mainly for callbacks.

    Because of the 'rargs', 'largs', and 'values' attributes,
    OptionParser is not thread-safe.  If, for some perverse reason, you
    need to parse command-line arguments simultaneously in different
    threads, use different OptionParser instances.

    RQ   c         C   s¢   t  j |  | | | ƒ |  j | ƒ |	 |  _ | |  _ t |  _ t |  _ | d  k r_ t	 ƒ  } n  | |  _
 |  j
 j |  ƒ |
 |  _ |  j | d | ƒ|  j ƒ  d  S(   Nt   add_help(   R   R   t	   set_usaget   progt   versiont   Truet   allow_interspersed_argst   process_default_valuesR)   R   Ru   t
   set_parsert   epilogt   _populate_option_listt   _init_parsing_state(   R   t   usageR]   RF   Rƒ   RI   RJ   Ru   t   add_help_optionR‚   Rˆ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   €  s    						c         C   sA   t  j |  ƒ x |  j D] } | j ƒ  q W|  ` |  ` |  ` d S(   s  
        Declare that you are done with this OptionParser.  This cleans up
        reference cycles so the OptionParser (and all objects referenced by
        it) can be garbage-collected promptly.  After calling destroy(), the
        OptionParser is unusable.
        N(   R   RU   t   option_groupsR]   Ru   (   R   t   group(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRU   ¢  s    c         C   s    g  |  _  g  |  _ |  j ƒ  d  S(   N(   R]   R�   RN   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRE   ´  s    		c         C   s&   |  j  d d d d d t d ƒ ƒd  S(   Ns   -hs   --helpt   actionRs   s   show this help message and exit(   Rk   t   _(   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _add_help_option¹  s    c         C   s#   |  j  d d d d t d ƒ ƒd  S(   Ns	   --versionR�   Rƒ   Rs   s&   show program's version number and exit(   Rk   R�   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _add_version_option¾  s    c         C   s_   |  j  r |  j |  j  ƒ n  | r2 |  j | ƒ n  |  j rH |  j ƒ  n  | r[ |  j ƒ  n  d  S(   N(   t   standard_option_listRl   Rƒ   R’   R‘   (   R   R]   R€   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR‰   Ã  s    		c         C   s   d  |  _ d  |  _ d  |  _ d  S(   N(   R)   t   rargst   largst   values(   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRŠ   Í  s    		c         C   sh   | d  k r t d ƒ |  _ nF | t k r6 d  |  _ n. | j ƒ  j d ƒ r[ | d |  _ n	 | |  _ d  S(   Ns   %prog [options]s   usage: i   (   R)   R�   R‹   R   t   lowerRZ   (   R   R‹   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR�   Ö  s    c         C   s   t  |  _ d  S(   N(   R„   R…   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   enable_interspersed_argsá  s    c         C   s   t  |  _ d  S(   N(   t   FalseR…   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   disable_interspersed_argsä  s    c         C   s   | |  _  d  S(   N(   R†   (   R   t   process(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   set_process_default_valuesç  s    c         C   s   | |  j  | <d  S(   N(   R   (   R   Rg   R@   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   set_defaultê  s    c         K   s   |  j  j | ƒ d  S(   N(   R   R-   (   R   Rj   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   set_defaultsí  s    c         C   s2   |  j  } x! |  j D] } | j | j  ƒ q W| S(   N(   R]   R�   t   extend(   R   t   optionsRŽ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _get_all_optionsð  s    
c         C   sŒ   |  j  s t |  j ƒ S|  j j ƒ  } xZ |  j ƒ  D]L } | j | j ƒ } t | ƒ r2 | j ƒ  } | j	 | | ƒ | | j <q2 q2 Wt | ƒ S(   N(
   R†   R   R   t   copyR¡   Rm   Rg   R   t   get_opt_stringt   check_value(   R   R   R^   Rh   Rn   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   get_default_valuesö  s    	 c         O   s«   t  | d ƒ t j k r. t |  | | Ž } ni t | ƒ d k rŽ | rŽ | d } t | t ƒ sp t d | ‚ n  | j |  k	 r— t d ‚ q— n	 t d ‚ |  j	 j
 | ƒ | S(   Ni    i   s   not an OptionGroup instance: %rs"   invalid OptionGroup (wrong parser)s   invalid arguments(   Rd   R   R   R   Re   R   Rf   RO   R1   R�   RW   (   R   Ri   Rj   RŽ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   add_option_group  s    
	c         C   sD   |  j  j | ƒ p! |  j j | ƒ } | r@ | j |  k	 r@ | j Sd  S(   N(   RK   Rm   RM   R\   R)   (   R   Rn   R^   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   get_option_group  s
    c         C   s    | d  k r t j d S| Sd  S(   Ni   (   R)   R5   t   argv(   R   Ri   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt	   _get_args!  s    c         C   s«   |  j  | ƒ } | d k r* |  j ƒ  } n  | |  _ g  |  _ } | |  _ y |  j | | | ƒ } Wn, t t f k
 r� } |  j	 t
 | ƒ ƒ n X| | } |  j | | ƒ S(   sS  
        parse_args(args : [string] = sys.argv[1:],
                   values : Values = None)
        -> (values : Values, args : [string])

        Parse the command-line options found in 'args' (default:
        sys.argv[1:]).  Any errors result in a call to 'error()', which
        by default prints the usage message to stderr and calls
        sys.exit() with an error message.  On success returns a pair
        (values, args) where 'values' is an Values instance (with all
        your option values) and 'args' is the list of arguments left
        over after parsing options.
        N(   R©   R)   R¥   R”   R•   R–   t   _process_argsR   R   RQ   R    t   check_values(   R   Ri   R–   R”   R•   t   stopt   err(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt
   parse_args'  s    		
c         C   s
   | | f S(   s³  
        check_values(values : Values, args : [string])
        -> (values : Values, args : [string])

        Check that the supplied option values and leftover arguments are
        valid.  Returns the option values and leftover arguments
        (possibly adjusted, possibly completely new -- whatever you
        like).  Default implementation just returns the passed-in
        values; subclasses may override as desired.
        (    (   R   R–   Ri   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR«   N  s    c         C   s±   xª | r¬ | d } | d k r* | d =d S| d d !d k rP |  j  | | ƒ q | d  d k r… t | ƒ d k r… |  j | | ƒ q |  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   i   t   -(   t   _process_long_optRe   t   _process_short_optsR…   RW   (   R   R•   R”   R–   t   arg(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRª   [  s    
	
"	
c         C   s   t  | |  j ƒ S(   s  _match_long_opt(opt : string) -> string

        Determine which long option string 'opt' matches, ie. which one
        it is an unambiguous abbrevation for.  Raises BadOptionError if
        'opt' doesn't unambiguously match any long option string.
        (   t   _match_abbrevRM   (   R   R`   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _match_long_optŽ  s    c   
      C   s_  | j  d ƒ } d | k rL | j d d ƒ \ } } | j d | ƒ t } n | } t } |  j | ƒ } |  j | } | j ƒ  r| j } t	 | ƒ | k  rá | d k rÁ |  j
 t d ƒ | ƒ q|  j
 t d ƒ | | f ƒ qE| d k rÿ | j  d ƒ }	 qEt | d | !ƒ }	 | d | 5n& | r?|  j
 t d ƒ | ƒ n d  }	 | j | |	 | |  ƒ d  S(   Ni    t   =i   s   %s option requires an arguments   %s option requires %d argumentss   %s option does not take a value(   t   popt   splitt   insertR„   R™   R´   RM   t   takes_valuet   nargsRe   RQ   R�   t   tupleR)   R›   (
   R   R”   R–   R²   R`   t   next_argt   had_explicit_valueR^   Rº   R@   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR°   —  s0    		c         C   so  | j  d ƒ } t } d } xM| d D]A} d | } |  j j | ƒ } | d 7} | sg t | ƒ ‚ n  | j ƒ  rA| t | ƒ k  r¢ | j d | | ƒ t } n  | j	 }	 t | ƒ |	 k  r|	 d k rã |  j
 t d ƒ | ƒ q>|  j
 t d ƒ | |	 f ƒ qG|	 d k r!| j  d ƒ }
 qGt | d |	 !ƒ }
 | d |	 5n d  }
 | j | |
 | |  ƒ | r& Pq& q& Wd  S(   Ni    i   R¯   s   %s option requires an arguments   %s option requires %d arguments(   R¶   R™   RK   Rm   R   R¹   Re   R¸   R„   Rº   RQ   R�   R»   R)   R›   (   R   R”   R–   R²   R¬   t   it   chR`   R^   Rº   R@   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR±   ¼  s6    

		c         C   s1   |  j  d  k r& t j j t j d ƒ S|  j  Sd  S(   Ni    (   R‚   R)   t   ost   patht   basenameR5   R¨   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   get_prog_nameæ  s    c         C   s   | j  d |  j ƒ  ƒ S(   Ns   %prog(   t   replaceRÃ   (   R   t   s(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   expand_prog_nameì  s    c         C   s   |  j  |  j ƒ S(   N(   RÆ   RJ   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRT   ï  s    i    c         C   s*   | r t  j j | ƒ n  t  j | ƒ d  S(   N(   R5   t   stderrt   writet   exit(   R   t   statust   msg(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRÉ   ò  s    c         C   s4   |  j  t j ƒ |  j d d |  j ƒ  | f ƒ d S(   sÜ   error(msg : string)

        Print a usage message incorporating 'msg' to stderr and exit.
        If you override this in a subclass, it should not return -- it
        should either exit or raise an exception.
        i   s   %s: error: %s
N(   t   print_usageR5   RÇ   RÉ   RÃ   (   R   RË   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRQ   ÷  s    c         C   s-   |  j  r% |  j j |  j |  j  ƒ ƒ Sd Sd  S(   NRr   (   R‹   Ru   t   format_usageRÆ   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt	   get_usage  s    		c         C   s    |  j  r | |  j ƒ  IJn  d S(   s`  print_usage(file : file = stdout)

        Print the usage message for the current program (self.usage) to
        'file' (default stdout).  Any occurence of the string "%prog" in
        self.usage is replaced with the name of the current program
        (basename of sys.argv[0]).  Does nothing if self.usage is empty
        or not defined.
        N(   R‹   RÎ   (   R   t   file(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRÌ     s    		c         C   s!   |  j  r |  j |  j  ƒ Sd Sd  S(   NRr   (   Rƒ   RÆ   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   get_version  s    	c         C   s    |  j  r | |  j ƒ  IJn  d S(   sD  print_version(file : file = stdout)

        Print the version message for this program (self.version) to
        'file' (default stdout).  As with print_usage(), any occurence
        of "%prog" in self.version is replaced by the current program's
        name.  Does nothing if self.version is empty or undefined.
        N(   Rƒ   RÐ   (   R   RÏ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   print_version  s    	c         C   sÕ   | d  k r |  j } n  | j |  ƒ g  } | j | j t d ƒ ƒ ƒ | j ƒ  |  j rƒ | j t j	 |  | ƒ ƒ | j d ƒ n  x4 |  j
 D]) } | j | j | ƒ ƒ | j d ƒ q� W| j ƒ  d j | d  ƒ S(   Nt   Optionss   
Rr   iÿÿÿÿ(   R)   Ru   t   store_option_stringsRW   R}   R�   R~   R]   R   Rw   R�   Ry   R   RY   (   R   Ru   Rv   RŽ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRw   %  s    
	
c         C   s   | j  |  j ƒ S(   N(   t   format_epilogRˆ   (   R   Ru   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRÔ   6  s    c         C   s    | d  k r |  j } n  g  } |  j rA | j |  j ƒ  d ƒ n  |  j rg | j |  j | ƒ d ƒ n  | j |  j | ƒ ƒ | j |  j | ƒ ƒ d j	 | ƒ S(   Ns   
Rr   (
   R)   Ru   R‹   RW   RÎ   RJ   Rx   Rw   RÔ   RY   (   R   Ru   Rv   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRy   9  s    		c         C   s/   | d k r t j } n  | j |  j ƒ  ƒ d S(   s°   print_help(file : file = stdout)

        Print an extended help message, listing all options and any
        help text provided with them, to 'file' (default stdout).
        N(   R)   R5   t   stdoutRÈ   Ry   (   R   RÏ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt
   print_helpE  s    N(,   RB   RC   Rz   R“   R)   R   R„   R   RU   RE   R‘   R’   R‰   RŠ   R�   R˜   Rš   Rœ   R�   Rž   R¡   R¥   R¦   R§   R©   R®   R«   Rª   R´   R°   R±   RÃ   RÆ   RT   RÉ   RQ   RÎ   RÌ   RÐ   RÑ   Rw   RÔ   Ry   RÖ   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   =  s`   ?				
												
	'		3			%	*				
			c         C   sƒ   | j  |  ƒ r |  Sg  | j ƒ  D] } | j |  ƒ r  | ^ q  } t | ƒ d k r[ | d S| sp t |  ƒ ‚ n t |  | ƒ ‚ d S(   sû   _match_abbrev(s : string, wordmap : {string : Option}) -> string

    Return the string key in 'wordmap' for which 's' is an unambiguous
    abbreviation.  If 's' is found to be ambiguous or doesn't match any of
    'words', raise BadOptionError.
    i   i    N(   R(   t   keysRZ   Re   R   R	   (   RÅ   t   wordmapt   wordt   possibilities(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR³   R  s    c         C   s   |  d  |  d j  d d ƒ S(   Ni   R�   R¯   (   RÄ   (   RÅ   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   _long_opt_no_underscoresi  s    RL   c           B   sA   e  Z d  „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z RS(   c         C   s   i  |  _  d  S(   N(   t   _data(   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR   n  s    c         C   s   |  j  j ƒ  S(   N(   RÜ   R×   (   R   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR×   q  s    c         C   s0   | d j  d ƒ d k  s t ‚ | |  j | <d  S(   Ni   R�   i    (   t   findt   AssertionErrorRÜ   (   R   t   keyR@   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   __setitem__t  s    c         C   s   |  j  t | ƒ S(   N(   RÜ   RÛ   (   R   Rß   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   __getitem__x  s    c         C   s   |  j  j t | ƒ | ƒ S(   N(   RÜ   Rm   RÛ   (   R   Rß   Rh   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRm   {  s    c         C   s   |  j  j t | ƒ ƒ S(   N(   RÜ   R(   RÛ   (   R   Rß   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyR(   ~  s    N(	   RB   RC   R   R×   Rà   Rá   R)   Rm   R(   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyRL   l  s   				(!   Rz   t
   __future__R    R5   RÀ   R   t   optik.optionR   R   R   t
   optik.helpR   t   optik.errorsR   R�   R   R   R   R	   t   __all__R
   R   R„   R™   t	   NameErrorR   R   R   R   R   R³   RÛ   RL   (    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pythonpath/optik/option_parser.pyt   <module>   s0   (

	A¼ÿ ÿ 		