Dd{J dZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z ejrddlZdd lmZdd lmZdd lmZddlmZej0dZeZdej8edej8edej>ej8ej@eej8ejBedfejDeffdZ#dedej>eeffdZ$dedejBddefdZ%dedejDefdZ&GddZGddZGdd Z'Gd!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. N)deque)gettext)ngettext)BadArgumentUsage)BadOptionUsage) NoSuchOption) UsageError)Argument)Context)Option) ParameterVargs nargs_specreturncTt|}t|}g}ddddtjtffd }|r||}| |dk(r|j ||n~|dkDrKt |Dcgc] }|| }}|j |j t|n.|dkr) tdt||j d|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 `None`. Ncz te.Deque[V]rch |jS|jS#t$rYywxYwN)popleftpop IndexError)rsposs ./usr/lib/python3/dist-packages/click/parser.py_fetchz_unpack_args.._fetchBs6 |yy{"uuw  s%% 11rrzCannot have two nargs < 0) rtOptionalrappendrangereversetuple TypeErrorlenreversedlist)rrrvrnargs_xrs @r _unpack_argsr+1s0 ;Dz"JDFB D-AJJqM z" =  A: IIfTl # QY',U|4!4A4 IIeAh  QY ;<<r7D IIdO- 4 ;4!"TAXZ.14!8: 9d4j  -5s7D%optcf|dd}|jrd|fS|dd|k(r |dd|ddfS||ddfS)Nr)isalnum)r,firsts r split_optr2msT GE }}3w 1Qx52AwAB #ab'>ctxr ch| |j|St|\}}||j|Sr)token_normalize_funcr2)r,r4prefixs r normalize_optr8vs? {c..6 C.KFCXc..s34 55r3stringcddl}|j|d}d|_d|_g} |D]}|j| |S#t$r|j|j Y|SwxYw)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)r9r<lexoutr@s rsplit_arg_stringrC}s| ++fD+ )CCCN C E JJu   J  399 J sA$A,+A,ceZdZ ddddejedej edej ededej ejf d Z e d e fd Z d ejd dd dfdZ y)r Nobj CoreOptionoptsdestactionr(constcg|_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_optssetprefixesr2r?addr$rrHrIr(rJrE) selfrErGrHrIr(rJr,r7values r__init__zOption.__init__s$'E  *C%cNMFE #GuA!NOO MM  fQi (6{aCJ!O  '',&&s+ !!&) * >F    r3rc|jdvS)N)rMr)rI)rSs r takes_valuezOption.takes_values{{111r3rTstate ParsingStatec|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) NrM store_constr append_constcountrrzunknown action '') rIrGrHrJ setdefaultrgetr?orderrE)rSrTrXs rprocesszOption.processs  ;;' !$)EJJtyy ! [[M )$(JJEJJtyy ! [[H $ JJ ! !$))R 0 7 7 > [[N * JJ ! !$))R 0 7 7 C [[G #$)JJNN499a$@1$DEJJtyy !/ }A>? ? 488$r3NrN)__name__ __module__ __qualname__rSequencestrrintAnyrUpropertyboolrWrbr3rr r s #'#' jjojjo   3   zz!%% B2T22 %QUU %> %d %r3r ceZdZd dddejedefdZdejejeejejefddd d fd Z y ) r rE CoreArgumentrHr(c.||_||_||_yr)rHr(rErSrErHr(s rrUzArgument.__init__s  r3rTrXrYrNc|jdkDre|Jtd|D}|t|k(rd}n>|dk7r9tt dj |j |j|jdk(r|jj|dk(rd}||j|j <|jj|jy)Nrc3&K|] }|d yw)Nrrm).0r*s r z#Argument.process..s6aAI6srz'Argument {name!r} takes {nargs} values.namer(rm) r(sumr$rr)formatrHrEenvvarrGrar)rSrTrXholess rrbzArgument.processs ::>$ $$6566EE "!&?@GG!YYdjjH ::  ; E % 499 488$r3r) rdrerfrrrhrirUUnionrgrbrmr3rr r slN!**S/# %wwqzz# 1::c?(CCD%%  %r3r c6eZdZdejeddfdZy)rYrargsrNc<i|_g|_||_g|_yr)rGlargsrra)rSrs rrUzParsingState.__init__s(* "$  .0 r3)rdrerfrListrhrUrmr3rrYrYs1affSk1d1r3rYcpeZdZdZd dej dddfdZ d!ddd ejed ej ed ej ed e d ej ejddfdZ d"ddd ej ed e ddfdZ dejedejejeejfejeejdffdZdeddfdZdeddfdZdedej ededdfdZdededdfdZdedededejfdZdededdfdZy)# 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. Nr4r rc||_d|_d|_|"|j|_|j|_i|_i|_ddh|_g|_y)NTF---)r4allow_interspersed_argsignore_unknown_options _short_opt _long_opt _opt_prefixes_args)rSr4s rrUzOptionParser.__init__ sa .2$ -2# ?+.+F+FD (*-*D*DD '/1.0!4[') r3rErFrGrHrIr(rJc@|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) r8r4r rupdaterQrNrrOr) rSrErGrHrIr(rJr,options r add_optionzOptionParser.add_option#s"9== c488,==T4e5Q !!&//2%% *C#)DOOC  *$$ )C"(DNN3  ) >sBrocR|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)rrr rqs r add_argumentzOptionParser.add_argument<s (3T?@r3r CoreParameterct|} |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. ) rY_process_args_for_options_process_args_for_argsr r4resilient_parsingrGrra)rSrrXs r parse_argszOptionParser.parse_argsFszT"   * *5 1  ' ' .zz5;; 33 xxtxx'A'A(B s"A,BBrXct|j|jz|jDcgc]}|jc}\}}t |jD]\}}|j |||||_g|_ycc}wr)r+rrrr( enumeraterb)rSrXr*pargsridxargs rrz#OptionParser._process_args_for_argsXs{" 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_optsrrrinsert)rSrXrarglens rrz&OptionParser._process_args_for_optionscskk++//!$CXFd{RaD...6A:""3.-- ""3' ""1c*kkr3r,explicit_valuec||jvr1ddlm}|||j}t|||j|j|}|j r2||j jd||j|||}n)|%t|tdj|d}|j||y)Nr)get_close_matches) possibilitiesr4z&Option {name!r} does not take a value.)rw) rdifflibrr r4rWrr_get_value_from_staterr)rzrb)rSr,rrXrrrrTs r_match_long_optzOptionParser._match_long_opts dnn $ 1-c4>>BMs-TXXN N$    ) ""1n5..sFEBE  ' Q?@GGSGQ  Eue$r3rcZd}d}|d}g}|ddD]}t|||j}|jj|} |dz }| s5|jr|j |]t ||j| jrC|t|kr!|jjd||dd}|j|| |} nd} | j| ||sn|jr2|r/|jj |dj|yyy)NFrr)r4Tr.)r8r4rr`rrr rWr$rrrrbrjoin) rSrrXstopir7unknown_optionschr,rrTs r_match_short_optzOptionParser._match_short_opts0 Qab' B6(2$:C__((-F FA..#**2."3DHH55!!s3x<KK&&q#ab'2D223F NN5% (3 >  & &? KK  &"''/*B)CD E,; &r3 option_namerc$|j}t|j|krF|jjrt}|St |t dd|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.rvrr) r(r$rrE_flag_needs_valuerrrz isinstancerhrrr")rSrrrXr(rT 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# r3cLd}d|vr|jdd\}}n|}t||j} |j|||y#t$rP|dd|j vr|j ||Yy|js|jj|YywxYw)N=rr/) splitr8r4rr rrrrr)rSrrXrlong_opt norm_long_opts rrzOptionParser._process_optss #:'*yya'8 $HnH%h9  $   F $2Awd000%%c51.. KK  s # $sA ,B#8(B#"B#rrcr})rdrerf__doc__rrrUrgrhrirjrrrTupleDictrrYrrrrr rrrmr3rrrs *AJJy1*T*:#'#') )jjo)jjo )  3 )  )zz!%% ) )4HIA!A)*CAADA A4FF3K4 QUU #QVVC[!&&2II J4$ L T |H%%() 3%@L% %<&FC&F &F&FP$$(.$7C$ $L$$\$d$r3r))rtypingr collectionsrrr)r exceptionsrrr r TYPE_CHECKINGtyping_extensionstecorer ror r rFrrTypeVarrobjectrrgrhrirr~rrr+r2r8rCrYrrmr3rrsM. (&$"??".*0 AIIcN H9! **S/9!'(zz#9!WWQZZQZZ 3%@$ FG H!&&QT+ UV9!x317738,6s6I!6636SQVVC[D3%3%l%%@11T$T$r3