o
    v&iO                     @  s2  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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Zd dlmZ dZG dd dZe ZeG dd dZ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 G d"d# d#ej!Z"dS )%    )annotationsN)Callable)Mapping)Sequence)Any)final)Literal)NoReturn   )
UsageError)check_ispytestfile_or_dirc                   @  s   e Zd ZdddZdS )NotSetreturnstrc                 C  s   dS )Nz<notset> selfr   r   _/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/config/argparsing.py__repr__   s   zNotSet.__repr__Nr   r   )__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @  s   e Zd ZdZ		d:ddd;ddZed<ddZejd=ddZd>ddZ	d?d@ddZ	dAd"d#Z
	dBdCd)d*Z	dBdCd+d,Z	dBdDd.d/Zdefd0d1dEd8d9ZdS )FParserzParser for command line arguments and config-file values.

    :ivar extra_info: Dict of generic param -> value to display in case
        there's an error processing the command line arguments.
    NF	_ispytestusage
str | None
processopt!Callable[[Argument], None] | Noner   boolr   Nonec                C  s~   t | ddlm} || _i | _t| || j| _| jd}t|d| dd| _	| j	g| _
| jjtdd}||_i | _i | _d S )	Nr   )filescompleterzCustom options
_anonymousTr   *)nargs)r   _pytest._argcompleter#   _processopt
extra_infoPytestArgumentParser	optparseradd_argument_groupOptionGroupr$   _groupsadd_argumentFILE_OR_DIR	completer_inidict_ini_aliases)r   r   r   r   r#   anonymous_arggroupfile_or_dir_argr   r   r   __init__'   s   

zParser.__init__r   c                 C  s   | j jS Nr+   progr   r   r   r   r9   A   s   zParser.progvaluec                 C  s   || j _d S r7   r8   )r   r:   r   r   r   r9   E   s   optionArgumentc                 C  s"   | j r|jr|  | d S d S d S r7   )r(   dest)r   r;   r   r   r   processoptionI   s
   zParser.processoption namedescriptionafterr-   c                 C  s   | j D ]}|j|kr|  S q| j|p|}t||| dd}d}t| j D ]\}}|j|kr1 nq&| j |d | | jj|d | jj  |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
   )	r.   r@   r+   r,   r-   	enumerateinsert_action_groupspop)r   r@   rA   rB   grouparggroupigrpr   r   r   getgroupN   s   


zParser.getgroupoptsattrsr   c                 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 :meth:`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   rL   rM   r   r   r   rN   m   s   zParser.addoptionargs Sequence[str | os.PathLike[str]]	namespaceargparse.Namespace | Noneargparse.Namespacec                 C  sX   ddl m} || j dd |D }|du rt }zd|_| jj||dW |`S |`w )zParse the arguments.

        Unlike ``parse_known_args`` and ``parse_known_and_unknown_args``,
        raises PrintHelp on `--help` and UsageError on unknown flags

        :meta private:
        r   )try_argcompletec                 S     g | ]}t |qS r   osfspath.0xr   r   r   
<listcomp>       z Parser.parse.<locals>.<listcomp>NTrQ   )r'   rT   r+   argparse	Namespace_raise_print_helpparse_intermixed_args)r   rO   rQ   rT   strargsr   r   r   parse}   s   
zParser.parsec                 C  s   | j ||dd S )zbParse the known arguments at this point.

        :returns: An argparse namespace object.
        r^   r   )parse_known_and_unknown_args)r   rO   rQ   r   r   r   parse_known_args   s   	zParser.parse_known_args$tuple[argparse.Namespace, list[str]]c                 C  s   dd |D }t jdk sdt j  krdk rDn n+| j||\}}|dus(J t|t}g }|D ]}|dr:|n|| q1||fS | j||S )a	  Parse the known arguments at this point, and also return the
        remaining unknown flag arguments.

        :returns:
            A tuple containing an argparse namespace object for the known
            arguments, and a list of unknown flag arguments.
        c                 S  rU   r   rV   rY   r   r   r   r\      r]   z7Parser.parse_known_and_unknown_args.<locals>.<listcomp>)         )rh      )rh   rk   r
   N-)	sysversion_infor+   rf   getattrr0   
startswithappendparse_known_intermixed_args)r   rO   rQ   rc   unknownr   unknown_flagsargr   r   r   re      s   $
z#Parser.parse_known_and_unknown_argsr   )aliaseshelptypeYLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool', 'int', 'float'] | Nonedefaultrv   Sequence[str]c                C  s   |dv sJ |du rd}|t u rt|}|||f| j|< |D ]'}|| jv r-td|d| j| }dur@t|d||| j|< qdS )a  Register a configuration file option.

        :param name:
            Name of the configuration.
        :param type:
            Type of the configuration. 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
                * ``int``: an integer
                * ``float``: a floating-point number

                .. versionadded:: 8.4

                    The ``float`` and ``int`` types.

            For ``paths`` and ``pathlist`` types, they are considered relative to the config-file.
            In case the execution is happening without a config-file defined,
            they will be considered relative to the current working directory (for example with ``--override-ini``).

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

            .. versionadded:: 8.1
                Use the current working directory to resolve ``paths`` and ``pathlist`` in the absence of a config-file.

            Defaults to ``string`` if ``None`` or not passed.
        :param default:
            Default value if no config-file option exists but is queried.
        :param aliases:
            Additional names by which this option can be referenced.
            Aliases resolve to the canonical name.

            .. versionadded:: 9.0
                The ``aliases`` parameter.

        The value of configuration keys can be retrieved via a call to
        :py:func:`config.getini(name) <pytest.Config.getini>`.
        )	NstringpathspathlistrO   linelistr!   intfloatNr|   zalias z- conflicts with existing configuration optionz is already an alias of )NOT_SETget_ini_default_for_typer2   
ValueErrorr3   get)r   r@   rw   rx   rz   rv   aliasalreadyr   r   r   addini   s   7

zParser.addini)NN)r   r   r   r    r   r!   r   r"   r   )r:   r   r   r"   )r;   r<   r   r"   )r?   N)r@   r   rA   r   rB   r   r   r-   rL   r   rM   r   r   r"   r7   )rO   rP   rQ   rR   r   rS   )rO   rP   rQ   rR   r   rg   )r@   r   rw   r   rx   ry   rz   r   rv   r{   r   r"   )r   r   r   __doc__r6   propertyr9   setterr>   rK   rN   rd   rf   re   r   r   r   r   r   r   r      s4    

 
r   rx   RLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool', 'int', 'float']r   r   c                 C  s4   | dv rg S | dkrdS | dkrdS | dkrdS dS )	zs
    Used by addini to get the default value for a given config option type, when
    default is not supplied.
    )r}   r~   rO   r   r!   Fr   r   r   g        r?   r   )rx   r   r   r   r     s   	r   c                   @  s$   e Zd ZdZddd	Zdd
dZdS )ArgumentErrorzURaised if an Argument instance is created with invalid or
    inconsistent arguments.msgr   r;   Argument | strr   r"   c                 C  s   || _ t|| _d S r7   )r   r   	option_id)r   r   r;   r   r   r   r6   %  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__N)r   r   r;   r   r   r"   r   )r   r   r   r   r6   r   r   r   r   r   r   !  s    
r   c                   @  sB   e Zd ZdZddd	ZdddZdddZdddZdddZdS )r<   zClass 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
    namesr   rM   r   r   r"   c              
   O  s   || _ g | _g | _z|d | _W n	 ty   Y nw z|d | _W n	 ty*   Y nw | | |d}|r<|| _dS | jrO| jd dd 	dd| _dS z| jd d	d | _W dS  t
yq } z	d
| _td| |d}~ww )z5Store params in private vars for use in add_argument.rx   rz   r=   r      Nrl   _r
   z???zneed a long or short option)_attrs_short_opts
_long_optsrx   KeyErrorrz   _set_opt_stringsr   r=   replace
IndexErrorr   )r   r   rM   r=   er   r   r   r6   9  s4   


 zArgument.__init__	list[str]c                 C  s   | j | j S r7   )r   r   r   r   r   r   r   T  s   zArgument.namesMapping[str, Any]c              	   C  s@   ddd| j fD ]}z
t| || j|< W q ty   Y qw | jS )Nrz   r=   rw   )r=   ro   r   AttributeError)r   attrr   r   r   rM   W  s   zArgument.attrsrL   r{   c                 C  s   |D ]P}t |dk rtd|d| t |dkr5|d dkr%|d dks.td|d| | j| q|dd d	krC|d dksLtd
|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 z&: must be at least two characters longr   rl   r
   zinvalid short option string z/: must be of the form -x, (x any non-dash char)--zinvalid long option string z*: must start with --, followed by non-dashN)lenr   r   rq   r   )r   rL   optr   r   r   r   `  s(   


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: rx   ztype: rz   z	default: zArgument({}), )	r   reprr   r=   hasattrrx   rz   formatjoin)r   rO   r   r   r   r   }  s   

zArgument.__repr__N)r   r   rM   r   r   r"   )r   r   )r   r   )rL   r{   r   r"   r   )	r   r   r   r   r6   r   rM   r   r   r   r   r   r   r<   0  s    



	r<   c                   @  s>   e Zd ZdZ	ddddZdddZdddZddddZdS ) r-   z,A group of options shown in its own section.FrH   argparse._ArgumentGroupr@   r   parserParser | Noner   r!   r   r"   c                 C  s$   t | || _|| _g | _|| _d S r7   )r   	_arggroupr@   optionsr   )r   rH   r@   r   r   r   r   r   r6     s
   
zOptionGroup.__init__rL   rM   r   c                 O  sN   t |dd | jD }|rtd| dt|i |}| j|dd dS )aJ  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 :meth:`add_argument()
            <argparse.ArgumentParser.add_argument>` function accepts.
        c                 s  s"    | ]}|  D ]}|V  qqd S r7   )r   )rZ   r   r@   r   r   r   	<genexpr>  s    z(OptionGroup.addoption.<locals>.<genexpr>zoption names z already addedF
shortupperN)setintersectionr   r   r<   _addoption_instance)r   rL   rM   conflictr;   r   r   r   rN     s   zOptionGroup.addoptionc                 O  s    t |i |}| j|dd d S )NTr   )r<   r   )r   rL   rM   r;   r   r   r   
_addoption  s   zOptionGroup._addoptionr;   r<   r   c                 C  sl   |s|j D ]}|d dkr|d  rtdq| jr!| j| | jj| i |  | j	
| d S )Nr   rl   r
   zlowercase shortoptions reserved)r   islowerr   r   r>   r   r/   r   rM   r   rq   )r   r;   r   r   r   r   r   r     s   
zOptionGroup._addoption_instanceN)F)
rH   r   r@   r   r   r   r   r!   r   r"   r   )r;   r<   r   r!   r   r"   )r   r   r   r   r6   rN   r   r   r   r   r   r   r-     s    

r-   c                      s(   e Zd Zd fd	d
ZdddZ  ZS )r*   r   r   r   r   r)   dict[str, str]r   r"   c                   s&   || _ t j|dtddd || _d S )NF@)r   add_helpformatter_classallow_abbrevfromfile_prefix_chars)_parsersuperr6   DropShorterLongHelpFormatterr)   )r   r   r   r)   	__class__r   r   r6     s   
	zPytestArgumentParser.__init__messager   r	   c                 C  sL   | j  d| }| jr|dddd t| j D  7 }t|  | )z1Transform argparse error message into UsageError.z	: error: 
c                 s  s$    | ]\}}d | d| V  qdS )z  r   Nr   )rZ   kvr   r   r   r     s    
z-PytestArgumentParser.error.<locals>.<genexpr>)r9   r)   r   sorteditemsr   format_usage)r   r   r   r   r   r   error  s   zPytestArgumentParser.error)r   r   r   r   r)   r   r   r"   )r   r   r   r	   )r   r   r   r6   r   __classcell__r   r   r   r   r*     s    r*   c                      s8   e Zd ZdZd fddZd 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.
    rO   r   kwargsr   r"   c                   s,   d|vrt j |d< t j|i | d S )Nwidth)_pytest_ioget_terminal_widthr   r6   )r   rO   r   r   r   r   r6     s   z%DropShorterLongHelpFormatter.__init__actionargparse.Actionr   c                   sj  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 ];}t|dksN|d dkrOq@|ds]td	| d
||dd  }|dd}	|	|vswt||	 t|k r{|||	< q@|D ],}t|dks|d dkr|	| |dd  |
|ddkr|	|ddd q~d|}
|
|_|
S )Nr   rl   _formatted_action_invocationr   r   r
    r   z&long optional argument without "--": []r?   =)r   _format_action_invocationro   splitr   r   rp   r   r   rq   r   r   )r   r   orgstrresr   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
splitlinesextendwrapstrip)r   textr   r   linesliner   r   r   _split_lines  s
   z)DropShorterLongHelpFormatter._split_lines)rO   r   r   r   r   r"   )r   r   r   r   )r   r   r   r   r6   r   r   r   r   r   r   r   r     s
    &r   c                      s0   e Zd ZdZ	dd fddZdddZ  ZS )OverrideIniActionzCustom argparse action that makes a CLI flag equivalent to overriding an
    option, in addition to behaving like `store_true`.

    This can simplify things since code only needs to inspect the config option
    and not consider the CLI flag.
    Noption_stringsr{   r=   r   r&   int | str | None
ini_option	ini_valuer   r"   c                  s.   t  j||dg|R i | || _|| _d S )Nr   )r   r6   r   r   )r   r   r=   r&   r   r   rO   r   r   r   r   r6   (  s   

zOverrideIniAction.__init__r   argparse.ArgumentParserrQ   rS   c                 O  sN   t || jd t|dd }|d u rg }|| j d| j  t |d| d S )NToverride_inir   )setattrr=   ro   rq   r   r   )r   r   rQ   rO   r   current_overridesr   r   r   __call__6  s   zOverrideIniAction.__call__r7   )r   r{   r=   r   r&   r   r   r   r   r   r   r"   )r   r   rQ   rS   r   r"   )r   r   r   r   r6   r   r   r   r   r   r   r      s
    r   )rx   r   r   r   )#
__future__r   r_   collections.abcr   r   r   rW   rm   typingr   r   r   r	   
exceptionsr   _pytest._ior   _pytest.deprecatedr   r0   r   r   r   r   	Exceptionr   r<   r-   ArgumentParserr*   HelpFormatterr   Actionr   r   r   r   r   <module>   s6    
m[7A