a cdJ @s~dZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z ej rddlZdd lmZdd lmZdd lmZddlmZedZeZejeejeejejej eejej!edfej"efdddZ#eejeefdddZ$eej!dedddZ%eej"edddZ&GdddZGdd d ZGd!d"d"Z'Gd#d$d$Z(dS)%a; 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. Click uses parts of optparse written by Gregory P. Ward and maintained by the Python Software Foundation. This is limited to code in parser.py. Copyright 2001-2006 Gregory P. Ward. All rights reserved. Copyright 2002-2006 Python Software Foundation. All rights reserved. N)deque)gettext)ngettext)BadArgumentUsage)BadOptionUsage) NoSuchOption) UsageError)Argument)Context)Option) ParameterV)args nargs_specreturncstt|}g}ddtjtdfdd |r̈|}|durHq2|dkr`|q2|dkrfddt|D}dur||t|q2|d kr2durtd t ||dq2durt|<gt |dd|dd<t|t fS) 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`. Nz te.Deque[V])crcs:z dur|WS|WSWnty4YdS0dSN)popleftpop IndexError)r)sposY/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/click/parser.py_fetchBs   z_unpack_args.._fetchrcsg|] }qSrr).0_)rrrr Tz _unpack_args..rzCannot have two nargs < 0) rtOptionalrappendrangereversetuple TypeErrorlenreversedlist)rrrvnargsxr)rrrr _unpack_args1s4      r,)optrcCsT|dd}|rd|fS|dd|krD|dd|ddfS||ddfS)Nr)isalnum)r-firstrrr split_optms  r2r )r-ctxrcCs4|dus|jdur|St|\}}|||Sr)Ztoken_normalize_funcr2)r-r3prefixrrr normalize_optvs r5)stringrcCsbddl}|j|dd}d|_d|_g}z|D]}||q,Wnty\||jYn0|S)aSplit an argument string as with :func:`shlex.split`, but don't fail if the string is incomplete. Ignores a missing closing quote or incomplete escape sequence and uses the partial token as-is. .. code-block:: python split_arg_string("example 'my file") ["example", "my file"] split_arg_string("example my\") ["example", "my"] :param string: String to split. rNT)posixr.)shlexwhitespace_split commentersr! ValueErrortoken)r6r8lexoutr<rrrsplit_arg_string}s r?c@sdeZdZddejeejeejeeejejdddZ e e ddd Z ed dd d d Z dS)r Nr CoreOption)objoptsdestactionr*constc Csg|_g|_t|_|D]r}t|\}} |srz#Argument.process..rz'Argument {name!r} takes {nargs} values.namer*r) r*sumr&rrformatrCrAZenvvarrBr[r!)rMrNrTZholesrrrr\s    zArgument.process)r) r]r^r_rr rarbrOUnionr`r\rrrrr s r c@s"eZdZejeddddZdS)rRN)rargsrcCsi|_g|_||_g|_dSr)rBlargsrpr[)rMrprrrrOszParsingState.__init__)r]r^r_rListrarOrrrrrRsrRc @s(eZdZdZd$ejdddddZd%dejeejeejee ejej dd d d Z d&d ejee dd ddZ ej eejejeej fej eej dfdddZeddddZeddddZeejeeddddZeeddddZeeeej dd d!Zeeddd"d#ZdS)' 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. Nr )r3rcCsJ||_d|_d|_|dur*|j|_|j|_i|_i|_ddh|_g|_dS)NTF---)r3allow_interspersed_argsignore_unknown_options _short_opt _long_opt _opt_prefixes_args)rMr3rrrrO s zOptionParser.__init__rr@)rArBrCrDr*rErc sdfdd|D}t||||||d}j|j|jD]}|j|<q:|jD]}|j|<qPdS)azAdds 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``, ``append_const`` or ``count``. The `obj` can be used to identify the option in the order list that is returned from the parser. csg|]}t|jqSr)r5r3)rr-rPrrr4rz+OptionParser.add_option..)rDr*rEN)r rzupdaterKrHrxrIry) rMrArBrCrDr*rEoptionr-rrPr add_option#s   zOptionParser.add_optionrf)rArCr*rcCs|jt|||ddS)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. )rCr*N)r{r!r rgrrr add_argument<szOptionParser.add_argument CoreParameter)rrcCsXt|}z||||Wn&tyF|jdus@|jjsBYn0|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) rR_process_args_for_options_process_args_for_argsr r3Zresilient_parsingrBrqr[)rMrrTrrr parse_argsFs   zOptionParser.parse_args)rTrcCsVt|j|jdd|jD\}}t|jD]\}}||||q,||_g|_dS)NcSsg|] }|jqSr)r*rhrrrrZrz7OptionParser._process_args_for_args..)r,rqrpr{ enumerater\)rMrTZpargsridxargrrrrXsz#OptionParser._process_args_for_argscCsz|jrv|jd}t|}|dkr&dS|dd|jvrN|dkrN|||q|jrb|j|q|jd|dSqdS)Nrrur) rprr&rz _process_optsrvrqr!insert)rMrTrZarglenrrrrcs z&OptionParser._process_args_for_options)r-explicit_valuerTrcCs||jvr2ddlm}|||j}t|||jd|j|}|jrh|durX|jd|||||}n$|durt |t dj |dnd}| ||dS)Nr)get_close_matches) possibilitiesr3z&Option {name!r} does not take a value.)rk) rydifflibrrr3rQrpr_get_value_from_staterrrnr\)rMr-rrTrrr}rNrrr_match_long_opts    zOptionParser._match_long_opt)rrTrc Csd}d}|d}g}|ddD]}t|||j}|j|} |d7}| sp|jrb||q t||jd| jr|t|kr|j d||dd}| || |} nd} | | ||r qq |jr|r|j |d|dS)NFrr)r3Tr.)r5r3rxrZrwr!rrQr&rprrr\rqjoin) rMrrTstopir4Zunknown_optionschr-r}rNrrr_match_short_opts0     zOptionParser._match_short_opt) option_namer}rTrcCs|j}t|j|kr@|jjr"t}qt|tdd|j||dnt|dkr|jd}|jjrt|t r|dd|j vrt|dkrt}q|j d}nt |jd|}|jd|=|S)Nz%Option {name!r} requires an argument.z+Option {name!r} requires {nargs} arguments.rjrr) r*r&rprA_flag_needs_valuerrrn isinstancerarzrr$)rMrr}rTr*rNZ next_rargrrrrs:   z"OptionParser._get_value_from_statecCsd}d|vr|dd\}}n|}t||j}z||||WnJty|dd|jvrr|||YdS|jsz|j |Yn0dS)N=rr/) splitr5r3rrrzrrwrqr!)rMrrTrZlong_optZ norm_long_optrrrrs   zOptionParser._process_opts)N)NrN)r)r]r^r___doc__rr rOr`rarbrcr~rrrTupleDictrrRrrrrr rrrrrrrss@     &  %  ) &rs))rtypingr collectionsrrrr exceptionsrrrr TYPE_CHECKINGZtyping_extensionstecorer rfr r r@r rTypeVarrobjectrr`rarbrror rrr,r2r5r?rRrsrrrrs4            0 < "6