
    ?gRP                       S SK Jr  S SKrS SKJr  S SKrS SKrS SKJr  S SKJr  S SKJ	r	  S SKJ
r
  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SKrS SKJr  S SKJr  Sr " S S5      r\" 5       r\
 " S S5      5       r    SS jr " S S\5      r " S S5      r " S S5      r " S S\R>                  5      r  " S S\RB                  5      r"g)     )annotationsN)gettext)Any)Callable)cast)final)List)Literal)Mapping)NoReturn)Sequence)
UsageError)check_ispytestfile_or_dirc                      \ rS rSrSS jrSrg)NotSet   c                    g)Nz<notset> selfs    ;/usr/lib/python3/dist-packages/_pytest/config/argparsing.py__repr__NotSet.__repr__   s        r   Nreturnstr)__name__
__module____qualname____firstlineno__r   __static_attributes__r   r   r   r   r      s    r   r   c                     \ rS rSr% SrSrS\S'     SSS.       SS jjjrSS	 jr S       SS
 jjr	SS jr
 S     SS jjrSS jr S       SS jjr S     SS jjr S     SS jjrS\4         SS jjrSrg)Parser"   zParser 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	_ispytestc                   [        U5        [        SU SS9U l        / U l        X l        Xl        0 U l        / U l        0 U l        g )NzCustom optionsTparserr*   )	r   OptionGroup
_anonymous_groups_processopt_usage_inidict	_ininames
extra_info)r   usage
processoptr*   s       r   __init__Parser.__init__,   sD     	y!%&6ttT*,%@B$&*,r   c                n    U R                   (       a$  UR                  (       a  U R                  U5        g g g N)r1   dest)r   options     r   processoptionParser.processoption<   s*    {{  (  r   c                   U R                    H  nUR                  U:X  d  M  Us  $    [        XU SS9nSn[        U R                   5       H  u  pVUR                  U:X  d  M    O   U R                   R	                  US-   U5        U$ )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      )r0   namer.   	enumerateinsert)r   rB   descriptionaftergroupigrps          r   getgroupParser.getgroupA   s{     \\EzzT! " DddK-FAxx5  . 	AE5)r   c                <    U R                   R                  " U0 UD6  g)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   optsattrss      r   rM   Parser.addoption[   s     	!!4151r   c                    SSK Jn  U R                  5       U l        U" U R                  5        U Vs/ s H  n[        R
                  " U5      PM     nnU R                  R                  XRS9$ s  snf )Nr   )try_argcomplete	namespace)_pytest._argcompleterR   
_getparser	optparserosfspath
parse_args)r   argsrT   rR   xstrargss         r   parseParser.parsek   sZ    
 	9*')-.A299Q<.~~(((FF /s    A-c                   SSK Jn  [        X R                  U R                  S9n/ U R
                  QU R                  PnU H  nUR                  (       d  M  UR                  =(       d    UR                  nUR                  U5      nUR                   H5  nUR                  5       nUR                  5       n	UR                  " U0 U	D6  M7     M     UR                  [        SS9n
Xl        U$ )Nr   )filescompleter)r(   *)nargs)rU   ra   MyOptionParserr5   r(   r0   r/   optionsrE   rB   add_argument_groupnamesrO   add_argumentFILE_OR_DIR	completer)r   ra   rW   groupsrG   descarggroupr=   nafile_or_dir_args              r   rV   Parser._getparserw   s    7"4tyyI	14<<11E}}}((6EJJ$77=#mmFAA))122 ,	  $00C0H %3!r   c                    U R                  XS9nUR                  R                  5        H  u  pV[        X%U5        M     [	        [
        [           [        U[        5      5      $ )NrS   )	r^   __dict__itemssetattrr   r	   r   getattrri   )r   r[   r=   rT   parsedoptionrB   values          r   parse_setoptionParser.parse_setoption   sQ     zz$z<'00668KDF%( 9DIw|[ABBr   c                &    U R                  XS9S   $ )zRParse the known arguments at this point.

:returns: An argparse namespace object.
rS   r   )parse_known_and_unknown_args)r   r[   rT   s      r   parse_known_argsParser.parse_known_args   s     000KANNr   c                    U R                  5       nU Vs/ s H  n[        R                  " U5      PM     nnUR                  XRS9$ s  snf )zParse 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.
rS   )rV   rX   rY   r}   )r   r[   rT   rW   r\   r]   s         r   r|   #Parser.parse_known_and_unknown_args   sE     OO%	)-.A299Q<.))')GG /s    Ac                    US;   d   eU[         L a  [        U5      nX#U4U R                  U'   U R                  R	                  U5        g)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

    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pathlistr[   linelistboolN)NOT_SETget_ini_default_for_typer3   r4   append)r   rB   helptypedefaults        r   addiniParser.addini   sK    N XXXXg.t4G#73dd#r   )r/   r0   r3   r4   r1   r2   r5   rW   NN)r6   r'   r7   z!Callable[[Argument], None] | Noner*   r   r   None)r=   Argumentr   r    N)rB   r   rE   r   rF   r'   r   r.   rN   r   rO   r   r   r   r;   )r[    Sequence[str | os.PathLike[str]]rT   argparse.Namespace | Noner   argparse.Namespace)r   rd   )r[   r   r=   r   rT   r   r   	list[str])r[   r   rT   r   r   z$tuple[argparse.Namespace, list[str]])
rB   r   r   r   r   ILiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool'] | Noner   r   r   r   )r   r    r!   r"   __doc__r(   __annotations__r8   r>   rJ   rM   r^   rV   ry   r}   r|   r   r   r#   r   r   r   r%   r%   "   s    D* !8<-
  -- 6-
 - 
- ) EI&)7A	42& 04
G.
G -
G 
	
G. 04		C.	C #	C -		C
 
	C 04	O.	O -	O 
		O 04H.H -H 
.	H* ,$,$ ,$	,$ ,$ 
,$ ,$r   r%   c                *    U c  gU S;   a  / $ U S:X  a  gg)zd
Used by addini to get the default value for a given ini-option type, when
default is not supplied.
r   )r   r   r[   r   r   Fr   )r   s    r   r   r      s'     |	:	:		r   c                  ,    \ rS rSrSrSS jrSS jrSrg)	ArgumentError   zQRaised if an Argument instance is created with invalid or
inconsistent arguments.c                0    Xl         [        U5      U l        g r;   )msgr   	option_id)r   r   r=   s      r   r8   ArgumentError.__init__   s    Vr   c                t    U R                   (       a  SU R                    SU R                   3$ U R                  $ )Nzoption : )r   r   r   s    r   __str__ArgumentError.__str__   s.    >>T^^,Btxxj9988Or   )r   r   N)r   r   r=   zArgument | strr   r   r   )r   r    r!   r"   r   r8   r   r#   r   r   r   r   r      s    %r   r   c                  J    \ rS rSrSrS
S jrSS jrSS jrSS jrSS jr	Sr
g	)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
c                   X l         / U l        / U l         US   U l         US   U l        U R                  U5        UR                  S5      nU(       a  X0l        gU R                  (       a(  U R                  S   SS R                  SS5      U l        g U R                  S   S	S U l        g! [         a     Nf = f! [         a     Nf = f! [         a  nS
U l        [        SU 5      UeSnAff = f)z5Store params in private vars for use in add_argument.r   r   r<   r      N-_rA   z???zneed a long or short option)_attrs_short_opts
_long_optsr   KeyErrorr   _set_opt_stringsgetr<   replace
IndexErrorr   )r   rg   rO   r<   es        r   r8   Argument.__init__  s    &(%'	fDI	 +DL 	e$ 99V,I__*12.66sC@DIP ,,Q/3	  		
  		  P!	#$A4HaOPs:   
B- 
B= C -
B:9B:=
C
	C

C0C++C0c                4    U R                   U R                  -   $ r;   )r   r   r   s    r   rg   Argument.names#  s    $//11r   c                    SR                  5       nUR                  U R                  5        U H  n [        X5      U R                  U'   M     U R                  $ ! [
         a     M9  f = f)Nzdefault dest help)splitr   r<   rv   r   AttributeError)r   rO   attrs      r   rO   Argument.attrs&  sb    #))+TYYD$+D$7D! 
 {{ " s   A
A('A(c                p   U H  n[        U5      S:  a  [        SU< S3U 5      e[        U5      S:X  a@  US   S:X  a	  US   S:w  d  [        SU< S3U 5      eU R                  R                  U5        Mr  USS S	:X  a	  US   S:w  d  [        S
U< S3U 5      eU R                  R                  U5        M     g)zXDirectly 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   rA   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   rN   opts      r   r   Argument._set_opt_strings1  s    
 C3x!|#,SG 4; ; 
 SQA##a&C-'6sg >H H 
   '',AaD(SVs]'5cW =C C 
 &&s+- r   c                   / nU R                   (       a  US[        U R                   5      -   /-  nU R                  (       a  US[        U R                  5      -   /-  nUS[        U R                  5      -   /-  n[	        U S5      (       a  US[        U R
                  5      -   /-  n[	        U S5      (       a  US[        U R                  5      -   /-  nSR                  S	R                  U5      5      $ )
Nz_short_opts: z_long_opts: zdest: r   ztype: r   z	default: zArgument({}), )	r   reprr   r<   hasattrr   r   formatjoin)r   r[   s     r   r   Argument.__repr__N  s    _tD,<,<'==>>D??^d4??&;;<<DDO+,,4  XTYY/00D4##[4#5566D$$TYYt_55r   )r   r   r   r   r<   r   N)rg   r   rO   r   r   r   )r   r   )r   zMapping[str, Any])rN   zSequence[str]r   r   r   )r   r    r!   r"   r   r8   rg   rO   r   r   r#   r   r   r   r   r      s!    P62	,:6r   r   c                  f    \ rS rSrSr  SSS.         SS jjjrSS jrSS jrSSS	 jjrS
r	g)r.   i\  z,A group of options shown in its own section.NFr)   c               L    [        U5        Xl        X l        / U l        X0l        g r;   )r   rB   rE   re   r-   )r   rB   rE   r-   r*   s        r   r8   OptionGroup.__init___  s#     	y!	&')r   c                    [        U5      R                  S U R                   5       5      nU(       a  [        SU S35      e[	        U0 UD6nU R                  USS9  g)a  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  R   #    U  H  oR                  5         H  o"v   M     M     g 7fr;   )rg   ).0r   rB   s      r   	<genexpr>(OptionGroup.addoption.<locals>.<genexpr>{  s      *
(SYY[TD[DLs   %'zoption names z already addedF
shortupperN)setintersectionre   
ValueErrorr   _addoption_instance)r   rN   rO   conflictr=   s        r   rM   OptionGroup.addoptionm  sd     t9)) *
 LL*
 
 }XJnEFF4)5)  E :r   c                :    [        U0 UD6nU R                  USS9  g )NTr   )r   r   )r   rN   rO   r=   s       r   
_addoptionOptionGroup._addoption  s$    4)5)  D 9r   c                "   U(       dA  UR                    H1  nUS   S:X  d  M  US   R                  5       (       d  M(  [        S5      e   U R                  (       a  U R                  R	                  U5        U R
                  R                  U5        g )Nr   r   rA   zlowercase shortoptions reserved)r   islowerr   r-   r>   re   r   )r   r=   r   r   s       r   r   OptionGroup._addoption_instance  si    ))q6S=SV^^%5%5$%FGG * ;;KK%%f-F#r   )rE   rB   re   r-   r   )
rB   r   rE   r   r-   zParser | Noner*   r   r   r   r   )F)r=   r   r   r   r   r   )
r   r    r!   r"   r   r8   rM   r   r   r#   r   r   r   r.   r.   \  s`    6
  $	    	  
;,:$ $r   r.   c                     ^  \ rS rSr  S       S	U 4S jjjrS
S jr  S     SS jjr\R                  S:  a      SS jr	Sr
U =r$ Sr
U =r$ )rd   i  c           	     |   > Xl         [        TU ]	  UUR                  S[        SSS9  U(       a  X l        g 0 U l        g )NF@)r(   r6   add_helpformatter_classallow_abbrevfromfile_prefix_chars)_parsersuperr8   r2   DropShorterLongHelpFormatterr5   )r   r-   r5   r(   	__class__s       r   r8   MyOptionParser.__init__  sA     --8"% 	 	
 )3*r   c                    U R                    SU 3n[        U R                  S5      (       a  U SU R                  R                   S3n[	        U R                  5       U-   5      e)z1Transform argparse error message into UsageError.z	: error: _config_source_hintz ())r(   r   r   r   r   format_usage)r   messager   s      r   errorMyOptionParser.error  s^    9WI.4<<!677EDLL<<=Q?C**,s233r   c                   U R                  X5      u  p4U(       a  U H  nU(       d  M  US   S:X  d  M  SR                  SR                  U5      5      /n[        U R                  R                  5       5       H  u  pxUR                  SU SU 35        M     U R                  SR                  U5      5        M     [        U[        5      R                  U5        U$ )z(Allow splitting of positional arguments.r   r   zunrecognized arguments: {} z  r   
)r}   r   r   sortedr5   rt   r   r   rv   ri   extend)	r   r[   rT   parsedunrecognizedarglineskvs	            r   rZ   MyOptionParser.parse_args  s      $44TE#33q6S=4;;CHH\<RSE !'t'<'<'> ?r!Bqc]3 !@JJtyy/0 $ FK(//=r   )   	   c                   U(       d  g US   U R                   ;  a  g XR                  ;   a  U R                  U   nX!S 4$ [        U5      S:X  a  g SU;   a6  UR                  SS5      u  p4X0R                  ;   a  U R                  U   nX#U4$ U R                  (       d  UR                  S5      (       do  U R                  U5      n[        U5      S:  a:  [        S5      nSR                  S U 5       5      nU R                  XaUS.-  5        O[        U5      S:X  a  Uu  nU$ U R                  R                  U5      (       a  U R                  (       d  g S	U;   a  g S US 4$ )
Nr   rA   =r   z4ambiguous option: %(option)s could match %(matches)sr   c              3  *   #    U  H	  u  pov   M     g 7fr;   r   )r   r   r=   s      r   r   1MyOptionParser._parse_optional.<locals>.<genexpr>  s     'Q=<1a=s   )r=   matchesr   )prefix_chars_option_string_actionsr   r   r   
startswith_get_option_tuplesr   r   r   _negative_number_matchermatch_has_negative_number_optionals)	r   
arg_stringactionoption_stringexplicit_argoption_tuplesr   re   option_tuples	            r   _parse_optionalMyOptionParser._parse_optional  s[    !}D$5$5588844Z@4//:!#j .8.>.>sA.F+ $?$??!88GF!,>>  
(=(=d(C(C $ 7 7
 C}%)!NC #ii'Q='QQGJJsw%OOP'1,&3O\'',,22:>>::j T))r   )r   r5   r   )r-   r%   r5   zdict[str, Any] | Noner(   r'   r   r   )r   r   r   r   )r[   zSequence[str] | NonerT   r   r   r   )r  r   r   z5tuple[argparse.Action | None, str, str | None] | None)r   r    r!   r"   r8   r   rZ   sysversion_infor  r#   __classcell__r   s   @r   rd   rd     s     -1	;; *; 	;
 
; ;&4 &*/3" - 
	& & !	*!!	*B!	* !	* !r   rd   c                  F   ^  \ rS rSrSrSU 4S jjrSU 4S jjrS rSrU =r	$ )	r   i  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.
c                t   > SU;  a!  [         R                  R                  5       US'   [        TU ]  " U0 UD6  g )Nwidth)_pytest_ioget_terminal_widthr   r8   )r   r[   kwargsr   s      r   r8   %DropShorterLongHelpFormatter.__init__  s3    & %kk<<>F7O$)&)r   c                J  > [         TU ]  U5      nU(       a  US   S:w  a  U$ [        USS 5      nU(       a  U$ UR                  S5      n[	        U5      S:X  a,  [	        US   5      S:X  d  [	        US   5      S:X  a  X!l        U$ / n0 nU H  n[	        U5      S:X  d	  US   S:X  a  M  UR                  S5      (       d  [        S	U S
3U5      eUSS  nUR                  SS5      n	X;  d  [	        Xi   5      [	        U5      :  d  M{  XU	'   M     U Hx  n[	        U5      S:X  d	  US   S:X  a  UR                  U5        USS  UR                  UR                  SS5      5      :X  d  MV  UR                  UR                  SSS5      5        Mz     SR                  U5      n
Xl        U
$ )Nr   r   _formatted_action_invocationr   r   rA   r   r   z&long optional argument without "--": []r   r  )r   _format_action_invocationrv   r   r   r#  r	  r   r   r   r   r   )r   r  orgstrresre   return_list
short_longr=   xxoption	shortenedformatted_action_invocationr   s              r   r%  6DropShorterLongHelpFormatter._format_action_invocation  s   26:fQi3&M!&*H$OJ,,t$w<1#gaj/Q"6#gaj/Q:N28/M%'
F6{a6!9#3$$T**#<VHAF  abzH ((b1I*c*2G.H3L / )19%  F6{a6!9#3""6*abzZ^^FNN3,CDD""6>>#sA#>?	 
 '+ii&<#.I+**r   c                    SSK n/ nUR                  5        H2  nUR                  UR                  UR	                  5       U5      5        M4     U$ )zmWrap 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_lines)DropShorterLongHelpFormatter._split_lines  s?    
 	OO%DLLtzz|U;< &r   r   )r[   r   r   r   r   r   )r  zargparse.Actionr   r   )
r   r    r!   r"   r   r8   r%  r5  r#   r  r  s   @r   r   r     s    *$+L
 
r   r   )r   r   r   r   )#
__future__r   argparser   rX   r  typingr   r   r   r   r	   r
   r   r   r   _pytest._ior  _pytest.config.exceptionsr   _pytest.deprecatedr   ri   r   r   r%   r   	Exceptionr   r   r.   ArgumentParserrd   HelpFormatterr   r   r   r   <module>r@     s    "   	 
           0 -  
 ( y$ y$ y$x
S"I Z6 Z6z2$ 2$jU*X,, U*p>8#9#9 >r   