
    BhJ                       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 y)    )annotationsN)Callable)Mapping)Sequence)Any)cast)final)Literal)NoReturn)
UsageError)check_ispytestfile_or_dirc                      e Zd ZddZy)NotSetc                     y)Nz<notset> selfs    d/var/www/html/Telegram-Engagement-Pod-/env/lib/python3.12/site-packages/_pytest/config/argparsing.py__repr__zNotSet.__repr__   s        Nreturnstr)__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	 	 	 	 	 	 	 ddZddZ	 d	 	 	 	 	 	 	 dd	Zdd
Z		 d	 	 	 	 	 ddZ
ddZ	 d	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZdef	 	 	 	 	 	 	 	 	 ddZy)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	_ispytestc                   t        |       t        d| d      | _        g | _        || _        || _        i | _        g | _        i | _        y )NzCustom optionsTparserr#   )	r   OptionGroup
_anonymous_groups_processopt_usage_inidict	_ininames
extra_info)r   usage
processoptr#   s       r   __init__zParser.__init__)   sH     	y!%&6ttT*,%@B$&*,r   c                Z    | j                   r|j                  r| j                  |       y y y N)r*   dest)r   options     r   processoptionzParser.processoption9   s*    {{  (  r   c                
   | j                   D ]  }|j                  |k(  s|c S  t        ||| d      }d}t        | j                         D ]  \  }}|j                  |k(  s n | j                   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)   namer'   	enumerateinsert)r   r9   descriptionaftergroupigrps          r   getgroupzParser.getgroup>   s     \\EzzT! " D+ddK-FAsxx5  . 	AE5)r   c                <     | j                   j                  |i | y)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   rC   zParser.addoptionX   s     	"!!4151r   c                    ddl m} | j                         | _         || j                         |D cg c]  }t	        j
                  |       }}| j                  j                  ||      S c c}w )Nr   )try_argcomplete	namespace)_pytest._argcompleterG   
_getparser	optparserosfspath
parse_args)r   argsrI   rG   xstrargss         r   parsezParser.parseh   s\    
 	9*')-.A299Q<.~~((I(FF /s   A-c                   ddl m} t        | | j                  | j                        }g | j
                  | j                  }|D ]}  }|j                  s|j                  xs |j                  }|j                  |      }|j                  D ]4  }|j                         }|j                         }	 |j                  |i |	 6  |j                  t        d      }
||
_        |S )Nr   )filescompleter)r!   *)nargs)rJ   rU   MyOptionParserr.   r!   r)   r(   optionsr<   r9   add_argument_groupnamesrE   add_argumentFILE_OR_DIR	completer)r   rU   rL   groupsr>   descarggroupr5   nafile_or_dir_args              r   rK   zParser._getparsert   s    7"4tyyI	14<<11E}}((6EJJ$77=#mmFAA)H))122 ,	  $00C0H %3!r   c                    | j                  ||      }|j                  j                         D ]  \  }}t        |||        t	        t
        t           t        |t                    S )NrH   )	rS   __dict__itemssetattrr   listr   getattrr]   )r   rP   r5   rI   parsedoptionr9   values          r   parse_setoptionzParser.parse_setoption   sW     zz$)z<'00668KD%FD%( 9DIw|[ABBr   c                .    | j                  ||      d   S )zbParse the known arguments at this point.

        :returns: An argparse namespace object.
        rH   r   )parse_known_and_unknown_args)r   rP   rI   s      r   parse_known_argszParser.parse_known_args   s     000KANNr   c                    | j                         }|D cg c]  }t        j                  |       }}|j                  ||      S c c}w )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.
        rH   )rK   rM   rN   rp   )r   rP   rI   rL   rQ   rR   s         r   ro   z#Parser.parse_known_and_unknown_args   sG     OO%	)-.A299Q<.))'Y)GG /s   Ac                    |dv sJ |t         u rt        |      }|||f| j                  |<   | j                  j	                  |       y)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pathlistrP   linelistboolintfloatN)NOT_SETget_ini_default_for_typer,   r-   append)r   r9   helptypedefaults        r   addinizParser.addini   sW    ^  

 

 
	
 

 g.t4G#T73dd#r   NN)r/   r    r0   z!Callable[[Argument], None] | Noner#   rw   r   None)r5   Argumentr   r    N)r9   r   r<   r   r=   r    r   r'   rD   r   rE   r   r   r   r3   )rP    Sequence[str | os.PathLike[str]]rI   argparse.Namespace | Noner   argparse.Namespace)r   rX   )rP   r   r5   r   rI   r   r   	list[str])rP   r   rI   r   r   z$tuple[argparse.Namespace, list[str]])
r9   r   r}   r   r~   YLiteral['string', 'paths', 'pathlist', 'args', 'linelist', 'bool', 'int', 'float'] | Noner   r   r   r   )r   r   r   __doc__r!   __annotations__r1   r6   rA   rC   rS   rK   rm   rp   ro   rz   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                :    | y| dv rg S | dk(  ry| dk(  ry| dk(  ryy)	zp
    Used by addini to get the default value for a given ini-option type, when
    default is not supplied.
    r   )rt   ru   rP   rv   rw   Frx   r   ry   g        r   )r~   s    r   r{   r{      s;     |	:	:				r   c                       e Zd ZdZddZddZy)ArgumentErrorzURaised if an Argument instance is created with invalid or
    inconsistent arguments.c                2    || _         t        |      | _        y r3   )msgr   	option_id)r   r   r5   s      r   r1   zArgumentError.__init__
  s    Vr   c                j    | j                   rd| j                    d| j                   S | j                  S )Nzoption : )r   r   r   s    r   __str__zArgumentError.__str__  s.    >>T^^,Btxxj9988Or   N)r   r   r5   zArgument | strr   r   r   )r   r   r   r   r1   r   r   r   r   r   r     s    %r   r   c                  8    e Zd ZdZddZd	dZd
dZddZddZy)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                   || _         g | _        g | _        	 |d   | _        	 |d   | _        | j                  |       |j                  d      }|r|| _        y| j                  r(| j                  d   dd j                  dd      | _        y	 | j                  d   d	d | _        y# t        $ r Y w xY w# t        $ r Y w xY w# t        $ r}d
| _        t        d|       |d}~ww xY w)z5Store params in private vars for use in add_argument.r~   r   r4   r      N-_r8   z???zneed a long or short option)_attrs_short_opts
_long_optsr~   KeyErrorr   _set_opt_stringsgetr4   replace
IndexErrorr   )r   r[   rE   r4   es        r   r1   zArgument.__init__  s    &(%'	fDI	 +DL 	e$ 99V,DI__*12.66sC@DIP ,,Q/3	  		
  		  P!	#$A4HaOPs:   
B% 
B4 C %	B10B14	C ?C 	C%C  C%c                4    | j                   | j                  z   S r3   )r   r   r   s    r   r[   zArgument.names9  s    $//11r   c                    dj                         }|j                  | j                         |D ]  }	 t        | |      | j                  |<    | j                  S # t
        $ r Y 6w xY w)Nzdefault dest help)splitr|   r4   rj   r   AttributeError)r   rE   attrs      r   rE   zArgument.attrs<  sd    #))+TYYD$+D$$7D! 
 {{ " s   A	A%$A%c                X   |D ]  }t        |      dk  rt        d|d|       t        |      dk(  r<|d   dk(  r|d   dk7  st        d|d|       | j                  j                  |       k|dd d	k(  r|d   dk7  st        d
|d|       | j                  j                  |        y)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   r8   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   rD   opts      r   r   zArgument._set_opt_stringsG  s    
 C3x!|#,SG 4; ; 
 SQA##a&C-'6sg >H H 
   '',AaD(SVs]'5cW =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j                  d	j                  |            S )
Nz_short_opts: z_long_opts: zdest: r~   ztype: r   z	default: zArgument({}), )	r   reprr   r4   hasattrr~   r   formatjoin)r   rP   s     r   r   zArgument.__repr__d  s    _tD,<,<'==>>D??^d4??&;;<<DDO+,,4 XTYY/00D4#[4#5566D$$TYYt_55r   N)r[   r   rE   r   r   r   )r   r   )r   zMapping[str, Any])rD   zSequence[str]r   r   r   )	r   r   r   r   r1   r[   rE   r   r   r   r   r   r   r     s!    P62	,:6r   r   c                  P    e Zd ZdZ	 	 d	dd	 	 	 	 	 	 	 	 	 d
dZddZddZdddZy)r'   z,A group of options shown in its own section.NFr"   c               R    t        |       || _        || _        g | _        || _        y r3   )r   r9   r<   rY   r&   )r   r9   r<   r&   r#   s        r   r1   zOptionGroup.__init__u  s)     	y!	&')r   c                    t        |      j                  d | j                  D              }|rt        d| d      t	        |i |}| j                  |d       y)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  J   K   | ]  }|j                         D ]  }|   y wr3   )r[   ).0r   r9   s      r   	<genexpr>z(OptionGroup.addoption.<locals>.<genexpr>  s"      *
(SSYY[TD[DLs   !#zoption names z already addedF
shortupperN)setintersectionrY   
ValueErrorr   _addoption_instance)r   rD   rE   conflictr5   s        r   rC   zOptionGroup.addoption  sd     t9)) *
 LL*
 
 }XJnEFF4)5)  E :r   c                @    t        |i |}| j                  |d       y )NTr   )r   r   )r   rD   rE   r5   s       r   
_addoptionzOptionGroup._addoption  s$    4)5)  D 9r   c                    |s8|j                   D ])  }|d   dk(  s|d   j                         s t        d       | j                  r| j                  j	                  |       | j
                  j                  |       y )Nr   r   r8   zlowercase shortoptions reserved)r   islowerr   r&   r6   rY   r|   )r   r5   r   r   s       r   r   zOptionGroup._addoption_instance  sf    ))q6S=SV^^%5$%FGG * ;;KK%%f-F#r   r   )
r9   r   r<   r   r&   zParser | Noner#   rw   r   r   r   )F)r5   r   r   rw   r   r   )r   r   r   r   r1   rC   r   r   r   r   r   r'   r'   r  s[    6
  $	    	  
;,:$r   r'   c                  T     e Zd Z	 	 d	 	 	 	 	 	 	 d fdZddZ	 	 d	 	 	 	 	 ddZ xZS )rX   c                |    || _         t        | 	  ||j                  dt        dd       |r|| _        y i | _        y )NF@)r!   r/   add_helpformatter_classallow_abbrevfromfile_prefix_chars)_parsersuperr1   r+   DropShorterLongHelpFormatterr.   )r   r&   r.   r!   	__class__s       r   r1   zMyOptionParser.__init__  sE     --8"% 	 	
 )3*r   c                    | j                    d| }t        | j                  d      r| d| j                  j                   d}t	        | j                         |z         )z1Transform argparse error message into UsageError.z	: error: _config_source_hintz ())r!   r   r   r   r   format_usage)r   messager   s      r   errorzMyOptionParser.error  s[    9WI.4<<!67EDLL<<=Q?C**,s233r   c                   | j                  ||      \  }}|r|D ]  }|s|d   dk(  sdj                  dj                  |            g}t        | j                  j                               D ]  \  }}|j                  d| d|         | j                  dj                  |              t        |t              j                  |       |S )z(Allow splitting of positional arguments.r   r   zunrecognized arguments: {} z  r   
)rp   r   r   sortedr.   rg   r|   r   rj   r]   extend)	r   rP   rI   parsedunrecognizedarglineskvs	            r   rO   zMyOptionParser.parse_args  s      $44T9E#3q6S=4;;CHH\<RSE !'t'<'<'> ?1r!Bqc]3 !@JJtyy/0 $ FK(//=r   r   )r&   r   r.   zdict[str, Any] | Noner!   r    r   r   )r   r   r   r   )rP   zSequence[str] | NonerI   r   r   r   )r   r   r   r1   r   rO   __classcell__r   s   @r   rX   rX     sd     -1	;; *; 	;
 
;&4 &*/3" - 
	r   rX   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.
    c                n    d|vr!t         j                  j                         |d<   t        |   |i | y )Nwidth)_pytest_ioget_terminal_widthr   r1   )r   rP   kwargsr   s      r   r1   z%DropShorterLongHelpFormatter.__init__  s3    & %kk<<>F7O$)&)r   c                   t         |   |      }|r
|d   dk7  r|S t        |dd       }|r|S |j                  d      }t	        |      dk(  r+t	        |d         dk(  st	        |d         dk(  r	||_        |S g }i }|D ]u  }t	        |      dk(  s|d   dk(  r|j                  d      st        d	| d
|      |dd  }|j                  dd      }	|	|vst	        ||	         t	        |      k  sq|||	<   w |D ]s  }t	        |      dk(  s|d   dk(  r|j                  |       |dd  |j                  |j                  dd            k(  sR|j                  |j                  ddd             u dj                  |      }
|
|_        |
S )Nr   r   _formatted_action_invocationr   r   r8   r   r   z&long optional argument without "--": []r   =)r   _format_action_invocationrj   r   r   r   
startswithr   r   r|   r   r   )r   actionorgstrresrY   return_list
short_longr5   xxoption	shortenedformatted_action_invocationr   s              r   r   z6DropShorterLongHelpFormatter._format_action_invocation  s   26:fQi3&M!&*H$OJ,,t$w<1#gaj/Q"6#gaj/Q:N28F/M%'
F6{a6!9#3$$T*#<VHAF  abzH ((b1I
*c*Y2G.H3L / )1
9%  F6{a6!9#3""6*abzZ^^FNN3,CDD""6>>#sA#>?	 
 '+ii&<#.I+**r   c                    ddl }g }|j                         D ]1  }|j                  |j                  |j	                         |             3 |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   )rP   r   r   r   r   r   )r   zargparse.Actionr   r   )r   r   r   r   r1   r   r   r   r   s   @r   r   r     s    *$+L
r   r   )r~   r   r   r   )!
__future__r   argparsecollections.abcr   r   r   rM   typingr   r   r	   r
   r   _pytest._ior   _pytest.config.exceptionsr   _pytest.deprecatedr   r]   r   rz   r   r{   	Exceptionr   r   r'   ArgumentParserrX   HelpFormatterr   r   r   r   <module>r
     s    "  $ # $ 	       0 -  
 ( K$ K$ K$\
 	0I Z6 Z6z2$ 2$j/X,, /d>8#9#9 >r   