
    iO                       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          Z e            Ze G d d                      Zd#dZ G d de          Z G d d          Z G d d          Z G d dej                  Z G d d ej                  Z  G d! d"ej!                  Z"dS )$    )annotationsN)Callable)Mapping)Sequence)Any)final)Literal)NoReturn   )
UsageError)check_ispytestfile_or_dirc                      e Zd ZddZdS )NotSetreturnstrc                    dS )Nz<notset> selfs    V/root/projects/qq-shell/venv/lib/python3.11/site-packages/_pytest/config/argparsing.py__repr__zNotSet.__repr__   s    z    Nr   r   )__name__
__module____qualname__r   r   r   r   r   r      s(             r   r   c                      e Zd ZdZ	 	 d1ddd2dZed3d            Zej        d4d            Zd5dZ	 d6d7dZ	d8dZ
	 d9d:d$Z	 d9d:d%Z	 d9d;d'Zdefd(d)d<d0ZdS )=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               l   t          |           ddlm} || _        i | _        t          | || j                  | _        | j                            d          }t          |d| d          | _	        | j	        g| _
        | j                            t          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_args          r   __init__zParser.__init__'   s     	y!!!777777%*,-dE4?KK!^>>?OPP%dd
 
 
 (.55k5MM$2!9;,.r   r   c                    | j         j        S Nr1   progr   s    r   r@   zParser.progA   s    ~""r   valuec                    || j         _        d S r>   r?   )r   rA   s     r   r@   zParser.progE   s    #r   optionArgumentc                T    | j         r|j        r|                      |           d S d S d S r>   )r.   dest)r   rC   s     r   processoptionzParser.processoptionI   sE     	){ )  (((((	) 	)) )r    namedescriptionafterr3   c                   | j         D ]}|j        |k    r|c S | j                            |p|          }t	          ||| d          }d}t          | j                   D ]\  }}|j        |k    r n| j                             |dz   |           | j        j                            |dz   | 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   )	r4   rI   r1   r2   r3   	enumerateinsert_action_groupspop)r   rI   rJ   rK   grouparggroupigrps           r   getgroupzParser.getgroupN   s     \ 	 	EzT!! " >44[5HDIIHdDDAAA-- 	 	FAsx5   !AE5))) 	%,,QUDN4Q4U4U4W4WXXXr   optsattrsr   c                *     | 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   rV   rW   s      r   rY   zParser.addoptionm   s$     	"!41511111r   args Sequence[str | os.PathLike[str]]	namespaceargparse.Namespace | Noneargparse.Namespacec                    ddl m}  || j                   d |D             }|t          j                    }	 d|_        | j                            ||          |`S # |`w xY 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                6    g | ]}t          j        |          S r   osfspath.0xs     r   
<listcomp>z Parser.parse.<locals>.<listcomp>        ...A29Q<<...r   NTr\   )r-   r`   r1   argparse	Namespace_raise_print_helpparse_intermixed_args)r   rZ   r\   r`   strargss        r   parsezParser.parse}   s     	988888'''..... *,,I	,*.I'>7797UU++	+++++s   "A A"c                <    |                      ||          d         S )zbParse the known arguments at this point.

        :returns: An argparse namespace object.
        rj   r   )parse_known_and_unknown_args)r   rZ   r\   s      r   parse_known_argszParser.parse_known_args   s"     000KKANNr   $tuple[argparse.Namespace, list[str]]c                   d |D             }t           j        dk     sdt           j        cxk    rdk     rqn nn| j                            ||          \  }}|J t	          |t
                    }g }|D ].}|                    d          r|n|                    |           /||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                6    g | ]}t          j        |          S r   rb   re   s     r   rh   z7Parser.parse_known_and_unknown_args.<locals>.<listcomp>   ri   r   )         )rw      )rw   rz   r   N-)	sysversion_infor1   rs   getattrr6   
startswithappendparse_known_intermixed_args)r   rZ   r\   ro   unknownr   unknown_flagsargs           r   rr   z#Parser.parse_known_and_unknown_args   s     /....j((Gs7G,T,T,T,T*,T,T,T,T,T!%!@!@)!T!TIw(((!)[99K')M T T"%.."5"5F;NNsSSSSm++>==gyQQQr   r   )aliaseshelptypeYLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool', 'int', 'float'] | Nonedefaultr   Sequence[str]c                  |dv sJ |d}|t           u rt          |          }|||f| j        |<   |D ]X}|| j        v rt          d|d          | j                            |          x}t          |d|          || j        |<   Yd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pathlistrZ   linelistr&   intfloatNr   zalias z- conflicts with existing configuration optionz is already an alias of )NOT_SETget_ini_default_for_typer8   
ValueErrorr9   get)r   rI   r   r   r   r   aliasalreadys           r   addinizParser.addini   s    n  

 

 

 

 

 <Dg.t44G#T73d 	, 	,E%% SUSSS    ,00777D E!P!PW!P!PQQQ'+De$$	, 	,r   )NN)r"   r#   r$   r%   r!   r&   r   r'   r   )rA   r   r   r'   )rC   rD   r   r'   )rH   N)rI   r   rJ   r   rK   r#   r   r3   rV   r   rW   r   r   r'   r>   )rZ   r[   r\   r]   r   r^   )rZ   r[   r\   r]   r   rt   )rI   r   r   r   r   r   r   r   r   r   r   r'   )r   r   r   __doc__r<   propertyr@   setterrG   rU   rY   rp   rs   rr   r   r   r   r   r   r   r      sv         !8</
  / / / / / /4 # # # X# 
[$ $ $ [$) ) ) ) EI    >2 2 2 2& 04, , , , ,6 04	O 	O 	O 	O 	O 04R R R R R@ P, "$P, P, P, P, P, P, P, P,r   r   r   RLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool', 'int', 'float']r   r   c                B    | 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   rZ   r   r&   Fr   r   r   g        rH   r   )r   s    r   r   r     sD     888		u	q	srr   c                  "    e Zd ZdZddZdd	Zd
S )ArgumentErrorzURaised if an Argument instance is created with invalid or
    inconsistent arguments.msgr   rC   Argument | strr   r'   c                <    || _         t          |          | _        d S r>   )r   r   	option_id)r   r   rC   s      r   r<   zArgumentError.__init__%  s    Vr   c                B    | j         rd| j          d| j         S | j        S )Nzoption : )r   r   r   s    r   __str__zArgumentError.__str__)  s-    > 	9T^99tx9998Or   N)r   r   rC   r   r   r'   r   )r   r   r   r   r<   r   r   r   r   r   r   !  sF         % % % %     r   r   c                  :    e Zd ZdZddZdd
ZddZddZddZdS )rD   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   rW   r   r   r'   c                   || _         g | _        g | _        	 |d         | _        n# t          $ r Y nw xY w	 |d         | _        n# t          $ r Y nw xY w|                     |           |                    d          }|r	|| _        dS | j        r0| j        d         dd         	                    dd          | _        dS 	 | j        d         d	d         | _        dS # t          $ r}d
| _        t          d|           |d}~ww xY w)z5Store params in private vars for use in add_argument.r   r   rF   r      Nr{   _r   z???zneed a long or short option)_attrs_short_opts
_long_optsr   KeyErrorr   _set_opt_stringsr   rF   replace
IndexErrorr   )r   r   rW   rF   es        r   r<   zArgument.__init__9  sK   &(%'	fDII 	 	 	D		 +DLL 	 	 	D	e$$$ 99V,, 		PDIII_ 	P*122.66sC@@DIIIP ,Q/3			 P P P!	#$A4HHaOPs5   % 
22A 
AAC 
D'C??D	list[str]c                     | j         | j        z   S r>   )r   r   r   s    r   r   zArgument.namesT  s    $/11r   Mapping[str, Any]c                ~    ddd| j         fD ]+}	 t          | |          | j        |<   # t          $ r Y (w xY w| j        S )Nr   rF   r   )rF   r~   r   AttributeError)r   attrs     r   rW   zArgument.attrsW  sb    	: 	 	D$+D$$7$7D!!!   {s   (
55rV   r   c                   |D ]}t          |          dk     rt          d|d|           t          |          dk    rG|d         dk    r|d         dk    st          d|d|           | j                            |           |dd         d	k    r|d         dk    st          d
|d|           | j                            |           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   r{   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   r   r   )r   rV   opts      r   r   zArgument._set_opt_strings`  s5   
  	, 	,C3xx!||#;S ; ; ;  
 SQA##a&C--'Hs H H H  
  '',,,,AaCD((SVs]]'Cc C C C  
 &&s++++-	, 	,r   c                   g }| j         r|dt          | j                   z   gz  }| j        r|dt          | j                  z   gz  }|dt          | j                  z   gz  }t	          | d          r|dt          | j                  z   gz  }t	          | d          r|dt          | j                  z   gz  }d                    d	                    |                    S )
Nz_short_opts: z_long_opts: zdest: r   ztype: r   z	default: zArgument({}), )	r   reprr   rF   hasattrr   r   formatjoin)r   rZ   s     r   r   zArgument.__repr__}  s     	?_tD,<'='==>>D? 	=^d4?&;&;;<<DDOO+,,4   	1XTY/00D4## 	7[4#5#5566D$$TYYt__555r   N)r   r   rW   r   r   r'   )r   r   )r   r   )rV   r   r   r'   r   )	r   r   r   r   r<   r   rW   r   r   r   r   r   rD   rD   0  s         P P P P62 2 2 2   , , , ,:6 6 6 6 6 6r   rD   c                  8    e Zd ZdZ	 dddZddZddZdddZdS )r3   z,A group of options shown in its own section.FrR   argparse._ArgumentGrouprI   r   parserParser | Noner!   r&   r   r'   c                \    t          |           || _        || _        g | _        || _        d S r>   )r   	_arggrouprI   optionsr   )r   rR   rI   r   r!   s        r   r<   zOptionGroup.__init__  s2     	y!!!!	')r   rV   rW   r   c                    t          |                              d | j        D                       }|rt          d| d          t	          |i |}|                     |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              3  H   K   | ]}|                                 D ]}|V  d S r>   )r   )rf   r   rI   s      r   	<genexpr>z(OptionGroup.addoption.<locals>.<genexpr>  sO       *
 *
SYY[[*
 *
-1D*
 *
 *
 *
 *
 *
 *
r   zoption names z already addedF
shortupperN)setintersectionr   r   rD   _addoption_instance)r   rV   rW   conflictrC   s        r   rY   zOptionGroup.addoption  s     t99)) *
 *
 L*
 *
 *
 
 
  	GEXEEEFFF4)5))  E :::::r   c                L    t          |i |}|                     |d           d S )NTr   )rD   r   )r   rV   rW   rC   s       r   
_addoptionzOptionGroup._addoption  s3    4)5))  D 99999r   rC   rD   r   c                j   |s?|j         D ]7}|d         dk    r)|d                                         rt          d          8| j        r| j                            |            | j        j        |                                i |                                 | j	        
                    |           d S )Nr   r{   r   zlowercase shortoptions reserved)r   islowerr   r   rG   r   r5   r   rW   r   r   )r   rC   r   r   s       r   r   zOptionGroup._addoption_instance  s     	H) H Hq6S==SV^^%5%5=$%FGGG; 	.K%%f---##V\\^^Fv||~~FFFF#####r   N)F)
rR   r   rI   r   r   r   r!   r&   r   r'   r   )rC   rD   r   r&   r   r'   )r   r   r   r   r<   rY   r   r   r   r   r   r3   r3     sy        66      ; ; ; ;,: : : :
$ 
$ 
$ 
$ 
$ 
$ 
$r   r3   c                  (     e Zd Zd fd	ZddZ xZS )r0   r   r   r"   r#   r/   dict[str, str]r   r'   c                z    || _         t                                          |dt          dd           || _        d S )NF@)r"   add_helpformatter_classallow_abbrevfromfile_prefix_chars)_parsersuperr<   DropShorterLongHelpFormatterr/   )r   r   r"   r/   	__class__s       r   r<   zPytestArgumentParser.__init__  sI     8"% 	 	
 	
 	
 %r   messager   r
   c           	        | j          d| }| j        rI|dd                    d t          | j                                                  D                       z   z  }t          |                                 |z             )z1Transform argparse error message into UsageError.z	: error: 
c              3  ,   K   | ]\  }}d | d| V  dS )z  r   Nr   )rf   kvs      r   r   z-PytestArgumentParser.error.<locals>.<genexpr>  sC       $ $"&!QQ!$ $ $ $ $ $r   )r@   r/   r   sorteditemsr   format_usage)r   r   r   s      r   errorzPytestArgumentParser.error  s    ..W..? 	4$)) $ $*01F1F1H1H*I*I$ $ $    C **,,s2333r   )r   r   r"   r#   r/   r   r   r'   )r   r   r   r
   )r   r   r   r<   r   __classcell__r   s   @r   r0   r0     sQ        % % % % % %$4 4 4 4 4 4 4 4r   r0   c                  6     e Zd ZdZd fdZd fdZd Z x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.
    rZ   r   kwargsr   r'   c                    d|vr!t           j                                        |d<    t                      j        |i | d S )Nwidth)_pytest_ioget_terminal_widthr   r<   )r   rZ   r   r   s      r   r<   z%DropShorterLongHelpFormatter.__init__  sG    &  %k<<>>F7O$)&)))))r   actionargparse.Actionr   c                   t                                          |          }|r|d         dk    r|S t          |dd           }|r|S |                    d          }t	          |          dk    r;t	          |d                   dk    st	          |d                   dk    r	||_        |S g }i }|D ]}t	          |          dk    s|d         dk    r"|                    d          st          d	| d
|          |dd          }|                    dd          }	|	|vs&t	          ||	                   t	          |          k     r|||	<   |D ]}t	          |          dk    s|d         dk    r|	                    |           |dd          |
                    |                    dd                    k    r*|	                    |                    ddd                     d                    |          }
|
|_        |
S )Nr   r{   _formatted_action_invocationr   r   r    r   z&long optional argument without "--": []rH   =)r   _format_action_invocationr~   splitr   r   r   r   r   r   r   r   )r   r   orgstrresr   return_list
short_longrC   xxoption	shortenedformatted_action_invocationr   s              r   r   z6DropShorterLongHelpFormatter._format_action_invocation  s<   226:: 	fQi3&&M!&*H$OO 	J,,t$$w<<1#gaj//Q"6"6#gaj//Q:N:N28F/M%'
 	1 	1F6{{a6!9#3#3$$T** #FVFFF   abbzH ((b11I
**c*Y2G.H.H3L L / / )1
9%  	@ 	@F6{{a6!9#3#3""6***abbzZ^^FNN3,C,CDDDD""6>>#sA#>#>???&*ii&<&<#.I+**r   c                    ddl }g }|                                D ]=}|                    |                    |                                |                     >|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lines         r   _split_linesz)DropShorterLongHelpFormatter._split_lines  s[    
 	OO%% 	= 	=DLLtzz||U;;<<<<r   )rZ   r   r   r   r   r'   )r   r   r   r   )r   r   r   r   r<   r   r  r   r   s   @r   r   r     su         * * * * * *$+ $+ $+ $+ $+ $+L
 
 
 
 
 
 
r   r   c                  0     e Zd ZdZ	 dd fdZddZ x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   rF   r   r,   int | str | None
ini_option	ini_valuer   r'   c               b     t                      j        ||dg|R i | || _        || _        d S )Nr   )r   r<   r  r  )	r   r  rF   r,   r  r  rZ   r   r   s	           r   r<   zOverrideIniAction.__init__(  sB     	qB4BBB6BBB$"r   r   argparse.ArgumentParserr\   r^   c                    t          || j        d           t          |dd           }|g }|                    | j         d| j                    t          |d|           d S )NToverride_inir   )setattrrF   r~   r   r  r  )r   r   r\   rZ   r   current_overridess         r   __call__zOverrideIniAction.__call__6  su     		49d+++#I~tDD$ "  DO!F!Fdn!F!FGGG	>+<=====r   r>   )r  r   rF   r   r,   r  r  r   r  r   r   r'   )r   r  r\   r^   r   r'   )r   r   r   r   r<   r  r   r   s   @r   r  r     se          #'	# # # # # # #> > > > > > > >r   r  )r   r   r   r   )#
__future__r   rk   collections.abcr   r   r   rc   r|   typingr   r   r	   r
   
exceptionsr   _pytest._ior   _pytest.deprecatedr   r6   r   r   r   r   	Exceptionr   rD   r3   ArgumentParserr0   HelpFormatterr   Actionr  r   r   r   <module>r)     s   " " " " " "  $ $ $ $ $ $ # # # # # # $ $ $ $ $ $ 				 



                         " " " " " "     - - - - - -        
 &(( i, i, i, i, i, i, i, i,X   *    I   X6 X6 X6 X6 X6 X6 X6 X6v4$ 4$ 4$ 4$ 4$ 4$ 4$ 4$n4 4 4 4 482 4 4 4:> > > > >8#9 > > >B"> "> "> "> "> "> "> "> "> ">r   