L iBJdZddlmZddlmZddlZddlm Z ddl m Z ddl m Z ddl mZdd l mZdd lmZdd lmZdd lmZdd lmZej*r$ddl mZddl mZddlmZddlmZddlmZddlmZej@dZ! d!dZ"d"dZ#d#dZ$GddZ%GddZ&GddZ'GddZ(d$d Z)y)%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. ) annotationsN)deque)gettext)ngettext)FLAG_NEEDS_VALUEUNSET)BadArgumentUsage)BadOptionUsage) NoSuchOption) UsageError)T_FLAG_NEEDS_VALUE)T_UNSET)Argument)Context)Option) ParameterVc*t|}t|}g}ddfd }|r||}| |dk(r|j||n|dkDrKt|Dcgc] }|| }}|j|jt |n2|dkr- t dt ||jt|r't ||<g}t|dzd|dzdt |t|fScc}w)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``. Nct |jS|jS#t$r tcYSwxYwN)popleftpop IndexErrorr )csposs R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/click/parser.py_fetchz_unpack_args.._fetchDs8 |yy{"uuw L s%%77rrzCannot have two nargs < 0)rzdeque[V]returnz V | T_UNSET) rappendrangereversetuple TypeErrorlenr reversedlist)args nargs_specrvrnargs_xrs @r _unpack_argsr/3s ;Dz"J:ch| |j|St|\}}||j|Sr)token_normalize_funcr6)r4ctxprefixs r_normalize_optr<xs? {c..6 S/KFCXc..s34 55r7cLeZdZ d ddZeddZddZy) _OptionNcg|_g|_t|_|D]}t |\}} |st d|d|jj |dt|dk(r*t| dk(r|jj|x|jj||jj ||d}||_ ||_ ||_ ||_ ||_ y)Nz$Invalid start character for option ()rrstore) _short_opts _long_optssetprefixesr6 ValueErroraddr&r!destactionr,constobj) selfrKoptsrHrIr,rJr4r;values r__init__z_Option.__init__s"%%  *C&sOMFE #GuA!NOO MM  fQi (6{aCJ!O  '',&&s+ !!&) * >F    r7c|jdvS)N)rAr!)rI)rLs r takes_valuez_Option.takes_values{{111r7c|jdk(r||j|j<n0|jdk(r$|j|j|j<n|jdk(r6|jj |jgj |n|jdk(r@|jj |jgj |jni|jdk(rA|jj |jddz|j|j<ntd|jd |jj |jy) NrA store_constr! append_constcountrrzunknown action '') rIrMrHrJ setdefaultr!getrForderrK)rLrNstates rprocessz_Option.processs  ;;' !$)EJJtyy ! [[M )$(JJEJJtyy ! [[H $ JJ ! !$))R 0 7 7 > [[N * JJ ! !$))R 0 7 7 C [[G #$)JJNN499a$@1$DEJJtyy !/ }A>? ? 488$r7NrN) rK CoreOptionrMcabc.Sequence[str]rH str | NonerIr_r,intrJ t.Any | None)r bool)rNzt.AnyrZ _ParsingStater None)__name__ __module__ __qualname__rOpropertyrQr[r7rr>r>sf "" !     B22 %r7r>c*eZdZdddZ ddZy) _Argumentc.||_||_||_yr)rHr,rKrLrKrHr,s rrOz_Argument.__init__s  r7c|jdkDrt|tjsJt d|D}|t |k(rt }n>|dk7r9ttdj|j|j|dk(rt }||j|j<|jj|jy)Nrc32K|]}|tus dyw)rNr ).0r.s r z$_Argument.process..s7aAJ7s rz'Argument {name!r} takes {nargs} values.namer,ri)r, isinstancecabcSequencesumr&r r r-formatrHrMrYr!rK)rLrNrZholess rr[z_Argument.processs ::>eT]]3 337577EE "!&?@GG!YYdjjH B;E % 499 488$r7Nr)rK CoreArgumentrHr_r,r`)rNz0str | cabc.Sequence[str | None] | None | T_UNSETrZrcr rd)rerfrgrOr[rir7rrkrks( %?%%  %r7rkceZdZddZy)rcc<i|_g|_||_g|_yr)rMlargsrargsrY)rLrs rrOz_ParsingState.__init__s&( "  *, r7N)r list[str]r rd)rerfrgrOrir7rrcrcs-r7rcceZdZdZd ddZ d ddZdddZ ddZddZddZ dd Z dd Z dd Z dd Z y) _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. Nc||_d|_d|_|"|j|_|j|_i|_i|_ddh|_g|_y)NTF---)r:allow_interspersed_argsignore_unknown_options _short_opt _long_opt _opt_prefixes_args)rLr:s rrOz_OptionParser.__init__sa .2$ -2# ?+.+F+FD (*-*D*DD '.0-/!4[&( r7c@|Dcgc]}t||j}}t||||||}|jj |j |j D]}||j|<|jD]}||j|<ycc}w)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. )rIr,rJN) r<r:r>rupdaterErBrrCr) rLrKrMrHrIr,rJr4options r add_optionz_OptionParser.add_options":>>#sDHH->>dDuER !!&//2%% *C#)DOOC  *$$ )C"(DNN3  ) ?sBcR|jjt|||y)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. )rHr,N)rr!rkrms r add_argumentz_OptionParser.add_arguments )Cd%@Ar7ct|} |j||j||j |j|jfS#t$r&|j|jj sYQwxYw)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. ) rc_process_args_for_options_process_args_for_argsrr:resilient_parsingrMr~rY)rLr)rZs r parse_argsz_OptionParser.parse_args&szd#   * *5 1  ' ' .zz5;; 33 xxtxx'A'A(B s"A,BBct|j|jz|jDcgc]}|jc}\}}t |jD]\}}|j |||||_g|_ycc}wr)r/r~rrr, enumerater[)rLrZr.pargsr)idxargs rrz$_OptionParser._process_args_for_args8s{" KK%++ %'DA'D t"$**- +HC KKc E * +  (EsB cl|jr|jjd}t|}|dk(ry|dd|jvr|dkDr|j ||nE|j r|j j|n|jjd|y|jryy)Nrrr) rrr&r _process_optsrr~r!insert)rLrZrarglens rrz'_OptionParser._process_args_for_optionsCskk++//!$CXFd{RaD...6A:""3.-- ""3' ""1c*kkr7c||jvr1ddlm}|||j}t|||j|j|}|j r2||j jd||j|||}n-|%t|tdj|t}|j||y)Nr)get_close_matches) possibilitiesr:z&Option {name!r} does not take a value.)rs)rdifflibrr r:rQrr_get_value_from_stater r-rxr r[)rLr4explicit_valuerZrrrrNs r_match_long_optz_OptionParser._match_long_optgs dnn $ 1-c4>>BMs-TXXN N$    ) ""1n5..sFEBE  ' Q?@GGSGQ  Eue$r7cbd}d}|d}g}|ddD]}t|||j}|jj|} |dz }| s5|jr|j |]t ||j| jrC|t|kr!|jjd||dd}|j|| |} nt} | j| ||sn|jr2|r/|jj |dj|yyy)NFrr)r:Tr1)r<r:rrXrr!r rQr&rrrr r[r~join) rLrrZstopir;unknown_optionschr4rrNs r_match_short_optz_OptionParser._match_short_opts0 Qab' B F8B4$((;C__((-F FA..#**2."3DHH55!!s3x<KK&&q#ab'2D223F NN5% (3 >  & &? KK  &"''/*B)CD E,; &r7c$|j}t|j|krF|jjrt }|St |tdd|j|||dk(ry|jd}|jjr7t|tr'|dd|jvrt|dkDrt }|S|jjd}|St|jd|}|jd|=|S)Nz%Option {name!r} requires an argument.z+Option {name!r} requires {nargs} arguments.rrrr)r,r&rrK_flag_needs_valuerr rrxrtstrrrr$)rL option_namerrZr,rN next_rargs rrz#_OptionParser._get_value_from_states  u{{ e #zz++(8 5%?Ef+Uf; aZ AI ,,y#.bqMT%7%77 NQ&)  *  %++fu-.E FUF# r7cLd}d|vr|jdd\}}n|}t||j} |j|||y#t$rP|dd|j vr|j ||Yy|js|jj|YywxYw)N=rr2) splitr<r:rr rrrr~r!)rLrrZrlong_opt norm_long_opts rrz_OptionParser._process_optss #:'*yya'8 $HnH&x:  $   F $2Awd000%%c51.. KK  s # $sA ,B#8(B#"B#r)r:Context | Noner rdr\)rKr]rMr^rHr_rIr_r,r`rJrar rdrz)rKr{rHr_r,r`r rd)r)rr z7tuple[dict[str, t.Any], list[str], list[CoreParameter]])rZrcr rd)r4rrr_rZrcr rd)rrrZrcr rd)rrrr>rZrcr z-str | cabc.Sequence[str] | T_FLAG_NEEDS_VALUE)rerfrg__doc__rOrrrrrrrrrrir7rrrs ):"") )!) )  )  )) )2B44 @4$ H%%(2%;H% %<&FP&&(/&8E& 6&P$r7rcddl}|dvr,|jd|dtdtd|S|dk(r d d lm}|jd 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'.r2) 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)rsrrs r __getattr__rs   tf: :   y1TF$$ !!6  =      r7)r)r^r*zcabc.Sequence[int]r zGtuple[cabc.Sequence[str | cabc.Sequence[str | None] | None], list[str]])r4rr ztuple[str, str])r4rr:rr r)rsrr object)*r __future__rcollections.abcabcrutypingt collectionsrrr-r_utilsrr exceptionsr r r r TYPE_CHECKINGrrcorerr{rrr]r CoreParameterTypeVarrr/r6r<r>rkrcrrrir7rrs0# $(&$"??*.*0 AIIcN9! 9!*<9!L9!x63%3%l%%>--W$W$tr7