��Qc@s�dZdZddlZddlZddlZddlZddlmZmZdZ ej
de �Zej
de e f�Zej
dd �Zd
fd��YZd�Zej
ejd
eej��Zd�Zd�Zdfd��YZdS(s6distutils.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(tDistutilsGetoptErrortDistutilsArgErrors[a-zA-Z](?:[a-zA-Z0-9-]*)s^%s$s^(%s)=!(%s)$t-t_tFancyGetoptcBs�eZdZdd�Zd�Zd�Zddd�Zd�Zd�Z d�Z
d�Zd �Zd
�Z
ddd�Zd�Zdd
�Zddd�ZRS(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
cCst||_i|_|jr(|j�ni|_i|_g|_g|_i|_i|_i|_ g|_
dS(N(toption_tabletoption_indext_build_indextaliastnegative_aliast
short_optst long_optst
short2longt attr_namet takes_argtoption_order(tselfR((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt__init__-s
cCs6|jj�x"|jD]}||j|d<qWdS(Ni(RtclearR(Rtoption((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyRYs
cCs||_|j�dS(N(RR(RR((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pytset_option_table^s cCsO||jkrtd|�n,|||f}|jj|�||j|<dS(Ns'option conflict: already an option '%s'(RRRtappend(Rtlong_optiontshort_optionthelp_stringR((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt
add_optionbs
cCs
||jkS(scReturn true if the option table for this parser has an
option with long name 'long_option'.(R(RR((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt
has_optionlscCstj|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.(tstringt translatet
longopt_xlate(RR((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt
get_attr_nameqscCs�t|t�st�xj|j�D]\\}}||jkrVtd|||f�n||jkr"td|||f�q"q"WdS(Ns(invalid %s '%s': option '%s' not defineds0invalid %s '%s': aliased option '%s' not defined(t
isinstancetdicttAssertionErrortitemsRR(RtaliasestwhatRtopt((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt_check_alias_dictxscCs|j|d�||_dS(s'Set the aliases for this option parser.RN(R&R(RR((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pytset_aliases�scCs|j|d�||_dS(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.snegative aliasN(R&R (RR ((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pytset_negative_aliases�scCs�g|_g|_|jj�i|_x]|jD]R}t|�dkrb|\}}}d}n7t|�dkr�|\}}}}ntd|f�t|t �s�t|�dkr�t
d|�n|dkp�|t �o�|�dkst
d|�n||j|<|jj|�|d d
kre|rH|d}n|dd !}d|j
|<nk|jj|�}|dk r�|j
|r�t
d||f�n||jd <d|j
|<n
d|j
|<|jj|�}|dk r!|j
||j
|kr!t
d
||f�q!ntj|�sDt
dd|�n|j|�|j|<|r2|jj|�||j|d<q2q2WdS(s�Populate the various data structures that keep tabs on the
option table. Called by 'getopt()' before it can do anything
worthwhile.
iiisinvalid option tuple: %ris9invalid long option '%s': must be a string of length >= 2is:invalid short option '%s': must a single character or Nonei�t=t:s>invalid negative alias '%s': aliased option '%s' takes a valuesginvalid alias '%s': inconsistent with aliased option '%s' (one of them takes a value, the other doesn'tsinvalid long option name '%s' s'(must be letters, numbers, hyphens onlyN(RR
RRtrepeatRtlent
ValueErrorRtstrRtNoneRRR tgetRt
longopt_retmatchRR
(RRtlongtshortthelpR+talias_to((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt_grok_option_table�sd
"
!
cCs|dkrtjd}n|dkr:t�}d}nd}|j�tj|j�}y"tj|||j �\}}Wntj
k
r�}t|�nXx\|D]T\}}t|�dkr�ddkr�j
|d}n2t|�dkr|d dkst�|d}|jj|�} | r<| }n|j|s�|dksatd��|jj|�} | r�| }d}q�d}n|j|}
|r�|jj|
�dk r�t||
d�d}nt||
|�|jj||f�q�W|r||fS|SdS( sParse 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.
iiiRs--tsboolean option can't have valueN(R/tsystargvtOptionDummyR7RtjoinR
tgetoptRterrorRR,RR!RR0RR R
R+tgetattrtsetattrRR(Rtargstobjecttcreated_objectR
toptstmsgR%tvalRtattr((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyR=�sF
"
"(
cCs&|jdkrtd�n|jSdS(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(RR/tRuntimeError(R((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pytget_option_order*scCs�d}x||jD]q}|d}|d}t|�}|ddkrS|d}n|dk rl|d}n||kr|}qqW|ddd}d}||} d|}
|r�|g}n d g}x|jD]}|d
\}}}t|| �}
|ddkr|dd!}n|dkrk|
rQ|jd|||
df�q�|jd||f�nHd
||f}|
r�|jd|||
df�n|jd|�x#|
dD]}|j|
|�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.
iii�R)iiiNt sOption summary:is --%-*s %ss
--%-*s s%s (-%s)s --%-*sN(RR,R/t wrap_textR(Rtheadertmax_optRR3R4tlt opt_widtht
line_widtht
text_widtht
big_indenttlinesR5ttextt opt_names((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt
generate_help5sF
! cCsG|dkrtj}nx(|j|�D]}|j|d�q(WdS(Ns
(R/R9tstdoutRVtwrite(RRLtfiletline((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt
print_help�sN(t__name__t
__module__t__doc__R/RRRRRRR&R'R(R7R=RIRVR[(((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyR!s
,
X@ TcCs)t|�}|j|�|j||�S(N(RR(R=(toptionstnegative_optRBRAtparser((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pytfancy_getopt�s
RJcCs~|dkrgSt|�|kr)|gStj|�}tj|t�}tjd|�}td|�}g}x|ryg}d}xt|r�|d�}|||kr�|j |d�|d=||}q�|r�dddkr�d=nPq�W|r]|dkr<|j |dd|!�|d||d<n|dddkr]|d=q]n|j tj
|d��qtW|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( +|-+)ii�RJR8N(R/R,Rt
expandtabsRtWS_TRANStretsplittfilterRR<(RTtwidthtchunksRStcur_linetcur_lenRN((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyRK�s:
cCstj|t�S(sXConvert a long option name to a valid Python identifier by
changing "-" to "_".
(RRR(R%((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyttranslate_longopt�sR;cBseZdZgd�ZRS(s_Dummy class just used as a place to hold command-line option
values as instance attributes.cCs%x|D]}t||d�qWdS(skCreate a new OptionDummy instance. The attributes listed in
'options' will be initialized to None.N(R@R/(RR_R%((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyR�s
(R\R]R^R(((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyR;�s(R^t__revision__R9RReR=tdistutils.errorsRRtlongopt_pattcompileR1tneg_alias_ret maketransRRRbt
whitespaceR,RdRKRlR;(((sI/usr/jas/src/cmd/cpython/dist/sys/lib/python2.7/distutils/fancy_getopt.pyt<module> s"�" ;
|