;iBJdZddlmZddlmZddlZddlm Z ddl m Z ddl m Z ddl mZdd l mZdd lmZdd lmZdd lmZdd lmZejr$ddl mZddl mZddlmZddlmZddlmZddlmZej dZ!d.dZ"d/dZ#d0d"Z$Gd#d$Z%Gd%d&Z&Gd'd(Z'Gd)d*Z(d1d-Z)dS)2a; 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. ) annotationsN)deque)gettext)ngettext)FLAG_NEEDS_VALUEUNSET)BadArgumentUsage)BadOptionUsage) NoSuchOption) UsageError)T_FLAG_NEEDS_VALUE)T_UNSET)Argument)Context)Option) ParameterVargscabc.Sequence[str] nargs_speccabc.Sequence[int]returnGtuple[cabc.Sequence[str | cabc.Sequence[str | None] | None], list[str]]ctt|}g}dd fd |r|}||dkr|n|dkrUfdt|D}||t |n@|d kr:t d t ||t|Љ6t |<gt|dzd|dzd<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 ``UNSET``. Ncdeque[V]r V | T_UNSETc |S|S#t$r tcYSwxYwN)popleftpop IndexErrorr )rsposs @C:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\click/parser.py_fetchz_unpack_args.._fetchDsL |yy{{"uuww   LLL s--AArc&g|] }Sr)).0_r'rs r& z _unpack_args..Vs!444!444rzCannot have two nargs < 0)rrrr) rappendrangereversetuple TypeErrorlenr reversedlist)rrrvnargsxr'r%s` @@r& _unpack_argsr93s ;;Dz""J:r-ctxContext | Nonecn||j|St|\}}|||Sr!)token_normalize_funcrB)r:rCprefixs r&_normalize_optrHxsB {c.6 S//KFC 5c..s33 5 55r-c>eZdZ dddZeddZddZdS)_OptionNrobj CoreOptionoptsrdest str | Noneactionr7intconst t.Any | Nonecg|_g|_t|_|D]}t |\}} |st d|d|j|dt|dkr.t| dkr|j||j||j||d}||_ ||_ ||_ ||_ ||_ dS)Nz$Invalid start character for option ()rrstore) _short_opts _long_optssetprefixesrB ValueErroraddr3r.rNrPr7rRrK) selfrKrMrNrPr7rRr:rGvalues r&__init__z_Option.__init__s"%%%  * *C&sOOMFE P !N!N!N!NOOO M  fQi ( ( (6{{aCJJ!OO '',,,,&&s+++ !!&)))) >F    r-rboolc|jdvS)N)rVr.)rP)r]s r& takes_valuez_Option.takes_values{111r-r^t.Anystate _ParsingStateNonech|jdkr||j|j<n|jdkr|j|j|j<n|jdkr4|j|jg|n|jdkr9|j|jg|jnT|jdkr1|j|jddz|j|j<ntd|jd |j|j dS) NrV store_constr. append_constcountrrzunknown action '') rPrMrNrR setdefaultr.getr[orderrK)r]r^rds r&processz_Option.processs! ;' ! !$)EJty ! ! [M ) )$(JEJty ! ! [H $ $ J ! !$)R 0 0 7 7 > > > > [N * * J ! !$)R 0 0 7 7 C C C C [G # #$)JNN49a$@$@1$DEJty ! !> >>>?? ? 48$$$$$r-NrN) rKrLrMrrNrOrPrOr7rQrRrS)rr`)r^rcrdrerrf)__name__ __module__ __qualname__r_propertyrbror)r-r&rJrJsm ""B222X2 % % % % % %r-rJc eZdZdddZddZdS) _ArgumentrrK CoreArgumentrNrOr7rQc0||_||_||_dSr!)rNr7rKr]rKrNr7s r&r_z_Argument.__init__s  r-r^0str | cabc.Sequence[str | None] | None | T_UNSETrdrerrfc|jdkrt|tjsJt d|D}|t |krt }nA|dkr;ttd |j |j|dkrt }||j |j <|j |jdS)Nrc3,K|]}|tu dVdS)rNr r*r8s r& z$_Argument.process..s&77aAJJJJJJ77r-rz'Argument {name!r} takes {nargs} values.namer7r))r7 isinstancecabcSequencesumr3r r r+formatrNrMrnr.rK)r]r^rdholess r&roz_Argument.processs :>>eT]33 3 3377577777EE ""!&?@@GG!YdjH B;;E % 49 48$$$$$r-Nr)rKrwrNrOr7rQ)r^rzrdrerrf)rqrrrsr_ror)r-r&rvrvsA %%%%%%r-rvceZdZddZdS)rerargs list[str]rrfc>i|_g|_||_g|_dSr!)rMlargsrrn)r]rs r&r_z_ParsingState.__init__s"&( "  *, r-N)rrrrf)rqrrrsr_r)r-r&reres(------r-recneZdZdZd+d,dZ d-d.dZd/d0dZd1dZd2dZd2dZ d3d"Z d4d$Z d5d)Z d4d*Z dS)6 _OptionParserajThe 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. .. deprecated:: 8.2 Will be removed in Click 9.0. NrCrDrrfc||_d|_d|_||j|_|j|_i|_i|_ddh|_g|_dS)NTF---)rCallow_interspersed_argsignore_unknown_options _short_opt _long_opt _opt_prefixes_args)r]rCs r&r_z_OptionParser.__init__s_ .2$ -2# ?+.+FD (*-*DD '.0-/!4[&( r-rrKrLrMrrNrOrPr7rQrRrScfd|D}t||||||}j|j|jD] }|j|< |jD] }|j|< dS)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. c:g|]}t|jSr))rHrC)r*r:r]s r&r,z,_OptionParser.add_option..s%>>>#sDH-->>>r-)rPr7rRN)rJrupdaterZrWrrXr) r]rKrMrNrPr7rRoptionr:s ` r& add_optionz_OptionParser.add_options"?>>>>>>dDuERRR !!&/222% * *C#)DOC $ ) )C"(DN3   ) )r-rwcZ|jt|||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. )rNr7N)rr.rvrys r& add_argumentz_OptionParser.add_arguments/ )Cd%@@@AAAAAr-rr7tuple[dict[str, t.Any], list[str], list[CoreParameter]]ct|} ||||n$#t$r|j |jjsYnwxYw|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. ) re_process_args_for_options_process_args_for_argsrrCresilient_parsingrMrrn)r]rrds r& parse_argsz_OptionParser.parse_args&sd##   * *5 1 1 1  ' ' . . . .   xtx'A  z5; 33s*<AArdrect|j|jzd|jD\}}t |jD]!\}}||||"||_g|_dS)Ncg|] }|j Sr))r7r}s r&r,z8_OptionParser._process_args_for_args..:s'D'D'DA'D'D'Dr-)r9rrr enumeratero)r]rdpargsridxargs r&rz$_OptionParser._process_args_for_args8s" K%+ %'D'D'D'D'D  t"$*-- + +HC KKc E * * * *  r-cb|jr|jd}t|}|dkrdS|dd|jvr|dkr|||n?|jr|j|n|jd|dS|jdSdS)Nrrr) rr#r3r _process_optsrrr.insert)r]rdrarglens r&rz'_OptionParser._process_args_for_optionsCsk +//!$$CXXFd{{RaRD...6A::""3....-  ""3'''' ""1c***k     r-r:r;explicit_valuec||jvr.ddlm}|||j}t|||j|j|}|jr5||jd|||||}n:|1t|td |t}| ||dS)Nr)get_close_matches) possibilitiesrCz&Option {name!r} does not take a value.)r)rdifflibrr rCrbrr_get_value_from_stater r+rr ro)r]r:rrdrrrr^s r&_match_long_optz_OptionParser._match_long_optgs dn $ $ 1 1 1 1 1 1--c4>BBMs-TXNNN N$    ) ""1n555..sFEBBEE  ' Q?@@GGSGQQ  Eue$$$$$r-rcd}d}|d}g}|ddD]}t|||j}|j|} |dz }| s3|jr||Yt ||j| jrP|t|kr%|j d||dd}| || |} nt} | | ||rn|jr5|r5|j|d|dSdSdS)NFrr)rCTr>)rHrCrrmrr.r rbr3rrrr rorjoin) r]rrdstopirGunknown_optionschr:rr^s r&_match_short_optz_OptionParser._match_short_opts Qabb'  B FB$(;;C_((--F FA 6.#**2..."3DH5555! s3xx<<K&&q#abb'222D223FF NN5% ( ( (    & F? F K  &D"''/*B*BDD E E E E E F F F Fr- option_namerrJ-str | cabc.Sequence[str] | T_FLAG_NEEDS_VALUEc|j}t|j|krH|jjrt }nt |tdd||||dkru|jd}|jjrAt|tr,|dd|j vrt|dkrt }nA|j d}n&t|jd|}|jd|=|S)Nz%Option {name!r} requires an argument.z+Option {name!r} requires {nargs} arguments.rrr)r7r3rrK_flag_needs_valuerr rrrr;rr#r1)r]rrrdr7r^ next_rargs r&rz#_OptionParser._get_value_from_states  u{  e # #z+ ($?Ef+Uf;; aZZ AI , +y#.. +bqbMT%777 NNQ&&) **%+fuf-..E FUF# r-c^d}d|vr|dd\}}n|}t||j} ||||dS#t$rP|dd|jvr|||YdS|js|j |YdSwxYw)N=rr?) splitrHrCrr rrrrr.)r]rrdrlong_opt norm_long_opts r&rz_OptionParser._process_optss #::'*yya'8'8 $HnnH&x::  $   F F F F F $ $ $2A2wd000%%c5111.  K  s # # # # # # $sA1B,"B,+B,r!)rCrDrrfrp)rKrLrMrrNrOrPrOr7rQrRrSrrfr)rKrwrNrOr7rQrrf)rrrr)rdrerrf)r:r;rrOrdrerrf)rr;rdrerrf)rr;rrJrdrerr)rqrrrs__doc__r_rrrrrrrrrr)r-r&rrs  ))))):"")))))2BBBBB4444$    H%%%%<&F&F&F&FP&&&&P$$$$$$r-rrobjectcddl}|dvr8|d|dtdtd|S|dkr%d d lm}|d td|St |) Nr>rr split_opt OptionParser ParsingState normalize_optz'parser.z\' is deprecated and will be removed in Click 9.0. The old parser is available in 'optparse'.r?) stacklevelr+split_arg_stringr)rzpImporting 'parser.split_arg_string' is deprecated, it will only be available in 'shell_completion' in Click 9.0.)warningswarnDeprecationWarningglobalsshell_completionrAttributeError)rrrs r& __getattr__rsOOO    :t : : :     yyT$$ !!!666666  =         r-)rrrrrr)r:r;rr<)r:r;rCrDrr;)rr;rr)*r __future__rcollections.abcabcrtypingt collectionsrrr+r_utilsrr exceptionsr r r r TYPE_CHECKINGrrcorerrwrrrLr CoreParameterTypeVarrr9rBrHrJrvrerrr)r-r&rsm0#""""" $$$$$$((((((&&&&&&$$$$$$""""""?1******......******000000 AIcNN9!9!9!9!x66663%3%3%3%3%3%3%3%l%%%%%%%%>--------W$W$W$W$W$W$W$W$tr-