;
AHc           @   s5  d  Z  d Z d Z d Z d k Z d k Z d k Z d k Z d e f d     YZ	 d e	 f d     YZ
 d	 e	 f d
     YZ d e	 f d     YZ e i d  Z d Z d Z d Z d Z d Z d Z d Z h  e d   <e e i <e e i <e d   <e d   <Z d f  d     YZ d Z d   Z d S(   s  DPyGetOpt -- Demiurge Python GetOptions Module

 $Id: DPyGetOpt.py 2872 2007-11-25 17:58:05Z fperez $

This module is modeled after perl's Getopt::Long module-- which
is, in turn, modeled after GNU's extended getopt() function.

Upon instantiation, the option specification should be a sequence
(list) of option definitions.

Options that take no arguments should simply contain the name of
the option.  If a ! is post-pended, the option can be negated by
prepending 'no';  ie 'debug!' specifies that -debug and -nodebug
should be accepted.

Mandatory arguments to options are specified using a postpended
'=' + a type specifier.  '=s' specifies a mandatory string
argument, '=i' specifies a mandatory integer argument, and '=f'
specifies a mandatory real number.  In all cases, the '=' can be
substituted with ':' to specify that the argument is optional.

Dashes '-' in option names are allowed.

If an option has the character '@' postpended (after the
argumentation specification), it can appear multiple times within
each argument list that is processed. The results will be stored
in a list.

The option name can actually be a list of names separated by '|'
characters;  ie-- 'foo|bar|baz=f@' specifies that all -foo, -bar,
and -baz options that appear on within the parsed argument list
must have a real number argument and that the accumulated list
of values will be available under the name 'foo'

$Id: DPyGetOpt.py 2872 2007-11-25 17:58:05Z fperez $s    Bill Bumgarner <bbum@friday.com>s   MITs   1.2Ns   Errorc           B   s   t  Z d  Z RS(   s2   Base class for exceptions in the DPyGetOpt module.(   s   __name__s
   __module__s   __doc__(    (    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   ErrorM   s   s   ArgumentErrorc           B   s   t  Z d  Z RS(   sX   Exception indicating an error in the arguments passed to
    DPyGetOpt.processArguments.(   s   __name__s
   __module__s   __doc__(    (    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   ArgumentErrorP   s   s   SpecificationErrorc           B   s   t  Z d  Z RS(   s;   Exception indicating an error with an option specification.(   s   __name__s
   __module__s   __doc__(    (    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   SpecificationErrorT   s   s   TerminationErrorc           B   s   t  Z d  Z RS(   sC   Exception indicating an error with an option processing terminator.(   s   __name__s
   __module__s   __doc__(    (    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   TerminationErrorW   s   s'   (?P<required>.)(?P<type>.)(?P<multi>@?)s   Requires an Arguments   Argument Optionals   String Argument Types   Integer Argument Types   Real Argument Types   Boolean Argument Types   Generic Argument Typec         C   s   |  S(   N(   s   x(   s   x(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   <lambda>k   s    s	   DPyGetOptc           B   s   t  Z e d g d  Z d d  Z d   Z d d  Z d   Z d d	  Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z e d  Z e d  Z RS(   Ns   --c         C   s   d |  _ g  |  _ d |  _ d |  _ h  |  _ t |  _ g  |  _ h  |  _	 d |  _
 d |  _ g  |  _ | |  _ g  |  _ t |  _ |  i   |  i   |  i   | o |  i |  n d S(   s  
        Declare and intialize instance variables

        Yes, declaration is not necessary... but one of the things
        I sorely miss from C/Obj-C is the concept of having an
        interface definition that clearly declares all instance
        variables and methods without providing any implementation
         details.   it is a useful reference!

        all instance variables are initialized to 0/Null/None of
        the appropriate type-- not even the default value...
        i   i    N(   s   selfs   allowAbbreviationss
   freeValuess
   ignoreCases
   needsParses   optionNamess   Nones   optionStartExprs   optionTupless   optionValuess
   orderMixeds   posixCompliances   specs   terminatorss
   termValuess
   terminators   setPosixCompliances   setIgnoreCases   setAllowAbbreviationss   parseConfiguration(   s   selfs   specs   terminators(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   __init__t   s(     														


i    c         C   sZ   | |  _ d |  _ |  i o t i d  |  _ d |  _ n t i d  |  _ d |  _ d S(   s   
        Enables and disables posix compliance.

        When enabled, '+' can be used as an option prefix and free
        values can be mixed with options.
        i   s-   (--|-)(?P<option>[A-Za-z0-9_-]+)(?P<arg>=.*)?i    s0   (--|-|\+)(?P<option>[A-Za-z0-9_-]+)(?P<arg>=.*)?N(   s   aFlags   selfs   posixCompliances
   needsParses   res   compiles   optionStartExprs
   orderMixed(   s   selfs   aFlag(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   setPosixCompliance   s     		
c         C   s   |  i Sd S(   sA   
        Returns the value of the posix compliance flag.
        N(   s   selfs   posixCompliance(   s   self(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   isPosixCompliant   s     i   c         C   s   d |  _ | |  _ d S(   sN   
        Enables and disables ignoring case during option processing.
        i   N(   s   selfs
   needsParses   aFlags
   ignoreCase(   s   selfs   aFlag(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   setIgnoreCase   s     	c         C   s   |  i Sd S(   se   
        Returns 1 if the option processor will ignore case when
        processing options.
        N(   s   selfs
   ignoreCase(   s   self(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys
   ignoreCase   s     c         C   s   | |  _ d S(   sg   
        Enables and disables the expansion of abbreviations during
        option processing.
        N(   s   aFlags   selfs   allowAbbreviations(   s   selfs   aFlag(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   setAllowAbbreviations   s     c         C   s   |  i Sd S(   s   
        Returns 1 if abbreviated options will be automatically
        expanded to the non-abbreviated form (instead of causing an
        unrecognized option error).
        N(   s   selfs   allowAbbreviations(   s   self(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   willAllowAbbreviations   s     c         C   s   |  i | g |  _ d S(   s  
        Adds newTerm as terminator of option processing.

        Whenever the option processor encounters one of the terminators
        during option processing, the processing of options terminates
        immediately, all remaining options are stored in the termValues
        instance variable and the full name of the terminator is stored
        in the terminator instance variable.
        N(   s   selfs   terminatorss   newTerm(   s   selfs   newTerm(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   addTerminator   s    	 c   
      C   sm  | \ } \ }	 } } } } |  i i	 |  oC | o  t
 d | d | d   qq t
 d | d t   n |  i |  i | <|  i d |  _ |  i | g |  _ |	 t j o d | } |	 | d | f } | | | f } |  i i	 |  oC | o  t
 d	 | d | d   q2t
 d
 | d t   n |  i |  i | <|  i d |  _ |  i | g |  _ n d S(   s   
        Adds the option described by oTuple (name, (type, mode,
        default), alias) to optionTuples.  Adds index keyed under name
        to optionNames.  Raises SpecificationError if name already in
        optionNames
        s   Alias 's   ' for 's+   ' already used for another option or alias.s   Option named 's+   ' specified more than once. Specification: i   s   noi    s   Negated alias 's   Negated option named 'N(   s   oTuples   names   types   modes   defaults   multis   realNames   selfs   optionNamess   has_keys   SpecificationErrors   options
   tupleIndexs   optionTupless   BooleanArgTypes   aliass	   specTuple(
   s   selfs   oTuples   multis   names   aliass   defaults	   specTuples   realNames   modes   type(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys
   _addOption   s(      
 c         C   sl   | \ } } } |  i oB t i |  } | o t i |  } n | } | | | f } n |  i |  d  S(   N(	   s   oTuples   names   argSpecs   realNames   selfs
   ignoreCases   strings   lowers
   _addOption(   s   selfs   oTuples   realNames   names   argSpec(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   addOptionConfigurationTuple  s    
c         C   sF   t  |  t j o" x, | D] } |  i |  q Wn |  i |  d  S(   N(   s   types   oTuples   ListTypes   ts   selfs   addOptionConfigurationTuple(   s   selfs   oTuples   t(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   addOptionConfigurationTuples  s
     c         C   s  | |  _  g  |  _ h  |  _ d |  _ d } t i d  } x| D]}
 |  i	 o t
 i |
  }
 n | i |
  }	 |	 t j o t d |
 d   n |	 i d  } |	 i d  } t
 i | d  } | d } | d } | o t } t } d } d } n\| d	 j o t } t } d } d } n3t i |  }	 |	 t j o t d
 |
 d   n |	 i d  } | d j o
 t } n, | d j o
 t } n t d | d   |	 i d  } | d j o t! } d } n\ | d j o t" } d } n? | d j p
 | d j o t# } d } n t d | d   |	 i d  d j o
 d } n d } | | | | f } | | | f } |  i& |  xG | D]? } |  i	 o t
 i |  } n | | | f } |  i& |  qWq@ Wd |  _( d  S(   Ni    s6   (?P<names>\w+[-A-Za-z0-9|]*)?(?P<spec>!|[=:][infs]@?)?s   Invalid specification {s   }s   namess   specs   |i   s   !s"   Invalid configuration for option 's   's   requireds   =s   :s#   Unknown requirement configuration 's   types   ss    s   is   fs   ns   Unknown type specifier 's   multis   @()   s   specs   selfs   optionTupless   optionNamess
   tupleIndexs   res   compiles	   splitExprs   options
   ignoreCases   strings   lowers   matchs   Nones   SpecificationErrors   groups   namess   specifications   splits   nlists   names   aliasess   GenericArgTypes   argTypes   argModes
   argDefaults   argMultiples   BooleanArgTypes   specificationExprs   requireds   ArgRequireds   ArgOptionals   types   StringArgTypes   IntegerArgTypes   RealArgTypes	   specTuples   oTuples
   _addOptions   aliass
   needsParse(   s   selfs   specs
   argDefaults
   tupleIndexs	   specTuples	   splitExprs   namess   aliasess   types   matchs   options   argModes   nlists   argMultiples   names   requireds   aliass   oTuples   argTypes   specification(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   parseConfiguration&  sz    				 










 
c         C   s   y |  i | } |  i | g SWn& t j
 o |  i o t SqH n Xt i	 d |  } t | d  |  i  } t |  o t Sn | Sd S(   s  
        Returns a list containing all the specification tuples that
        match argName.  If none match, None is returned.  If one
        matches, a list with one tuple is returned.  If more than one
        match, a list containing all the tuples that matched is
        returned.

        In other words, this function does not pass judgement upon the
        validity of multiple matches.
        s   ^c         C   s   | i |  d  t j	 S(   Ni    (   s   argExprs   searchs   xs   None(   s   xs   argExpr(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   <lambda>  s    N(   s   selfs   optionNamess   argNames
   tupleIndexs   optionTupless   KeyErrors   allowAbbreviationss   Nones   res   compiles   argExprs   filters   tupless   len(   s   selfs   argNames   argExprs   tupless
   tupleIndex(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   _getArgTuple  s    
 c         C   s   | |  i j o | |  _ n |  i o t Sn t | d  |  i  } t |  o t Sn6 t |  d j o" t	 d | d t
 |    n | d |  _ |  i Sd S(   s*  
        Returns the full name of the terminator if optionName is a valid
        terminator.  If it is, sets self.terminator to the full name of
        the terminator.

        If more than one terminator matched, raises a TerminationError with a
        string describing the ambiguity.
        c         C   s   t  i |  |  d j S(   Ni    (   s   strings   finds   xs   on(   s   xs   on(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   <lambda>  s    i   s   Ambiguous terminator 's
   ' matches i    N(   s
   optionNames   selfs   terminatorss
   terminators   allowAbbreviationss   Nones   filters   termss   lens   TerminationErrors   repr(   s   selfs
   optionNames   terms(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   _isTerminator  s     "c         C   s  t  t d  o | t i j o t i d } n t |  } g  |  _ h  |  _ d } t
 |  _ g  |  _ xr| | j  od| | } | d } |  i |  o) |  i | | |  _ | | |  _ d Sn |  i i |  } | t
 j oA |  i | g |  _ |  i o |  i | | |  _ d Sq$qj n | i d  } | i d  }
 |
 o |
 d }
 | d } n y | | }
 Wn t
 }
 n X|  i o t i |  } n |  i |  }	 |	 t
 j o t d | d   nL t |	  d j o. t d	 | d
 t t d   |	     n |	 d } | \ } } } | \ } } } } | t% j o8 |
 p |  i |
  o t d | d |   qn | t
 j o |
 o |  i |
  o ye t& | } y | |
  } | d } Wn: | t% j o  t d | d | d   q| } n XWqQt j
 o
   qQt d | d | d   qQXn | } | o= y |  i | | g |  i | <Wq| g |  i | <qXqj |  i) o |  i i* |  o t d | d   n | |  i | <qj Wd S(   sx  
        Processes args, a list of arguments (including options).

        If args is the same as sys.argv, automatically trims the first
        argument (the executable name/path).

        If an exception is not raised, the argument list was parsed
        correctly.

        Upon successful completion, the freeValues instance variable
        will contain all the arguments that were not associated with an
        option in the order they were encountered.  optionValues is a
        dictionary containing the value of each option-- the method
        valueForOption() can be used to query this dictionary.
        terminator will contain the argument encountered that terminated
        option processing (or None, if a terminator was never
        encountered) and termValues will contain all of the options that
        appeared after the Terminator (or an empty list).
        s   argvi   i    Ns   options   args   Illegal option 's   's   Ambiguous option 's   ';  matches c         C   s   |  d S(   Ni    (   s   x(   s   x(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   <lambda>)  s    s   Option 's   ' requires an argument of type s   Invalid argument to option 's   ';  should be 's   (s   ) Conversion function for 's   ' not found.s
   Argument 's   ' occurs multiple times.(+   s   hasattrs   syss   argss   argvs   lens   maxs   selfs
   freeValuess   optionValuess   indexs   Nones
   terminators
   termValuess   args   _isTerminators   optionStartExprs   matchs
   orderMixeds   groups   optNames   nextArgs
   ignoreCases   strings   lowers   _getArgTuples   tupless   ArgumentErrors   reprs   maps   configs   fullNames   specs   realNames   optTypes   optModes
   optDefaults   optMultiples   ArgRequireds   ConversionFunctionss   funcs   optionValues   isPosixCompliants   has_key(   s   selfs   argss   optTypes
   optDefaults   args   optModes   indexs   realNames   optNames   tupless   nextArgs   configs   specs   matchs   maxs   funcs   optionValues   fullNames   optMultiple(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   processArguments  s      				 




.
 &
 $c         C   s)   y |  i | } Wn | } n X| Sd S(   s   
        Return the value associated with optionName.  If optionName was
        not encountered during parsing of the arguments, returns the
        defaultValue (which defaults to None).
        N(   s   selfs   optionValuess
   optionNames   optionValues   defaultValue(   s   selfs
   optionNames   defaultValues   optionValue(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   valueForOptiond  s     
(   s   __name__s
   __module__s   Nones   __init__s   setPosixCompliances   isPosixCompliants   setIgnoreCases
   ignoreCases   setAllowAbbreviationss   willAllowAbbreviationss   addTerminators
   _addOptions   addOptionConfigurationTuples   addOptionConfigurationTupless   parseConfigurations   _getArgTuples   _isTerminators   processArgumentss   valueForOption(    (    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys	   DPyGetOptr   s    *					3			i	(	 s   Test Run Amok!c          C   s  y t  d d d g  Wn t j
 o } d | GHn Xy t  d d g  Wn t j
 o } d | GHn Xt  d d g  } y | i d	 d
 g  Wn t j
 o } d | GHn Xt  d g d d g  } y | i d d g  Wn t j
 o } d | GHn Xd d d d d d g }  d g } d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d. g } d3 t |   GHd4 t |  GHd5 t |  GHt  |  |  } | i |  d6 t | i
  GHd7 t | i  GHd8 t | i  GHd9 S(:   s+   
    A relatively complete test suite.
    s   foos   bar=ss.   EXCEPTION (should be 'foo' already used..): %ss   foo|bar|apple=s@s
   baz|apple!s4   EXCEPTION (should be duplicate alias/name error): %ss   apple|atlas=i@s   application|executable=f@s   -apps   29.3s,   EXCEPTION (should be ambiguous argument): %ss   antigravitys
   antithesiss   -foos   antis.   EXCEPTION (should be ambiguous terminator): %ss   plain-options   boolean-option!s   list-of-integers=i@s7   list-real-option|list-real-alias|list-real-pseudonym=f@s   optional-string-option:ss   abbreviated-string-list=s@s
   terminators   -plain-options   +noboolean-options   --list-of-integerss   1s   +list-of-integerss   2s   -list-of-integerss   3s
   freeargones   -list-real-options   1.1s   +list-real-aliass   1.2s   --list-real-pseudonyms   1.3s
   freeargtwos   -abbreviated-string-lists   String1s   --abbreviated-ss   String2s   -abbrevs   String3s   -as   String4s   -optional-string-options   terms+   next option should look like an invalid args   Using profile: s   With terminator: s   Processing arguments: s   Options (and values): s   free args: s   term args: N(   s	   DPyGetOpts   Errors   excs   xs   processArgumentss   profiles   terminatorss   argss   reprs   gos   optionValuess
   freeValuess
   termValues(   s   profiles   terminatorss   argss   gos   xs   exc(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   _testu  s<     	Z(   s   __doc__s
   __author__s   __license__s   __version__s   res   strings   syss   typess	   Exceptions   Errors   ArgumentErrors   SpecificationErrors   TerminationErrors   compiles   specificationExprs   ArgRequireds   ArgOptionals   StringArgTypes   IntegerArgTypes   RealArgTypes   BooleanArgTypes   GenericArgTypes   atois   atofs   ConversionFunctionss	   DPyGetOpts
   test_errors   _test(   s   _tests   ArgOptionals   StringArgTypes   BooleanArgTypes   IntegerArgTypes   res   GenericArgTypes   __version__s
   test_errors   TerminationErrors	   DPyGetOpts   strings   __license__s   ArgRequireds
   __author__s   ConversionFunctionss   Errors   typess   syss   RealArgTypes   ArgumentErrors   SpecificationErrors   specificationExpr(    (    sA   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/DPyGetOpt.pys   ?$   s2   				B  