mς
­fIc           @   s‘  d  k  Z  d k  l Z d k l Z l Z l Z d  k Z e d  Z e i	 i
 d  Z e d  j	 o e i	 d =n e o	 d GHn e e  i d d   e e  i d d   e d e  e d	 e  e o	 d
 GHn e  i d d g  \ Z Z e e  e e d j  e  i d d g  \ Z Z e e  e e d j  e  i d d g  \ Z Z e e  e e d j  e d e  e d e  e d d e  e o	 d GHn e  i g  d d g   \ Z Z e e d< g j  e e g  j  e  i g  d d g   \ Z Z e e d= g j  e e g  j  e  i g  d d d g  \ Z Z e e d> g j  e e g  j  e  i g  d d d d g  \ Z Z e e d? g j  e e d g j  e d e  e d e  e o	 d GHn e  i g  d d g g   \ Z Z e e d@ g j  e e g  j  e  i g  d d g g   \ Z Z e e dA g j  e e g  j  e  i g  d d g g   \ Z Z e e dB g j  e e g  j  e  i g  d d d d g g   \ Z Z e e dC g j  e e g  j  e  i g  d  d! d" g g   \ Z Z e e dD g j  e e g  j  e d% e  e d& e  d d d' d( d) d d* d d d) d+ d, g Z e o	 d- GHn e  i  e d. d/ d0 g  \ Z Z e e dE dF dG dH dI dJ dK g j  e e d+ d, g j  e d2 e  e o	 d3 GHn d d+ d' d d1 d4 g Z e  i e d5 d6 d7 g  \ Z Z e e dL dM dN dO g j  e e d+ g j  e  i e d8 d6 d7 g  \ Z Z e e dP g j  e e d+ d' d d1 d4 g j  d e i	 d <e  i e d5 d6 d7 g  \ Z Z e e dQ g j  e e d+ d' d d1 d4 g j  e d  j o e i	 d =n e e i	 d <d9 Z h  d: e <Z d  k Z e e i e e  e o	 d; GHn d  S(R   N(   s   GetoptError(   s   verifys   verboses   run_doctestc         B   s,   y |  d UWn | j
 o n X|  d S(   s{   Executes a statement passed in teststr, and raises an exception
       (failure) if the expected exception is *not* raised.N(   t   teststrt   expectedt   failure(   R    R   R   (    (    t-   /mit/python/lib/python2.4/test/test_getopt.pyt   expectException	   s     t   POSIXLY_CORRECTs%   Running tests on getopt.short_has_argt   as   a:s$   tmp = getopt.short_has_arg('a', 'b')s#   tmp = getopt.short_has_arg('a', '')s%   Running tests on getopt.long_has_argst   abcs   abc=t   abcds6   has_arg, option = getopt.long_has_args('abc', ['def'])s1   has_arg, option = getopt.long_has_args('abc', [])s   has_arg, option = s-   getopt.long_has_args('abc', ['abcd','abcde'])s!   Running tests on getopt.do_shortss   -at    t   a1t   1t   2s0   opts, args = getopt.do_shorts([], 'a1', 'a', [])s0   opts, args = getopt.do_shorts([], 'a', 'a:', [])s    Running tests on getopt.do_longss   --abcs   abc=1s   abcd=s   --abcdt   abs   foo=42s   foo-bars   foo=s   --foot   42s6   opts, args = getopt.do_longs([], 'abc=1', ['abc'], [])s5   opts, args = getopt.do_longs([], 'abc', ['abc='], [])s   -bs	   --alpha=2s   --betat   3t   arg1t   arg2s   Running tests on getopt.getopts   a:bs   alpha=t   betas   --alphas=   opts, args = getopt.getopt(cmdline, 'a:b', ['alpha', 'beta'])s"   Running tests on getopt.gnu_getopts   --beta=2s   ab:t   alphas   beta=s   +ab:s#  
Examples from the Library Reference:  Doc/lib/libgetopt.tex

An example using only Unix style options:


>>> import getopt
>>> args = '-a -b -cfoo -d bar a1 a2'.split()
>>> args
['-a', '-b', '-cfoo', '-d', 'bar', 'a1', 'a2']
>>> optlist, args = getopt.getopt(args, 'abc:d:')
>>> optlist
[('-a', ''), ('-b', ''), ('-c', 'foo'), ('-d', 'bar')]
>>> args
['a1', 'a2']

Using long option names is equally easy:


>>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
>>> args = s.split()
>>> args
['--condition=foo', '--testing', '--output-file', 'abc.def', '-x', 'a1', 'a2']
>>> optlist, args = getopt.getopt(args, 'x', [
...     'condition=', 'output-file=', 'testing'])
>>> optlist
[('--condition', 'foo'), ('--testing', ''), ('--output-file', 'abc.def'), ('-x', '')]
>>> args
['a1', 'a2']

t
   libreftests,   Module getopt: tests completed successfully.(   s   -aR	   (   s   -aR   (   s   -aR   (   s   -aR   (   s   --abcR	   (   s   --abcR   (   s   --abcdR   (   s   --abcR	   (   s   --fooR   (   s   -aR   (   s   -bR	   (   s   --alphaR   (   s   --betaR	   (   s   -aR   (   s   -aR	   (   s   --betaR	   (   s   -aR	   (   s   -bR   (   s   --alphaR	   (   s   --betaR   (   s   -aR	   (   s   -aR	   (   t   getoptt   GetoptErrort   test.test_supportt   verifyt   verboset   run_doctestt   ost   AssertionErrorR   t   environt   gett   old_posixly_correctt   Nonet   short_has_argt   long_has_argst   has_argt   optiont	   do_shortst   optst   argst   do_longst   cmdlinet
   gnu_getoptR   t   __test__t   syst   modulest   __name__(   R   R   R)   R   R   R'   R,   R   R   R+   R   R   R#   R   R&   R$   (    (    R   t   ?   sΖ   		
		

	!$	!!!'$*	!%	!!! 	