HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pip/_vendor/pyparsing/__pycache__/testing.cpython-310.pyc
o

@%NeL4�@sFddlmZddlmZddlmZmZmZmZm	Z	Gdd�d�Z
dS)�)�contextmanager)�Optional�)�
ParserElement�ParseException�Keyword�__diag__�
__compat__c@sxeZdZdZGdd�d�ZGdd�d�Ze						dd	ed
ee	dee	de
d
edeedeedefdd��ZdS)�pyparsing_testzB
    namespace class for classes useful in writing unit tests
    c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)z&pyparsing_test.reset_pyparsing_contexta�
        Context manager to be used when writing unit tests that modify pyparsing config values:
        - packrat parsing
        - bounded recursion parsing
        - default whitespace characters.
        - default keyword characters
        - literal string auto-conversion class
        - __diag__ settings

        Example::

            with reset_pyparsing_context():
                # test that literals used to construct a grammar are automatically suppressed
                ParserElement.inlineLiteralsUsing(Suppress)

                term = Word(alphas) | Word(nums)
                group = Group('(' + term[...] + ')')

                # assert that the '()' characters are not included in the parsed tokens
                self.assertParseAndCheckList(group, "(abc 123 def)", ['abc', '123', 'def'])

            # after exiting context manager, literals are converted to Literal expressions again
        cCs
i|_dS�N)�
_save_context��self�r�?/usr/lib/python3/dist-packages/pip/_vendor/pyparsing/testing.py�__init__-s
z/pyparsing_test.reset_pyparsing_context.__init__cCs�tj|jd<tj|jd<tj|jd<tj|jd<tj|jd<tjr)tjj	|jd<nd|jd<tj
|jd<tj|jd<d	d
�tj
D�|jd<dtji|jd
<|S)N�default_whitespace�default_keyword_chars�literal_string_class�verbose_stacktrace�packrat_enabled�packrat_cache_size�
packrat_parse�recursion_enabledcSsi|]}|tt|��qSr)�getattrr)�.0�namerrr�
<dictcomp>Fs�z?pyparsing_test.reset_pyparsing_context.save.<locals>.<dictcomp>r�collect_all_And_tokensr	)r�DEFAULT_WHITE_CHARSrr�DEFAULT_KEYWORD_CHARS�_literalStringClassr�_packratEnabled�
packrat_cache�size�_parse�_left_recursion_enabledr�
_all_namesr	rr
rrr�save0s2����
���
�z+pyparsing_test.reset_pyparsing_context.savecCs�tj|jdkrt�|jd�|jdt_|jdt_t�|jd�|jd��D]\}}|r4t	j
nt	j|�q+dt_|jdrKt�
|jd�n|jd	t_|jd
t_|jdt_|S)NrrrrrFrrrrr	)rrr�set_default_whitespace_charsrrr �inlineLiteralsUsing�itemsr�enable�disabler"�enable_packratr%r&r	r)rr�valuerrr�restorePs,���
�z.pyparsing_test.reset_pyparsing_context.restorecCst|��}|j�|j�|Sr)�typer�update)r�retrrr�copyqs
z+pyparsing_test.reset_pyparsing_context.copycCs|��Sr)r(r
rrr�	__enter__vsz0pyparsing_test.reset_pyparsing_context.__enter__cGs|��dSr)r0)r�argsrrr�__exit__ysz/pyparsing_test.reset_pyparsing_context.__exit__N)
�__name__�
__module__�__qualname__�__doc__rr(r0r4r5r7rrrr�reset_pyparsing_contexts !r<c@sReZdZdZ	ddd�Z	ddd�Z	ddd	�Z	dd
d�Zee	dfdd
��Z
dS)z&pyparsing_test.TestParseResultsAssertszk
        A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
        NcCs@|dur|j||��|d�|dur|j||��|d�dSdS)z�
            Unit test assertion to compare a :class:`ParseResults` object with an optional ``expected_list``,
            and compare any defined results names with an optional ``expected_dict``.
            N��msg)�assertEqual�as_list�as_dict)r�result�
expected_list�
expected_dictr>rrr�assertParseResultsEquals�s
�z?pyparsing_test.TestParseResultsAsserts.assertParseResultsEqualsTcC�@|j|dd�}|rt|���nt|���|j|||d�dS)z�
            Convenience wrapper assert to test a parser element and input string, and assert that
            the resulting ``ParseResults.asList()`` is equal to the ``expected_list``.
            T)�	parse_all)rCr>N��parse_string�print�dumpr@rE)r�expr�test_stringrCr>�verboserBrrr�assertParseAndCheckList��
z>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckListcCrF)z�
            Convenience wrapper assert to test a parser element and input string, and assert that
            the resulting ``ParseResults.asDict()`` is equal to the ``expected_dict``.
            T)�parseAll)rDr>NrH)rrLrMrDr>rNrBrrr�assertParseAndCheckDict�rPz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDictc	Cs|\}}|dur�dd�t||�D�}|D]k\}}}	tdd�|	D�d�}
tdd�|	D�d�}|durR|j||
p7|d��t|t�rB|�Wd�n1sLwYqtdd�|	D�d�}td	d�|	D�d�}
||
fd
krx|j|||
|
pt|d�qtd�|��q|j||dur�|nd
d�dS)ah
            Unit test assertion to evaluate output of ``ParserElement.runTests()``. If a list of
            list-dict tuples is given as the ``expected_parse_results`` argument, then these are zipped
            with the report tuples returned by ``runTests`` and evaluated using ``assertParseResultsEquals``.
            Finally, asserts that the overall ``runTests()`` success value is ``True``.

            :param run_tests_report: tuple(bool, [tuple(str, ParseResults or Exception)]) returned from runTests
            :param expected_parse_results (optional): [tuple(str, list, dict, Exception)]
            NcSsg|]\}}g|�|�R�qSrr)r�rpt�expectedrrr�
<listcomp>�s��zOpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<listcomp>cs��|]
}t|t�r|VqdSr)�
isinstance�str�r�exprrr�	<genexpr>���zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>css(�|]}t|t�rt|t�r|VqdSr)rWr1�
issubclass�	ExceptionrYrrrr[�s���
�)�expected_exceptionr>csrVr)rW�listrYrrrr[�r\csrVr)rW�dictrYrrrr[�r\�NN)rCrDr>zno validation for {!r}zfailed runTestsr=)	�zip�next�assertRaisesrWr^rErJ�format�
assertTrue)r�run_tests_report�expected_parse_resultsr>�run_test_success�run_test_results�mergedrMrBrT�fail_msgr_rCrDrrr�assertRunTestResults�sR�����
������
�z;pyparsing_test.TestParseResultsAsserts.assertRunTestResultsccs<�|j||d��dVWd�dS1swYdS)Nr=)re)r�exc_typer>rrr�assertRaisesParseException�s�"�zApyparsing_test.TestParseResultsAsserts.assertRaisesParseException)NNN)NTrb)r8r9r:r;rErOrRrnrrrprrrr�TestParseResultsAsserts|s
�
�
�
�?rqNT�|�s�
start_line�end_line�expand_tabs�eol_mark�mark_spaces�mark_control�returncs|r|��}�durA�dkr(t�dd�ttdd�tdd��D�d	d
iB�}d�nt��fdd�ttdd
��d	gD��}|�|�}|dura|dkra|dkr[t�ddd��}|�|�}n|�d|�}|durgd}|durot|�}t	|t|��}t	t
d|�|�}�dkr�|��|d|�}ndd�|�d�|d|�D�}|s�dStt|���t
dd�|D��}	d�d}
|	dkr�|
d�
dd�tt
|	dd��D��d}nd}||
d�
dd�t|	d�D��d}|
d|	dd}
||
d�
��fdd�t||d �D��dS)!u	
        Helpful method for debugging a parser - prints a string with line and column numbers.
        (Line and column numbers are 1-based.)

        :param s: tuple(bool, str - string to be printed with line and column numbers
        :param start_line: int - (optional) starting line number in s to print (default=1)
        :param end_line: int - (optional) ending line number in s to print (default=len(s))
        :param expand_tabs: bool - (optional) expand tabs to spaces, to match the pyparsing default
        :param eol_mark: str - (optional) string to mark the end of lines, helps visualize trailing spaces (default="|")
        :param mark_spaces: str - (optional) special character to display in place of spaces
        :param mark_control: str - (optional) convert non-printing control characters to a placeholding
                                 character; valid values:
                                 - "unicode" - replaces control chars with Unicode symbols, such as "␍" and "␊"
                                 - any single character string - replace control characters with given string
                                 - None (default) - string is displayed as-is

        :return: str - input string with leading line numbers and column number headers
        N�unicodecSsi|]\}}||�qSrr)r�c�urrrrsz4pyparsing_test.with_line_numbers.<locals>.<dictcomp>r�!i$i3$�i!$�csi|]}|��qSrr)rr|)ryrrrs� � i	$i#$)�	r�rcSsg|]}|d�qS)�␊r�r�linerrrrU'sz4pyparsing_test.with_line_numbers.<locals>.<listcomp>r�css�|]}t|�VqdSr)�lenr�rrrr[,s�z3pyparsing_test.with_line_numbers.<locals>.<genexpr>�ccss$�|]
}d�d|dd�VqdS)z{}{}zc                                                                                                   r�dN�rf�r�irrrr[1s
��
�r��
css"�|]}d�|dd�VqdS)z         {}r�
Nr�r�rrrr[<s
��
�r��
1234567890c3s$�|]
\}}d�|�|��VqdS)z{:{}d}:{}{}Nr�)rr�r�)rw�lineno_widthrrr[Fs
��
�)�start)�
expandtabsrX�	maketransrc�ranger`�	translate�replacer��min�max�
splitlines�split�join�	enumerate)rsrtrurvrwrxry�tbl�s_lines�max_line_len�lead�header0�header1�header2r)rwr�ryr�with_line_numbers�s��� �
 
����	�
����	�
����z pyparsing_test.with_line_numbers)NNTrrNN)r8r9r:r;r<rq�staticmethodrXr�int�boolr�rrrrr
s8hq���������r
N)�
contextlibr�typingr�corerrrrr	r
rrrr�<module>s