zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
U
ß=®d{Jã    @s~dZddlZddlmZddlmZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z ej ržddlZdd lmZdd lmZdd lmZddlmZe d¡ZeƒZejeejeejejej eejej!edfej"efdœdd„Z#eejeefdœdd„Z$eej!dedœdd„Z%eej"edœdd„Z&Gdd„dƒZGdd „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)Ú    ParameterÚV)ÚargsÚ
nargs_specÚreturncstˆƒ‰t|ƒ}g}d‰dtjtdœ‡fdd„ ‰|r̈|ƒ}|dkrHq2|dkr`| ˆˆƒ¡q2|dkr ‡‡fdd„t|ƒDƒ}ˆdk    r| ¡| t|ƒ¡q2|d    kr2ˆdk    r¸td
ƒ‚t    |ƒ‰| d¡q2ˆdk    rtˆƒ|ˆ<g‰t
|ˆdd…ƒ|ˆdd…<t|ƒt ˆƒfS) aGiven 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 ˆdkr| ¡WS| ¡WSWntk
r6YdSXdS©N)ÚpopleftÚpopÚ
IndexError)r)Úspos©úCd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\click/parser.pyÚ_fetchBs 
z_unpack_args.<locals>._fetchrcsg|] }ˆˆƒ‘qSrr)Ú.0Ú_)rrrrÚ
<listcomp>Tsz _unpack_args.<locals>.<listcomp>rzCannot have two nargs < 0) rÚtÚOptionalrÚappendÚrangeÚreverseÚtupleÚ    TypeErrorÚlenÚreversedÚlist)rrÚrvÚnargsÚxr)rrrrÚ _unpack_args1s4      
  r+)ÚoptrcCsT|dd…}| ¡rd|fS|dd…|krD|dd…|dd…fS||dd…fS)NrÚé)Úisalnum)r,ÚfirstrrrÚ    split_optms  r1r )r,ÚctxrcCs4|dks|jdkr|St|ƒ\}}|›| |¡›Sr)Ztoken_normalize_funcr1)r,r2ÚprefixrrrÚ normalize_optvs r4)ÚstringrcCsdddl}|j|dd}d|_d|_g}z|D]}| |¡q,Wn tk
r^| |j¡YnX|S)aŸSplit 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-)ÚshlexÚwhitespace_splitÚ
commentersr Ú
ValueErrorÚtoken)r5r7ÚlexÚoutr;rrrÚsplit_arg_string}sr>c@sfeZdZddejeejeejeeejejdœdd„Z    e
e dœdd    „ƒZ ejd
dd œd d „Z dS)r NrÚ
CoreOption)ÚobjÚoptsÚdestÚactionr)Úconstc
Csºg|_g|_tƒ|_|D]r}t|ƒ\}}    |s<td|›dƒ‚|j |d¡t|ƒdkrrt|    ƒdkrr|j |¡q|j |¡|j |¡q|dkr˜d}||_    ||_
||_ ||_ ||_ dS)Nz$Invalid start character for option (ú)rrÚstore)Ú _short_optsÚ
_long_optsÚsetÚprefixesr1r:Úaddr%r rBrCr)rDr@)
Úselfr@rArBrCr)rDr,r3ÚvaluerrrÚ__init__ s&      zOption.__init__)rcCs
|jdkS)N)rFr )rC©rLrrrÚ takes_valueÁszOption.takes_valueÚ ParsingState©rMÚstatercCsÄ|jdkr||j|j<nš|jdkr2|j|j|j<n€|jdkrT|j |jg¡ |¡n^|jdkrx|j |jg¡ |j¡n:|jdkr |j |jd¡d|j|j<ntd|j›d    ƒ‚|j |j    ¡dS)
NrFÚ store_constr Ú append_constÚcountrrzunknown action 'ú')
rCrArBrDÚ
setdefaultr Úgetr:Úorderr@)rLrMrSrrrÚprocessÅs
 
 
 
 
zOption.process)NrN)Ú__name__Ú
__module__Ú __qualname__rÚSequenceÚstrrÚintÚAnyrNÚpropertyÚboolrPr[rrrrr Ÿsù
ù !r c@sTeZdZd dejeedœdd„Zejejeej    ejefdddœd    d
„Z
dS) r
rÚ CoreArgument)r@rBr)cCs||_||_||_dSr)rBr)r@©rLr@rBr)rrrrNÖszArgument.__init__rQNrRcCsœ|jdkr\|dk    st‚tdd„|Dƒƒ}|t|ƒkr:d}n"|dkr\ttdƒj|j|jdƒ‚|jdkr~|jj    dk    r~|dkr~d}||j
|j<|j   |j¡dS)    Nrcss|]}|dkrdVqdS)Nrr©rr*rrrÚ    <genexpr>âsz#Argument.process.<locals>.<genexpr>rz'Argument {name!r} takes {nargs} values.©Únamer)éÿÿÿÿr) r)ÚAssertionErrorÚsumr%rrÚformatrBr@ZenvvarrArZr )rLrMrSZholesrrrr[Ûs 
  ÿÿ zArgument.process)r) r\r]r^rrr`rarNÚUnionr_r[rrrrr
Õs
ür
c@s"eZdZejeddœdd„ZdS)rQN)ÚrargsrcCsi|_g|_||_g|_dSr)rAÚlargsrprZ)rLrprrrrNöszParsingState.__init__)r\r]r^rÚListr`rNrrrrrQõsrQc    @s(eZdZdZd$ejdddœdd„Zd%dejeejeejee    ejej
dd    œd
d „Z d&d ejee    dd œdd„Z ej eejejeej
fej eej dfdœdd„Zeddœdd„Zeddœdd„Zeejeeddœdd„Zeeddœdd„Zeeeej
dœd d!„Zeeddœd"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 )r2rcCsJ||_d|_d|_|dk    r*|j|_|j|_i|_i|_ddh|_g|_dS)NTFú-ú--)r2Úallow_interspersed_argsÚignore_unknown_optionsÚ
_short_optÚ    _long_optÚ _opt_prefixesÚ_args)rLr2rrrrN s
zOptionParser.__init__rr?)r@rArBrCr)rDrc    sd‡fdd„|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|ˆjƒ‘qSr)r4r2)rr,rOrrr4sz+OptionParser.add_option.<locals>.<listcomp>)rCr)rDN)r rzÚupdaterJrGrxrHry)    rLr@rArBrCr)rDÚoptionr,rrOrÚ
add_option#s
 
zOptionParser.add_optionre)r@rBr)rcCs|j t|||d¡dS)z±Adds 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.
        )rBr)N)r{r r
rfrrrÚ add_argument<szOptionParser.add_argumentÚ CoreParameter)rrcCsZt|ƒ}z| |¡| |¡Wn(tk
rH|jdksB|jjsD‚YnX|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)    rQÚ_process_args_for_optionsÚ_process_args_for_argsr    r2Zresilient_parsingrArqrZ)rLrrSrrrÚ
parse_argsFs    
zOptionParser.parse_args)rSrcCsVt|j|jdd„|jDƒƒ\}}t|jƒD]\}}| |||¡q,||_g|_dS)NcSsg|]
}|j‘qSr)r)rgrrrrZsz7OptionParser._process_args_for_args.<locals>.<listcomp>)r+rqrpr{Ú    enumerater[)rLrSZpargsrÚidxÚargrrrr‚Xs
ÿz#OptionParser._process_args_for_argscCsz|jrv|j d¡}t|ƒ}|dkr&dS|dd…|jkrN|dkrN| ||¡q|jrb|j |¡q|j d|¡dSqdS)Nrrur)    rprr%rzÚ _process_optsrvrqr Úinsert)rLrSr†Zarglenrrrrcs z&OptionParser._process_args_for_options)r,Úexplicit_valuerSrcCsœ||jkr2ddlm}|||jƒ}t|||jd‚|j|}|jrh|dk    rX|j d|¡| |||¡}n$|dk    rˆt    |t
dƒj |dƒ‚nd}|  ||¡dS)Nr)Úget_close_matches)Ú possibilitiesr2z&Option {name!r} does not take a value.)rj) ryÚdifflibrŠrr2rPrprˆÚ_get_value_from_staterrrnr[)rLr,r‰rSrŠr‹r}rMrrrÚ_match_long_opt‡s 
 
ÿzOptionParser._match_long_opt)r†rSrc Csîd}d}|d}g}|dd…D]¤}t|›|›|jƒ}|j |¡}    |d7}|    sp|jrb| |¡q t||jd‚|    jr¬|t|ƒkrœ|j     
d||d…¡d}|  ||    |¡}
nd}
|      |
|¡|r qÆq |jrê|rê|j  |›d |¡›¡dS)NFrr)r2Tr-)r4r2rxrYrwr rrPr%rprˆrr[rqÚjoin) rLr†rSÚstopÚir3Zunknown_optionsÚchr,r}rMrrrÚ_match_short_opt¥s0 
 
zOptionParser._match_short_opt)Ú option_namer}rSrcCs¸|j}t|jƒ|kr@|jjr"t}q´t|tdd|ƒj||dƒ‚nt|dkr–|jd}|jjrˆt|t    ƒrˆ|dd…|j
krˆt|ƒdkrˆt}q´|j  d¡}nt |jd|…ƒ}|jd|…=|S)Nz%Option {name!r} requires an argument.z+Option {name!r} requires {nargs} arguments.rirr) r)r%rpr@Ú_flag_needs_valuerrrnÚ
isinstancer`rzrr#)rLr”r}rSr)rMZ    next_rargrrrrÍs<ýüþ
ÿþý
ü z"OptionParser._get_value_from_statecCs’d}d|kr| dd¡\}}n|}t||jƒ}z| |||¡WnLtk
rŒ|dd…|jkrt| ||¡YdS|js|‚|j     |¡YnXdS)Nú=rr.)
Úsplitr4r2rŽrrzr“rwrqr )rLr†rSr‰Zlong_optZ norm_long_optrrrr‡ós  zOptionParser._process_opts)N)NrN)r)r\r]r^Ú__doc__rrrNr_r`rarbr~rrrÚTupleÚDictrƒrQr‚rrŽr“r rr‡rrrrrsýsL ù
ø ÿþ &þ  %þ )þ &rs))r™ÚtypingrÚ collectionsrrrrÚ
exceptionsrrrr    Ú TYPE_CHECKINGZtyping_extensionsÚteÚcorer
rer r r?r r€ÚTypeVarrÚobjectr•r_r`raršrorrrr+r1r4r>rQrsrrrrÚ<module>s6           
0þ <    "6