
    F-PhxJ                       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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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 dS )"    )annotationsN)Callable)Mapping)Sequence)Any)cast)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    Y/var/www/html/test/jupyter/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U dZdZded<   	 	 d/ddd0dZd1dZ	 d2d3dZd4dZ		 d5d6d"Z
d7d$Z	 d5d8d&Z	 d5d6d'Z	 d5d9d)Zdefd:d.ZdS );ParserzParser 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
str | NoneprogF	_ispytestusage
processopt!Callable[[Argument], None] | Noner#   boolr   Nonec                   t          |           t          d| d          | _        g | _        || _        || _        i | _        g | _        i | _        d S )NzCustom optionsTparserr#   )	r   OptionGroup
_anonymous_groups_processopt_usage_inidict	_ininames
extra_info)r   r$   r%   r#   s       r   __init__zParser.__init__)   sX     	y!!!%&6ttTTT*,%@B$&*,r   optionArgumentc                T    | j         r|j        r|                      |           d S d S d S N)r/   dest)r   r5   s     r   processoptionzParser.processoption9   sE     	){ )  (((((	) 	)) )r    namer   descriptionafterr,   c                    | j         D ]}|j        |k    r|c S t          ||| d          }d}t          | j                   D ]\  }}|j        |k    r n| j                             |dz   |           |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,   	enumerateinsert)r   r<   r=   r>   groupigrps          r   getgroupzParser.getgroup>   s     \ 	 	EzT!! "D+ddKKK-- 	 	FAsx5   !AE5)))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   rG   rH   s      r   rJ   zParser.addoptionX   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             }| j                            ||          S )Nr   )try_argcompletec                6    g | ]}t          j        |          S r   osfspath.0xs     r   
<listcomp>z Parser.parse.<locals>.<listcomp>q        ...A29Q<<...r   rM   )_pytest._argcompleterQ   
_getparser	optparser
parse_args)r   rK   rM   rQ   strargss        r   parsezParser.parseh   sg    
 	988888**'''.....~((I(FFFr   MyOptionParserc                   ddl m} t          | | j        | j                  }g | j        | j        }|D ]k}|j        rb|j        p|j	        }|
                    |          }|j        D ]7}|                                }|                                }	 |j        |i |	 8l|                    t          d          }
||
_        |S )Nr   )filescompleter)r!   *)nargs)r\   rd   rb   r3   r!   r.   r-   optionsr=   r<   add_argument_groupnamesrH   add_argumentFILE_OR_DIR	completer)r   rd   r^   groupsrC   descarggroupr5   nafile_or_dir_args              r   r]   zParser._getparsert   s    777777"4tyIII	14<11 	3 	3E} 3(6EJ$77==#m 3 3FAA)H)122222#00C0HH %3!r   	list[str]c                    |                      ||          }|j                                        D ]\  }}t          |||           t	          t
          t                   t          |t                              S )Nr[   )	ra   __dict__itemssetattrr   listr   getattrrk   )r   rK   r5   rM   parsedoptionr<   values          r   parse_setoptionzParser.parse_setoption   sn     zz$)z<<'06688 	) 	)KD%FD%((((DIw|[AABBBr   c                <    |                      ||          d         S )zbParse the known arguments at this point.

        :returns: An argparse namespace object.
        r[   r   )parse_known_and_unknown_args)r   rK   rM   s      r   parse_known_argszParser.parse_known_args   s"     000KKANNr   $tuple[argparse.Namespace, list[str]]c                p    |                                  }d |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                6    g | ]}t          j        |          S r   rS   rV   s     r   rY   z7Parser.parse_known_and_unknown_args.<locals>.<listcomp>   rZ   r   r[   )r]   r   )r   rK   rM   r^   r`   s        r   r~   z#Parser.parse_known_and_unknown_args   s?     OO%%	.....))'Y)GGGr   helptypeILiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool'] | Nonedefaultc                    |dv sJ |t           u rt          |          }|||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
                * ``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 ini-file.
            In case the execution is happening without an ini-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 an ini-file.

            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pathlistrK   linelistr'   intfloatN)NOT_SETget_ini_default_for_typer1   r2   append)r   r<   r   r   r   s        r   addinizParser.addini   sj    Z  

 

 

 

 

 g.t44G#T73dd#####r   NN)r$   r    r%   r&   r#   r'   r   r(   )r5   r6   r   r(   r;   N)r<   r   r=   r   r>   r    r   r,   rG   r   rH   r   r   r(   r8   )rK   rL   rM   rN   r   rO   )r   rb   )rK   rL   r5   rO   rM   rN   r   rs   )rK   rL   rM   rN   r   r   )
r<   r   r   r   r   r   r   r   r   r(   )r   r   r   __doc__r!   __annotations__r4   r:   rF   rJ   ra   r]   r|   r   r~   r   r   r   r   r   r   r      sl          D !8<-
  - - - - - - ) ) ) ) EI    42 2 2 2& 04
G 
G 
G 
G 
G   . 04		C 	C 	C 	C 	C 04	O 	O 	O 	O 	O 04H H H H H* <$ <$ <$ <$ <$ <$ <$r   r   r   YLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool', 'int', 'float'] | Noner   r   c                J    | dS | dv rg S | dk    rdS | dk    rdS | dk    rd	S dS )
zp
    Used by addini to get the default value for a given ini-option type, when
    default is not supplied.
    Nr;   )r   r   rK   r   r'   Fr   r   r   g        r   )r   s    r   r   r      sN     |r	:	:	:		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   r5   Argument | strr   r(   c                <    || _         t          |          | _        d S r8   )r   r   	option_id)r   r   r5   s      r   r4   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   r5   r   r   r(   r   )r   r   r   r   r4   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 )r6   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
    ri   r   rH   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   r9   r      N-_r@   z???zneed a long or short option)_attrs_short_opts
_long_optsr   KeyErrorr   _set_opt_stringsgetr9   replace
IndexErrorr   )r   ri   rH   r9   es        r   r4   zArgument.__init__  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rs   c                     | j         | j        z   S r8   )r   r   r   s    r   ri   zArgument.names7  s    $/11r   Mapping[str, Any]c                    d                                 }|                    | j                   |D ]+}	 t          | |          | j        |<   # t
          $ r Y (w xY w| j        S )Nzdefault dest help)splitr   r9   ry   r   AttributeError)r   rH   attrs      r   rH   zArgument.attrs:  s|    #))++TY 	 	D$+D$$7$7D!!!   {s   A
AArG   Sequence[str]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   rG   opts      r   r   zArgument._set_opt_stringsE  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   r9   hasattrr   r   formatjoin)r   rK   s     r   r   zArgument.__repr__b  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)ri   r   rH   r   r   r(   )r   rs   )r   r   )rG   r   r   r(   r   )	r   r   r   r   r4   ri   rH   r   r   r   r   r   r6   r6     s         P P P P62 2 2 2	 	 	 	, , , ,:6 6 6 6 6 6r   r6   c                  @    e Zd ZdZ	 	 dddddZddZddZdddZdS )r,   z,A group of options shown in its own section.r;   NFr"   r<   r   r=   r+   Parser | Noner#   r'   r   r(   c               \    t          |           || _        || _        g | _        || _        d S r8   )r   r<   r=   rg   r+   )r   r<   r=   r+   r#   s        r   r4   zOptionGroup.__init__s  s3     	y!!!	&')r   rG   rH   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 r8   )ri   )rW   r   r<   s      r   	<genexpr>z(OptionGroup.addoption.<locals>.<genexpr>  sO       *
 *
SYY[[*
 *
-1D*
 *
 *
 *
 *
 *
 *
r   zoption names z already addedF
shortupperN)setintersectionrg   
ValueErrorr6   _addoption_instance)r   rG   rH   conflictr5   s        r   rJ   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   )r6   r   )r   rG   rH   r5   s       r   
_addoptionzOptionGroup._addoption  s3    4)5))  D 99999r   r5   r6   r   c                    |s?|j         D ]7}|d         dk    r)|d                                         rt          d          8| j        r| j                            |           | j                            |           d S )Nr   r   r@   zlowercase shortoptions reserved)r   islowerr   r+   r:   rg   r   )r   r5   r   r   s       r   r   zOptionGroup._addoption_instance  s     	H) H Hq6S==SV^^%5%5=$%FGGG; 	.K%%f---F#####r   r   )
r<   r   r=   r   r+   r   r#   r'   r   r(   r   )F)r5   r6   r   r'   r   r(   )r   r   r   r   r4   rJ   r   r   r   r   r   r,   r,   p  s        66
  $	       ; ; ; ;,: : : :$ $ $ $ $ $ $r   r,   c                  <     e Zd Z	 	 dd fd
ZddZ	 	 dddZ xZS )rb   Nr+   r   r3   dict[str, Any] | Noner!   r    r   r(   c                    || _         t                                          ||j        dt          dd           |r|ni | _        d S )NF@)r!   r$   add_helpformatter_classallow_abbrevfromfile_prefix_chars)_parsersuperr4   r0   DropShorterLongHelpFormatterr3   )r   r+   r3   r!   	__class__s       r   r4   zMyOptionParser.__init__  sW     -8"% 	 	
 	
 	
 )3:**r   messager   r   c                    | j          d| }t          | j        d          r| d| j        j         d}t	          |                                 |z             )z1Transform argparse error message into UsageError.z	: error: _config_source_hintz ())r!   r   r   r   r   format_usage)r   r   r   s      r   errorzMyOptionParser.error  sg    ..W..4<!677 	@??DL<???C**,,s2333r   rK   Sequence[str] | NonerM   rN   rO   c                   |                      ||          \  }}|r|D ]}|r|d         dk    rd                    d                    |                    g}t          | j                                                  D ] \  }}|                    d| d|            !|                     d                    |                     t          |t                    
                    |           |S )z(Allow splitting of positional arguments.r   r   zunrecognized arguments: {} z  r   
)r   r   r   sortedr3   rv   r   r   ry   rk   extend)	r   rK   rM   parsedunrecognizedarglineskvs	            r   r_   zMyOptionParser.parse_args  s      $44T9EE 		># 1 1 13q6S==4;;CHH\<R<RSSE !'t'<'<'>'> ? ? 4 41]!]]q]]3333JJtyy//000FK((//===r   r   )r+   r   r3   r   r!   r    r   r(   )r   r   r   r   )rK   r   rM   rN   r   rO   )r   r   r   r4   r   r_   __classcell__r   s   @r   rb   rb     s         -1	; ; ; ; ; ; ;&4 4 4 4 &*/3        r   rb   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.
    rK   r   kwargsr   r(   c                    d|vr!t           j                                        |d<    t                      j        |i | d S )Nwidth)_pytest_ioget_terminal_widthr   r4   )r   rK   r   r   s      r   r4   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   r   z&long optional argument without "--": []r;   =)r   _format_action_invocationry   r   r   r   
startswithr   r   r   r   r   )r   r   orgstrresrg   return_list
short_longr5   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
splitlinesr   wrapstrip)r   textr   r	  r   lines         r   _split_linesz)DropShorterLongHelpFormatter._split_lines  s[    
 	OO%% 	= 	=DLLtzz||U;;<<<<r   )rK   r   r   r   r   r(   )r   r   r   r   )r   r   r   r   r4   r   r  r   r   s   @r   r   r     su         * * * * * *$+ $+ $+ $+ $+ $+L
 
 
 
 
 
 
r   r   )r   r   r   r   )!
__future__r   argparsecollections.abcr   r   r   rT   typingr   r   r	   r
   r   _pytest._ior   _pytest.config.exceptionsr   _pytest.deprecatedr   rk   r   r   r   r   	Exceptionr   r6   r,   ArgumentParserrb   HelpFormatterr   r   r   r   <module>r     s_   " " " " " "  $ $ $ $ $ $ # # # # # # $ $ $ $ $ $ 				                                   0 0 0 0 0 0 - - - - - -        
 &(( I$ I$ I$ I$ I$ I$ I$ I$X   0    I   Z6 Z6 Z6 Z6 Z6 Z6 Z6 Z6z2$ 2$ 2$ 2$ 2$ 2$ 2$ 2$j/ / / / /X, / / /d> > > > >8#9 > > > > >r   