o �J�h#J�@s"dZddlmZddlmZddlZddlm Z ddl m Z ddl m Z ddl mZdd l mZdd l mZdd l mZejrWdd lmZdd lmZddlmZddlmZe�d�Ze�Zd.dd�Zd/dd�Z d0d d!�Z!Gd"d#�d#�Z"Gd$d%�d%�Z#Gd&d'�d'�Z$Gd(d)�d)�Z%d1d,d-�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�)�BadArgumentUsage)�BadOptionUsage)� NoSuchOption)� UsageError)�Argument)�Context)�Option)� Parameter�V�args�cabc.Sequence[str]� nargs_spec�cabc.Sequence[int]�return�Gtuple[cabc.Sequence[str | cabc.Sequence[str | None] | None], list[str]]cs t���t|�}g}d�d �fdd� �|ra�|�}|durq|dkr*|�����n5|dkrJ��fd d �t|�D�}�durB|��|�t|��n|d kr_�durVtd ��t|��|�d�|s�dur}t��|�<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`. N�c�deque[V]r�V | Nonecs2z�dur |��WS|��WStyYdSw�N)�popleft�pop� IndexError)r)�spos��JC:\pinokio\api\whisper-webui.git\app\env\lib\site-packages\click\parser.py�_fetchEs   �z_unpack_args.<locals>._fetchrcsg|]}����qSrr)�.0�_)r rrr� <listcomp>Wsz _unpack_args.<locals>.<listcomp>rzCannot have two nargs < 0)rrrr) r�append�range�reverse�tuple� TypeError�len�reversed�list)rr�rv�nargs�xr)r rrr� _unpack_args4s6   �  r/�opt�str�tuple[str, str]cCsT|dd�}|��rd|fS|dd�|kr"|dd�|dd�fS||dd�fS)Nr��)�isalnum)r0�firstrrr� _split_optps r7�ctx�Context | NonecCs4|dus |jdur |St|�\}}|�|�|���Sr)�token_normalize_funcr7)r0r8�prefixrrr�_normalize_optys r<c@s6eZdZ   dddd�Zeddd��Zddd�ZdS)�_OptionNr�obj� CoreOption�optsr�dest� str | None�actionr-�int�const� t.Any | Nonec Cs�g|_g|_t�|_|D]9}t|�\}} |std|�d���|j�|d�t|�dkr9t| �dkr9|j�|�q |j�|�|j�|�q |durLd}||_ ||_ ||_ ||_ ||_ dS)Nz$Invalid start character for option (�)rr�store)� _short_opts� _long_opts�set�prefixesr7� ValueError�addr)r$rArCr-rEr>) �selfr>r@rArCr-rEr0r;�valuerrr�__init__�s&    z_Option.__init__r�boolcCs |jdvS)N)rHr$)rC�rOrrr� takes_value�s z_Option.takes_valuerP�t.Any�state� _ParsingState�NonecCs�|jdkr ||j|j<nM|jdkr|j|j|j<n@|jdkr*|j�|jg��|�n/|jdkr<|j�|jg��|j�n|jdkrP|j�|jd�d|j|j<n td|j�d ���|j�|j �dS) NrH� store_constr$� append_const�countrrzunknown action '�') rCr@rArE� setdefaultr$�getrM�orderr>)rOrPrVrrr�process�s     z_Option.process�NrN) r>r?r@rrArBrCrBr-rDrErF)rrR)rPrUrVrWrrX)�__name__� __module__� __qualname__rQ�propertyrTr`rrrrr=�s �! r=c@s"eZdZdddd �Zddd�ZdS)� _Argumentrr>� CoreArgumentrArBr-rDcCs||_||_||_dSr)rAr-r>�rOr>rAr-rrrrQ�s z_Argument.__init__rP�&str | cabc.Sequence[str | None] | NonerVrWrrXcCs�|jdkr.|dus J�tdd�|D��}|t|�krd}n|dkr.ttd�j|j|jd���|jdkr?|jjdur?|dkr?d}||j |j<|j � |j�dS) Nrcss�|] }|durdVqdS)Nrr�r!r.rrr� <genexpr>�s�z$_Argument.process.<locals>.<genexpr>rz'Argument {name!r} takes {nargs} values.��namer-�����r) r-�sumr)rr"�formatrAr>�envvarr@r_r$)rOrPrVZholesrrrr`�s   �� z_Argument.processN�r)r>rgrArBr-rD)rPrirVrWrrX)rbrcrdrQr`rrrrrf�s rfc@seZdZddd�ZdS) rW�rargs� list[str]rrXcCsi|_g|_||_g|_dSr)r@�largsrsr_)rOrsrrrrQ�s z_ParsingState.__init__N)rsrtrrX)rbrcrdrQrrrrrW�srWc@s�eZdZdZd5d6dd�Z  d7d8dd�Zd9d:dd�Zd;dd�Zd<d!d"�Zd<d#d$�Z d=d(d)�Z d>d+d,�Z d?d1d2�Z d>d3d4�Z dS)@� _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. Nr8r9rrXcCsJ||_d|_d|_|dur|j|_|j|_i|_i|_ddh|_g|_dS)NTF�-�--)r8�allow_interspersed_args�ignore_unknown_options� _short_opt� _long_opt� _opt_prefixes�_args)rOr8rrrrQ�s  z_OptionParser.__init__rr>r?r@rrArBrCr-rDrErFc sd�fdd�|D�}t||||||d�}�j�|j�|jD]}|�j|<q|jD]}|�j|<q(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. csg|]}t|�j��qSr)r<r8)r!r0rSrrr#sz,_OptionParser.add_option.<locals>.<listcomp>)rCr-rEN)r=r}�updaterLrIr{rJr|) rOr>r@rArCr-rE�optionr0rrSr� add_options    �z_OptionParser.add_optionrgcCs|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. )rAr-N)r~r$rfrhrrr� add_argument sz_OptionParser.add_argumentrrt�7tuple[dict[str, t.Any], list[str], list[CoreParameter]]cCsXt|�}z |�|�|�|�Wnty#|jdus |jjs!�Ynw|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) rW�_process_args_for_options�_process_args_for_argsr r8�resilient_parsingr@rur_)rOrrVrrr� parse_args(s   ��z_OptionParser.parse_argsrVrWcCsVt|j|jdd�|jD��\}}t|j�D] \}}|�|||�q||_g|_dS)NcSsg|]}|j�qSr)r-rjrrrr#<sz8_OptionParser._process_args_for_args.<locals>.<listcomp>)r/rursr~� enumerater`)rOrVZpargsr�idx�argrrrr�:s� z$_OptionParser._process_args_for_argscCs�|jr?|j�d�}t|�}|dkrdS|dd�|jvr'|dkr'|�||�n|jr1|j�|�n |j�d|�dS|jsdSdS)Nrrxr) rsrr)r}� _process_optsryrur$�insert)rOrVr�Zarglenrrrr�Es �z'_OptionParser._process_args_for_optionsr0r1�explicit_valuecCs�||jvrddlm}|||j�}t|||jd��|j|}|jr4|dur,|j�d|�|�|||�}n|durCt |t d�j |d���d}|� ||�dS)Nr)�get_close_matches)� possibilitiesr8z&Option {name!r} does not take a value.)rm) r|Zdifflibr�r r8rTrsr��_get_value_from_staterr"rpr`)rOr0r�rVr�r�r�rPrrr�_match_long_optis    �z_OptionParser._match_long_optr�c Cs�d}d}|d}g}|dd�D]R}t|�|��|j�}|j�|�} |d7}| s8|jr1|�|�qt||jd��| jrV|t|�krN|j � d||d��d}|� || |�} nd} | � | |�|rbnq|jrw|ry|j �|�d�|����dSdSdS)NFrr)r8Tr3)r<r8r{r^rzr$r rTr)rsr�r�r`ru�join) rOr�rV�stop�ir;Zunknown_options�chr0r�rPrrr�_match_short_opt�s4    � �z_OptionParser._match_short_opt� option_namer�r=rUcCs�|j}t|j�|kr |jjrt}|St|tdd|�j||d���|dkrM|jd}|jjrEt|t �rE|dd�|j vrEt|�dkrEt}|S|j� d�}|St |jd|��}|jd|�=|S)Nz%Option {name!r} requires an argument.z+Option {name!r} requires {nargs} arguments.rlrr) r-r)rsr>�_flag_needs_valuerrrp� isinstancer1r}rr')rOr�r�rVr-rPZ next_rargrrrr��s<���� ��  �� z#_OptionParser._get_value_from_statecCs�d}d|vr|�dd�\}}n|}t||j�}z |�|||�WdStyG|dd�|jvr:|�||�YdS|js>�|j� |�YdSw)N�=rr4) �splitr<r8r�r r}r�rzrur$)rOr�rVr�Zlong_optZ norm_long_optrrrr��s   �z_OptionParser._process_optsr)r8r9rrXra)r>r?r@rrArBrCrBr-rDrErFrrXrr)r>rgrArBr-rDrrX)rrtrr�)rVrWrrX)r0r1r�rBrVrWrrX)r�r1rVrWrrX)r�r1r�r=rVrWrrU)rbrcrd�__doc__rQr�r�r�r�r�r�r�r�r�rrrrrv�s  �    $  (&rvrm�objectcCshddl}|dvr|jd|�d�tdd�t�d|��S|dkr0d d lm}|jd tdd�|St|��) Nr>� OptionParserr Z split_optZ ParsingStater Z normalize_optz'parser.z\' is deprecated and will be removed in Click 9.0. The old parser is available in 'optparse'.r4)� stacklevelr"�split_arg_stringr)r�zpImporting 'parser.split_arg_string' is deprecated, it will only be available in 'shell_completion' in Click 9.0.)�warnings�warn�DeprecationWarning�globals�shell_completionr��AttributeError)rmr�r�rrr� __getattr__�s" � �r�)rrrrrr)r0r1rr2)r0r1r8r9rr1)rmr1rr�)'r�� __future__r�collections.abc�abc�cabc�typing�t� collectionsrrr"r� exceptionsrrr r � TYPE_CHECKING�corer rgr r r?rZ CoreParameter�TypeVarrr�r�r/r7r<r=rfrWrvr�rrrr�<module>s8                < 6 
Memory