o
    Ú­jéR  ã                   @   s†  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ erŽd dlmZ dZeG dd„ dƒƒZ G dd„ de!ƒZ"G dd„ dƒZ#G dd„ dƒZ$G dd „ d e j%ƒZ&G d!d"„ d"e j'ƒZ(dS )#é    N)Úgettext)ÚAny)ÚCallable)Úcast)ÚDict)ÚList)ÚMapping)ÚNoReturn)ÚOptional)ÚSequence)ÚTuple)ÚTYPE_CHECKING)ÚUnion)Úfinal)Ú
UsageError)ÚARGUMENT_PERCENT_DEFAULT)ÚARGUMENT_TYPE_STR)ÚARGUMENT_TYPE_STR_CHOICE)Úcheck_ispytest)ÚLiteralÚfile_or_dirc                   @   sš  e Zd ZU dZdZee ed< 		d/ddœdee deedgdf  d	e	d
dfdd„Z
d0dd„Z	d1dededee d
dfdd„Zdeded
dfdd„Z	d2deeedf  deej d
ejfdd„Zd3d!d"„Z	d2deeedf  dejdeej d
ee fd#d$„Z	d2deeedf  deej d
ejfd%d&„Z	d2deeedf  deej d
eejee f fd'd(„Z		d/ded)ed*ed+ d,ed
df
d-d.„ZdS )4ÚParserzÄParser for command line arguments and ini-file values.

    :ivar extra_info: Dict of generic param -> value to display in case
        there's an error processing the command line arguments.
    NÚprogF©Ú	_ispytestÚusageÚ
processoptÚArgumentr   Úreturnc                C   s@   t |ƒ td| dd�| _g | _|| _|| _i | _g | _i | _d S )NzCustom optionsT©Úparserr   )	r   ÚOptionGroupÚ
_anonymousÚ_groupsÚ_processoptÚ_usageÚ_inidictÚ	_ininamesÚ
extra_info)Úselfr   r   r   © r*   úV/var/www/html/CropPilot/venv/lib/python3.10/site-packages/_pytest/config/argparsing.pyÚ__init__+   s   
zParser.__init__Úoptionc                 C   s"   | j r|jr|   |¡ d S d S d S ©N)r$   Údest)r)   r-   r*   r*   r+   Úprocessoption;   s
   þzParser.processoptionÚ ÚnameÚdescriptionÚafterr!   c                 C   sj   | j D ]}|j|kr|  S qt||| dd�}d}t| j ƒD ]\}}|j|kr) nq| j  |d |¡ |S )a  Get (or create) a named option Group.

        :param name: Name of the option group.
        :param description: Long description for --help output.
        :param after: Name of another group, used for ordering --help output.
        :returns: The option group.

        The returned group object has an ``addoption`` method with the same
        signature as :func:`parser.addoption <pytest.Parser.addoption>` but
        will be shown in the respective group in the output of
        ``pytest --help``.
        Tr   r   é   )r#   r2   r!   Ú	enumerateÚinsert)r)   r2   r3   r4   ÚgroupÚiÚgrpr*   r*   r+   Úgetgroup@   s   

ÿ
ÿzParser.getgroupÚoptsÚattrsc                 O   s   | j j|i |¤Ž dS )a!  Register a command line option.

        :param opts:
            Option names, can be short or long options.
        :param attrs:
            Same attributes as the argparse library's :py:func:`add_argument()
            <argparse.ArgumentParser.add_argument>` function accepts.

        After command line parsing, options are available on the pytest config
        object via ``config.option.NAME`` where ``NAME`` is usually set
        by passing a ``dest`` attribute, for example
        ``addoption("--long", dest="NAME", ...)``.
        N)r"   Ú	addoption)r)   r<   r=   r*   r*   r+   r>   Z   s   zParser.addoptionÚargszos.PathLike[str]Ú	namespacec                 C   s>   ddl m} |  ¡ | _|| jƒ dd„ |D ƒ}| jj||d�S )Nr   )Útry_argcompletec                 S   ó   g | ]}t  |¡‘qS r*   ©ÚosÚfspath©Ú.0Úxr*   r*   r+   Ú
<listcomp>s   ó    z Parser.parse.<locals>.<listcomp>©r@   )Ú_pytest._argcompleterA   Ú
_getparserÚ	optparserÚ
parse_args)r)   r?   r@   rA   Ústrargsr*   r*   r+   Úparsej   s
   

zParser.parseÚMyOptionParserc                 C   s–   ddl m} t| | j| jd�}| j| jg }|D ]&}|jr>|jp"|j	}| 
|¡}|jD ]}| ¡ }| ¡ }	|j|i |	¤Ž q+q|jtdd�}
||
_|S )Nr   )Úfilescompleter)r   Ú*)Únargs)rL   rS   rR   r(   r   r#   r"   Úoptionsr3   r2   Úadd_argument_groupÚnamesr=   Úadd_argumentÚFILE_OR_DIRÚ	completer)r)   rS   rN   Úgroupsr8   ÚdescÚarggroupr-   ÚnÚaÚfile_or_dir_argr*   r*   r+   rM   v   s   

€zParser._getparserc                 C   sB   | j ||d�}|j ¡ D ]
\}}t|||ƒ qttt t|tƒƒS )NrK   )	rQ   Ú__dict__ÚitemsÚsetattrr   r   ÚstrÚgetattrrZ   )r)   r?   r-   r@   Úparsedoptionr2   Úvaluer*   r*   r+   Úparse_setoption‰   s   zParser.parse_setoptionc                 C   s   | j ||d�d S )zbParse the known arguments at this point.

        :returns: An argparse namespace object.
        rK   r   )Úparse_known_and_unknown_args)r)   r?   r@   r*   r*   r+   Úparse_known_args”   s   	zParser.parse_known_argsc                 C   s$   |   ¡ }dd„ |D ƒ}|j||d�S )a  Parse the known arguments at this point, and also return the
        remaining unknown arguments.

        :returns:
            A tuple containing an argparse namespace object for the known
            arguments, and a list of the unknown arguments.
        c                 S   rB   r*   rC   rF   r*   r*   r+   rI   ¬   rJ   z7Parser.parse_known_and_unknown_args.<locals>.<listcomp>rK   )rM   rk   )r)   r?   r@   rN   rP   r*   r*   r+   rj   Ÿ   s   z#Parser.parse_known_and_unknown_argsÚhelpÚtypezBLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool']Údefaultc                 C   s,   |dv sJ ‚|||f| j |< | j |¡ dS )a–  Register an ini-file option.

        :param name:
            Name of the ini-variable.
        :param type:
            Type of the variable. Can be:

                * ``string``: a string
                * ``bool``: a boolean
                * ``args``: a list of strings, separated as in a shell
                * ``linelist``: a list of strings, separated by line breaks
                * ``paths``: a list of :class:`pathlib.Path`, separated as in a shell
                * ``pathlist``: a list of ``py.path``, separated as in a shell

            .. versionadded:: 7.0
                The ``paths`` variable type.

            Defaults to ``string`` if ``None`` or not passed.
        :param default:
            Default value if no ini-file option exists but is queried.

        The value of ini-variables can be retrieved via a call to
        :py:func:`config.getini(name) <pytest.Config.getini>`.
        )NÚstringÚpathsÚpathlistr?   ÚlinelistÚboolN)r&   r'   Úappend)r)   r2   rl   rm   rn   r*   r*   r+   Úaddini¯   s   !zParser.addini©NN)r-   r   r   N©r1   Nr.   )r   rR   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r
   re   Ú__annotations__r   rs   r,   r0   r;   r   r>   r   r   ÚargparseÚ	NamespacerQ   rM   r   ri   rk   r   rj   ru   r*   r*   r*   r+   r   !   sœ   
 ýûþýû
ú
ÿÿÿÿ
þýþý
ü
üþýü
ûýþý
üýþý
üùþýÿüùør   c                   @   s<   e Zd ZdZdededef ddfdd„Zdefd	d
„ZdS )ÚArgumentErrorzURaised if an Argument instance is created with invalid or
    inconsistent arguments.Úmsgr-   r   r   Nc                 C   s   || _ t|ƒ| _d S r.   )r€   re   Ú	option_id)r)   r€   r-   r*   r*   r+   r,   Ù   s   zArgumentError.__init__c                 C   s    | j rd| j › d| j› �S | jS )Nzoption ú: )r�   r€   ©r)   r*   r*   r+   Ú__str__Ý   s   zArgumentError.__str__)rx   ry   rz   r{   re   r   r,   r„   r*   r*   r*   r+   r   Õ   s    r   c                   @   s€   e Zd ZdZeeeedœZdede	ddfdd„Z
dee fd	d
„Zdeee	f fdd„Zdee ddfdd„Zdefdd„ZdS )r   z÷Class that mimics the necessary behaviour of optparse.Option.

    It's currently a least effort implementation and ignoring choices
    and integer prefixes.

    https://docs.python.org/3/library/optparse.html#optparse-standard-option-types
    )Úintro   ÚfloatÚcomplexrX   r=   r   Nc              
   O   sz  || _ g | _g | _d| d¡pdv rtjtdd� z|d }W n	 ty(   Y n=w t|t	ƒrb|dkrItjt
j||d�d	d� t|d
 d ƒ|d< ntjtj||d�d	d� tj| |d< |d | _n|| _z|d | _W n	 tyu   Y nw |  |¡ | d¡}|r‡|| _dS | jrš| jd dd…  dd¡| _dS z| jd dd… | _W dS  ty¼ } z	d| _td| ƒ|‚d}~ww )z5Store params in private vars for use in add_argument.ú%defaultrl   r1   é   )Ú
stacklevelrm   Úchoice)ÚtyprX   é   Úchoicesr   rn   r/   é   Nú-Ú_r5   z???zneed a long or short option)Ú_attrsÚ_short_optsÚ
_long_optsÚgetÚwarningsÚwarnr   ÚKeyErrorÚ
isinstancere   r   Úformatrm   r   r   Ú_typ_maprn   Ú_set_opt_stringsr/   ÚreplaceÚ
IndexErrorr   )r)   rX   r=   rŒ   r/   Úer*   r*   r+   r,   ï   sR   ÿ
þÿÿ


 €þzArgument.__init__c                 C   s   | j | j S r.   )r“   r”   rƒ   r*   r*   r+   rX      s   zArgument.namesc              	   C   sv   d  ¡ }| | j¡ |D ]}z
t| |ƒ| j|< W q ty!   Y qw | j d¡r8| jd }| dd¡}|| jd< | jS )Nzdefault dest helprl   rˆ   z%(default)s)Úsplitrt   r/   rf   r’   ÚAttributeErrorr•   r�   )r)   r=   Úattrr`   r*   r*   r+   r=   #  s   ÿ

zArgument.attrsr<   c                 C   sž   |D ]J}t |ƒdk rtd| | ƒ‚t |ƒdkr1|d dkr#|d dks*td| | ƒ‚| j |¡ q|dd… dkr?|d dksFtd| | ƒ‚| j |¡ qd	S )
zhDirectly from optparse.

        Might not be necessary as this is passed to argparse later on.
        r�   z>invalid option string %r: must be at least two characters longr   r�   r5   zMinvalid short option string %r: must be of the form -x, (x any non-dash char)ú--zGinvalid long option string %r: must start with --, followed by non-dashN)Úlenr   r“   rt   r”   )r)   r<   Úoptr*   r*   r+   rœ   3  s4   ÿýÿýÿýêzArgument._set_opt_stringsc                 C   s˜   g }| j r|dt| j ƒ g7 }| jr|dt| jƒ g7 }|dt| jƒ g7 }t| dƒr5|dt| jƒ g7 }t| dƒrD|dt| jƒ g7 }d d	 |¡¡S )
Nz_short_opts: z_long_opts: zdest: rm   ztype: rn   z	default: zArgument({})ú, )	r“   Úreprr”   r/   Úhasattrrm   rn   rš   Újoin)r)   r?   r*   r*   r+   Ú__repr__P  s   

zArgument.__repr__)rx   ry   rz   r{   r…   re   r†   r‡   r›   r   r,   r   rX   r   r=   r   rœ   rª   r*   r*   r*   r+   r   ä   s    1r   c                   @   s‚   e Zd ZdZ		dddœdededee d	ed
df
dd„Zdede	d
dfdd„Z
dede	d
dfdd„Zdddded
dfdd„ZdS )r!   z,A group of options shown in its own section.r1   NFr   r2   r3   r    r   r   c                C   s$   t |ƒ || _|| _g | _|| _d S r.   )r   r2   r3   rV   r    )r)   r2   r3   r    r   r*   r*   r+   r,   a  s
   
zOptionGroup.__init__r<   r=   c                 O   sJ   t |ƒ dd„ | jD ƒ¡}|rtd| ƒ‚t|i |¤Ž}| j|dd� dS )aM  Add an option to this group.

        If a shortened version of a long option is specified, it will
        be suppressed in the help. ``addoption('--twowords', '--two-words')``
        results in help showing ``--two-words`` only, but ``--twowords`` gets
        accepted **and** the automatic destination is in ``args.twowords``.

        :param opts:
            Option names, can be short or long options.
        :param attrs:
            Same attributes as the argparse library's :py:func:`add_argument()
            <argparse.ArgumentParser.add_argument>` function accepts.
        c                 s   s"   � | ]}|  ¡ D ]}|V  qqd S r.   )rX   )rG   r¥   r2   r*   r*   r+   Ú	<genexpr>}  s   € ÿÿz(OptionGroup.addoption.<locals>.<genexpr>zoption names %s already addedF©Ú
shortupperN)ÚsetÚintersectionrV   Ú
ValueErrorr   Ú_addoption_instance)r)   r<   r=   Úconflictr-   r*   r*   r+   r>   o  s   ÿzOptionGroup.addoptionc                 O   s    t |i |¤Ž}| j|dd� d S )NTr¬   )r   r±   )r)   r<   r=   r-   r*   r*   r+   Ú
_addoption…  s   zOptionGroup._addoptionr-   r   r­   c                 C   sR   |s|j D ]}|d dkr|d  ¡ rtdƒ‚q| jr!| j |¡ | j |¡ d S )Nr   r�   r5   zlowercase shortoptions reserved)r“   Úislowerr°   r    r0   rV   rt   )r)   r-   r­   r¥   r*   r*   r+   r±   ‰  s   
€zOptionGroup._addoption_instancerw   )F)rx   ry   rz   r{   re   r
   r   rs   r,   r   r>   r³   r±   r*   r*   r*   r+   r!   ^  s(    üúþýüú
ùr!   c                	       sÆ   e Zd Z		ddedeeeef  dee ddf‡ fdd„Zdede	fd	d
„Z
		ddeee  deej dejfdd„Zejdd… dk r_dedeeeej eee f  fdd„Z‡  ZS ‡  ZS )rR   Nr    r(   r   r   c                    s6   || _ tƒ j||jdtdd� |r|| _d S i | _d S )NF)r   r   Úadd_helpÚformatter_classÚallow_abbrev)Ú_parserÚsuperr,   r%   ÚDropShorterLongHelpFormatterr(   )r)   r    r(   r   ©Ú	__class__r*   r+   r,   ”  s   û	zMyOptionParser.__init__Úmessagec                 C   s@   | j › d|› �}t| jdƒr|› d| jj› d�}t|  ¡ | ƒ‚)z1Transform argparse error message into UsageError.z	: error: Ú_config_source_hintz (ú))r   r¨   r¸   r¾   r   Úformat_usage)r)   r½   r€   r*   r*   r+   Úerror¦  s   zMyOptionParser.errorr?   r@   c           	      C   s�   |   ||¡\}}|rF|D ]1}|r=|d dkr=dd |¡ g}t| j ¡ ƒD ]\}}| d|› d|› �¡ q%|  d |¡¡ qt|tƒ 	|¡ |S )z(Allow splitting of positional arguments.r   r�   zunrecognized arguments: %sú z  r‚   Ú
)
rk   r©   Úsortedr(   rc   rt   rÁ   rf   rZ   Úextend)	r)   r?   r@   ÚparsedÚunrecognizedÚargÚlinesÚkÚvr*   r*   r+   rO   ±  s   €zMyOptionParser.parse_argsr�   )r‰   é	   Ú
arg_stringc           	      C   s  |sd S |d | j vrd S || jv r| j| }||d fS t|ƒdkr$d S d|v r?| dd¡\}}|| jv r?| j| }|||fS | jsG| d¡sv|  |¡}t|ƒdkrktdƒ}d dd„ |D ƒ¡}|  	|||d	œ ¡ nt|ƒdkrv|\}|S | j
 |¡r�| js�d S d
|v r‡d S d |d fS )Nr   r5   ú=r£   z4ambiguous option: %(option)s could match %(matches)sr¦   c                 s   s   � | ]\}}}|V  qd S r.   r*   )rG   r‘   r-   r*   r*   r+   r«   Ü  s   € z1MyOptionParser._parse_optional.<locals>.<genexpr>)r-   ÚmatchesrÂ   )Úprefix_charsÚ_option_string_actionsr¤   r    r·   Ú
startswithÚ_get_option_tuplesr   r©   rÁ   Ú_negative_number_matcherÚmatchÚ_has_negative_number_optionals)	r)   rÍ   ÚactionÚoption_stringÚexplicit_argÚoption_tuplesr€   rV   Úoption_tupler*   r*   r+   Ú_parse_optionalÅ  s>   






ÿ
zMyOptionParser._parse_optionalrv   )rx   ry   rz   r   r
   r   re   r   r,   r	   rÁ   r   r}   r~   rO   ÚsysÚversion_infor   ÚActionrÜ   Ú__classcell__r*   r*   r»   r+   rR   “  s:    üþýüûý
þý
üÿþýrR   c                       sN   e Zd ZdZdededdf‡ fdd„Zdejdef‡ fd	d
„Z	dd„ Z
‡  ZS )rº   a+  Shorten help for long options that differ only in extra hyphens.

    - Collapse **long** options that are the same except for extra hyphens.
    - Shortcut if there are only two options and one of them is a short one.
    - Cache result on the action object as this is called at least 2 times.
    r?   Úkwargsr   Nc                    s,   d|vrt j ¡ |d< tƒ j|i |¤Ž d S )NÚwidth)Ú_pytestÚ_ioÚget_terminal_widthr¹   r,   )r)   r?   rá   r»   r*   r+   r,   ñ  s   z%DropShorterLongHelpFormatter.__init__r×   c                    sf  t ƒ  |¡}|r|d dkr|S t|dd ƒ}|r|S | d¡}t|ƒdkr:t|d ƒdks5t|d ƒdkr:||_|S g }i }|D ]9}t|ƒdksN|d dkrOq@| d¡s[td	| |ƒ‚|dd … }| dd
¡}	|	|vsut||	 ƒt|ƒk ry|||	< q@|D ],}t|ƒdksŠ|d dkr�| 	|¡ |dd … | 
| dd
¡¡kr¨| 	| ddd¡¡ q|d |¡}
|
|_|
S )Nr   r�   Ú_formatted_action_invocationr¦   r�   r5   rÂ   r£   z)long optional argument without "--": [%s]r1   rÎ   )r¹   Ú_format_action_invocationrf   r    r¤   ræ   rÒ   r   r�   rt   r•   r©   )r)   r×   ÚorgstrÚresrV   Úreturn_listÚ
short_longr-   ÚxxoptionÚ	shortenedÚformatted_action_invocationr»   r*   r+   rç   ÷  sF   
,
ÿÿ€
€
z6DropShorterLongHelpFormatter._format_action_invocationc                 C   s4   ddl }g }| ¡ D ]}| | | ¡ |¡¡ q
|S )z}Wrap lines after splitting on original newlines.

        This allows to have explicit line breaks in the help text.
        r   N)ÚtextwrapÚ
splitlinesrÅ   ÚwrapÚstrip)r)   Útextrâ   rï   rÉ   Úliner*   r*   r+   Ú_split_lines  s
   z)DropShorterLongHelpFormatter._split_lines)rx   ry   rz   r{   r   r,   r}   rß   re   rç   rõ   rà   r*   r*   r»   r+   rº   é  s
    &rº   ))r}   rD   rÝ   r–   r   Útypingr   r   r   r   r   r   r	   r
   r   r   r   r   Ú_pytest._iorã   Ú_pytest.compatr   Ú_pytest.config.exceptionsr   Ú_pytest.deprecatedr   r   r   r   Útyping_extensionsr   rZ   r   Ú	Exceptionr   r   r!   ÚArgumentParserrR   ÚHelpFormatterrº   r*   r*   r*   r+   Ú<module>   sF     4z5V