Viewing File: /opt/alt/python35/lib/python3.5/site-packages/click/__pycache__/parser.cpython-35.pyc



W<@sdZddlZddlmZddlmZmZmZmZddZ	dd	Z
d
dZdd
ZddZ
GdddeZGdddeZGdddeZGdddeZdS)aq
    click.parser
    ~~~~~~~~~~~~

    This module started out as largely a copy paste from the stdlib's
    optparse module with the features removed that we do not need from
    optparse because we implement them in Click on a higher level (for
    instance type handling, help formatting and a lot more).

    The plan is to remove more and more from here over time.

    The reason this is a different module and not optparse from the stdlib
    is that there are differences in 2.x and 3.x about the error messages
    generated and optparse in the stdlib uses gettext for no good reason
    and might cause us issues.
N)deque)
UsageErrorNoSuchOptionBadOptionUsageBadArgumentUsagecshtt|}g}dfddx|r|}|dkrm|jq9|dkrfddt|D}dk	r|j|jt|q9|dkr9dk	rtdt||jdq9Wdk	rRt|<gt|dd|dd<t|tfS)	aGiven an iterable of arguments and an iterable of nargs specifications,
    it returns a tuple with all the unpacked arguments at the first index
    and all remaining arguments as the second.

    The nargs specification is the number of arguments that should be consumed
    or `-1` to indicate that this position should eat up all the remainders.

    Missing items are filled with `None`.
    NcsAy$dkr|jS|jSWntk
r<dSYnXdS)N)popleftpop
IndexError)c)spos
/parser.py_fetch's

z_unpack_args.<locals>._fetchrcsg|]}qSr
r
).0_)rargsr
r
<listcomp>5s	z _unpack_args.<locals>.<listcomp>rzCannot have two nargs < 0)	rappendrangereversetuple	TypeErrorlenreversedlist)rZ
nargs_specrvnargsxr
)rrrr_unpack_argss0
		"
(rcCs6|dkrtd|td||fdS)Nrz%s option requires an argumentz%s option requires %d arguments)r)roptr
r
r_error_opt_argsKsr!cCsn|dd}|jr&d|fS|dd|krZ|dd|ddfS||ddfS)Nr)isalnum)r firstr
r
r	split_optQs
r&cCsB|dks|jdkr|St|\}}||j|S)N)Ztoken_normalize_funcr&)r ctxprefixr
r
r
normalize_optZsr)cCsg}xtjd|tjD]}|jj}|dd|ddkr|dddkr|dd	jddjd}yt||}Wntk
rYnX|j	|qW|S)
zDGiven an argument string this attempts to split it into small parts.z>('([^'\\]*(?:\\.[^'\\]*)*)'|"([^"\\]*(?:\\.[^"\\]*)*)"|\S+)\s*Nrz"'asciibackslashreplacezunicode-escaper,)
refinditerSgroupstripencodedecodetypeUnicodeErrorr)stringrmatchargr
r
rsplit_arg_stringas6	
r9c@sFeZdZddddddZeddZddZdS)	OptionNrc
Csg|_g|_t|_x|D]}t|\}}	|sStd||jj|dt|dkrt|	dkr|jj|q%|jj||jj|q%W|dkrd}||_	||_
||_||_||_
dS)Nz'Invalid start character for option (%s)rrstore)_short_opts
_long_optssetprefixesr&
ValueErroraddrrdestactionrconstobj)
selfoptsrBrCrrDrEr r(valuer
r
r__init__us(		

$				zOption.__init__cCs
|jdkS)Nr;r)zstorezappend)rC)rFr
r
rtakes_valueszOption.takes_valuecCs|jdkr"||j|j<n|jdkrG|j|j|j<n|jdkrx|jj|jgj|n|jdkr|jj|jgj|jnK|jdkr|jj|jdd|j|j<ntd|j|jj|j	dS)	Nr;store_constrZappend_constcountrrzunknown action %r)
rCrGrBrD
setdefaultrgetr@orderrE)rFrHstater
r
rprocesss"%)zOption.process)__name__
__module____qualname__rIpropertyrJrQr
r
r
rr:ssr:c@s.eZdZddddZddZdS)ArgumentrNcCs||_||_||_dS)N)rBrrE)rFrBrrEr
r
rrIs		zArgument.__init__cCs|jdkrktdd|D}|t|krCd}n(|dkrktd|j|jf||j|j<|jj|jdS)Nrcss!|]}|dkrdVqdS)Nrr
)rrr
r
r	<genexpr>sz#Argument.process.<locals>.<genexpr>rzargument %s takes %d values)	rsumrrrBrGrOrrE)rFrHrPZholesr
r
rrQs	zArgument.process)rRrSrTrIrQr
r
r
rrVsrVc@seZdZddZdS)ParsingStatecCs(i|_g|_||_g|_dS)N)rGlargsrargsrO)rFr[r
r
rrIs			zParsingState.__init__N)rRrSrTrIr
r
r
rrYsrYc@seZdZdZdddZddddddZdddd	Zd
dZdd
ZddZ	ddZ
ddZddZdS)OptionParsera+The option parser is an internal class that is ultimately used to
    parse options and arguments.  It's modelled after optparse and brings
    a similar but vastly simplified API.  It should generally not be used
    directly as the high level Click classes wrap it for you.

    It's not nearly as extensible as optparse or argparse as it does not
    implement features that are implemented on a higher level (such as
    types or defaults).

    :param ctx: optionally the :class:`~click.Context` where this parser
                should go with.
    NcCss||_d|_d|_|dk	r?|j|_|j|_i|_i|_tddg|_g|_dS)NTF-z--)r'allow_interspersed_argsignore_unknown_options
_short_opt	_long_optr>
_opt_prefixes_args)rFr'r
r
rrIs					zOptionParser.__init__rc	s|dkr|}fdd|D}t||d|d|d|d|}jj|jx|jD]}|j|<qoWx|jD]}|j|<qWdS)ayAdds a new option named `dest` to the parser.  The destination
        is not inferred (unlike with optparse) and needs to be explicitly
        provided.  Action can be any of ``store``, ``store_const``,
        ``append``, ``appnd_const`` or ``count``.

        The `obj` can be used to identify the option in the order list
        that is returned from the parser.
        Ncs"g|]}t|jqSr
)r)r')rr )rFr
rrs	z+OptionParser.add_option.<locals>.<listcomp>rCrrDrE)r:rbupdater?r<r`r=ra)	rFrGrBrCrrDrEoptionr r
)rFr
add_options
zOptionParser.add_optioncCs;|dkr|}|jjtd|d|d|dS)zAdds a positional argument named `dest` to the parser.

        The `obj` can be used to identify the option in the order list
        that is returned from the parser.
        NrBrrE)rcrrV)rFrBrrEr
r
radd_argumentszOptionParser.add_argumentcCstt|}y|j||j|Wn1tk
r]|jdksV|jjrYYnX|j|j|jfS)aZParses positional arguments and returns ``(values, args, order)``
        for the parsed options and arguments as well as the leftover
        arguments if there are any.  The order is a list of objects as they
        appear on the command line.  If arguments appear multiple times they
        will be memorized multiple times as well.
        N)	rY_process_args_for_options_process_args_for_argsrr'Zresilient_parsingrGrZrO)rFrrPr
r
r
parse_argss

zOptionParser.parse_argscCsyt|j|jdd|jD\}}x1t|jD] \}}|j|||q?W||_g|_dS)NcSsg|]}|jqSr
)r)rrr
r
rrs	z7OptionParser._process_args_for_args.<locals>.<listcomp>)rrZr[rc	enumeraterQ)rFrPZpargsridxr8r
r
rris	z#OptionParser._process_args_for_argscCsx|jr|jjd}t|}|dkr:dS|dd|jkrr|dkrr|j||q|jr|jj|q|jjd|dSqWdS)Nrz--r)	r[r	rrb
_process_optsr^rZrinsert)rFrPr8Zarglenr
r
rrhs%	z&OptionParser._process_args_for_optionscs&|jkr=fdd|jD}td||j}|jr|dk	rr|jjd||j}t|j|krt|q|dkr|jjd}qt	|jd|}|jd|=n%|dk	rt
dnd}|j||dS)Ncs%g|]}|jr|qSr
)
startswith)rZword)r r
rrBs	z0OptionParser._match_long_opt.<locals>.<listcomp>
possibilitiesrrz%s option does not take a value)rarrJr[rnrrr!r	rrrQ)rFr explicit_valuerPrprerrHr
)r r_match_long_opt@s$
		zOptionParser._match_long_optcCsd}d}|d}g}xK|ddD]9}t|||j}|jj|}	|d7}|	s|jr|j|q-t||	jrI|t|kr|j	j
d||dd}|	j}
t|j	|
krt|
|qO|
dkr|j	j
d}qOt|j	d|
}|j	d|
=nd}|	j|||r-Pq-W|jr|r|jj|dj|dS)NFrrTr")r)r'r`rNr_rrrJrr[rnrr!r	rrQrZjoin)rFr8rPstopir(Zunknown_optionsZchr rerrHr
r
r_match_short_opt`s<

	
		zOptionParser._match_short_optcCsd}d|kr-|jdd\}}n|}t||j}y|j|||WnWtk
r|dd|jkr|j||S|js|jj	|YnXdS)N=rr#)
splitr)r'rrrrbrvr_rZr)rFr8rPrqZlong_optZ
norm_long_optr
r
rrms
	zOptionParser._process_opts)
rRrSrT__doc__rIrfrgrjrirhrrrvrmr
r
r
rr\s	

$ /r\)ryr-collectionsr
exceptionsrrrrrr!r&r)r9objectr:rVrYr\r
r
r
r<module>s"3	0	
Back to Directory File Manager