
    LgZ4                     P    d dl mZ d dlZddlmZmZmZmZmZ  G d d          Z	dS )    )contextmanagerN   )ParserElementParseExceptionKeyword__diag__
__compat__c                       e Zd ZdZ G d d          Z G d d          Ze	 	 	 	 	 	 dd	ed
ej	        e
         dej	        e
         dededej	        e         dej	        e         defd            ZdS )pyparsing_testzB
    namespace class for classes useful in writing unit tests
    c                   6    e Zd ZdZd Zd Zd Zd Zd Zd Z	dS )	&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
        c                     i | _         d S N)_save_contextselfs    Y/var/www/html/4nations/venv/lib/python3.11/site-packages/pip/_vendor/pyparsing/testing.py__init__z/pyparsing_test.reset_pyparsing_context.__init__-   s    !#D    c                    t           j        | j        d<   t          j        | j        d<   t           j        | j        d<   t           j        | j        d<   t           j        | j        d<   t           j        rt           j        j	        | j        d<   n
d | j        d<   t           j
        | j        d<   t           j        | j        d<   d	 t          j        D             | j        d
<   dt          j        i| j        d<   | S )Ndefault_whitespacedefault_keyword_charsliteral_string_classverbose_stacktracepackrat_enabledpackrat_cache_sizepackrat_parserecursion_enabledc                 :    i | ]}|t          t          |          S  )getattrr   ).0names     r   
<dictcomp>z?pyparsing_test.reset_pyparsing_context.save.<locals>.<dictcomp>F   s1     . . .26gh--. . .r   r   collect_all_And_tokensr	   )r   DEFAULT_WHITE_CHARSr   r   DEFAULT_KEYWORD_CHARS_literalStringClassr   _packratEnabledpackrat_cachesize_parse_left_recursion_enabledr   
_all_namesr	   r%   r   s    r   savez+pyparsing_test.reset_pyparsing_context.save0   s   7D7XD34:A:WD67 1 & 8E7WD344A4QD01, @ "/4 "(  <@"#782?2FD/ 5 #. .:B:M. . .Dz*
 )**K0D|, Kr   c                    t           j        | j        d         k    rt          j        | j        d                    | j        d         t           _        | j        d         t
          _        t          j        | j        d                    | j        d                                         D ](\  }} |rt          j
        nt          j        |           )dt           _        | j        d         r t          j        | j        d                    n| j        d	         t           _        | j        d
         t           _        | j        d         t           _        | S )Nr   r   r   r   r   Fr   r   r   r   r	   )r   r&   r   set_default_whitespace_charsr   r   r'   inlineLiteralsUsingitemsr   enabledisabler)   enable_packratr,   r-   r	   r%   )r   r#   values      r   restorez.pyparsing_test.reset_pyparsing_context.restoreP   sE    1%&:;< < :&';<   04/ABV/WM,,0,>?V,WG)-"#9:    $1*=CCEE G Ge?E?x/?FFFF,1M)!"34 K,T-?@T-UVVVV'+'9/'J$484F#5M1 150B<0PJ-Kr   c                 r     t          |                       }|j                            | j                   |S r   )typer   update)r   rets     r   copyz+pyparsing_test.reset_pyparsing_context.copyq   s2    $t**,,C$$T%7888Jr   c                 *    |                                  S r   )r/   r   s    r   	__enter__z0pyparsing_test.reset_pyparsing_context.__enter__v   s    99;;r   c                 .    |                                   d S r   )r8   )r   argss     r   __exit__z/pyparsing_test.reset_pyparsing_context.__exit__y   s    LLNNNNNr   N)
__name__
__module____qualname____doc__r   r/   r8   r=   r?   rB   r    r   r   reset_pyparsing_contextr      sz        	 	0	$ 	$ 	$	 	 	@	 	 	B	 	 	
	 	 		 	 	 	 	r   rG   c                   V    e Zd ZdZ	 d	dZ	 d
dZ	 d
dZ	 ddZee	dfd            Z
dS )&pyparsing_test.TestParseResultsAssertszk
        A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
        Nc                     |*|                      ||                                |           |,|                      ||                                |           dS dS )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_dictrL   s        r   assertParseResultsEqualsz?pyparsing_test.TestParseResultsAsserts.assertParseResultsEquals   sh     (  0@0@c JJJ(  0@0@c JJJJJ )(r   Tc                     |                     |d          }|r"t          |                                           n!t          |                                           |                     |||           dS )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)rQ   rL   Nparse_stringprintdumprN   rS   )r   exprtest_stringrQ   rL   verboserP   s          r   assertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   sw     &&{d&CCF (fkkmm$$$$fnn&&'''))&SV)WWWWWr   c                     |                     |d          }|r"t          |                                           n!t          |                                           |                     |||           dS )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)rR   rL   NrV   )r   rZ   r[   rR   rL   r\   rP   s          r   assertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict   sw     &&{T&BBF (fkkmm$$$$fnn&&'''))&SV)WWWWWr   c                    |\  }}|d t          ||          D             }|D ]\  }}}	t          d |	D             d          }
t          d |	D             d          }|J|                     ||
p|          5  t          |t                    r|	 ddd           n# 1 swxY w Y   t          d |	D             d          }t          d |	D             d          }||fdk    r|                     ||||
p|	           t          d
                    |                     |                     |||nd           dS )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)]
            Nc                 "    g | ]\  }}g ||R S r    r    )r"   rptexpecteds      r   
<listcomp>zOpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<listcomp>   s9       %X %c$8$$  r   c              3   D   K   | ]}t          |t                    |V  d S r   )
isinstancestrr"   exps     r   	<genexpr>zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s1      IIJsC4H4HIIIIIIIr   c              3   n   K   | ]0}t          |t                    t          |t                    ,|V  1d S r   )rg   r:   
issubclass	Exceptionri   s     r   rk   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s[         #)#t44 :DC9S9S     r   )expected_exceptionrL   c              3   D   K   | ]}t          |t                    |V  d S r   )rg   listri   s     r   rk   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   1      NNS
38M8MNSNNNNNNr   c              3   D   K   | ]}t          |t                    |V  d S r   )rg   dictri   s     r   rk   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   rr   r   NN)rQ   rR   rL   zno validation for {!r}zfailed runTestsrK   )	zipnextassertRaisesrg   rn   rS   rX   format
assertTrue)r   run_tests_reportexpected_parse_resultsrL   run_test_successrun_test_resultsmergedr[   rP   rd   fail_msgro   rQ   rR   s                 r   assertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResults   s8    2B..%1 ),-=?U)V)V   6< %P %P1K  $IIIII4   H *. '/  
 * *& *5!../AxSV /   - -  *&)<< -&,-- - - - - - - - - - - - - - - )-NNHNNNPT) ) )-NNHNNNPT) ) *=9\II 99 &.;.;$,O	 :     "":"A"A+"N"NOOOO OO S_ccBS      s   ;B  B$	'B$	c              #   r   K   |                      ||          5  d V  d d d            d S # 1 swxY w Y   d S )NrK   )rx   )r   exc_typerL   s      r   assertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseException   s      ""8"55                   s   ,00)NNN)NTru   )rC   rD   rE   rF   rS   r]   r`   r   r   r   r   r    r   r   TestParseResultsAssertsrI   |   s        	 	
 GK
	K 
	K 
	K 
	K GK	X 	X 	X 	X GK	X 	X 	X 	X FJ=	 =	 =	 =	~ 
6D$ 	 	 	 
	 	 	r   r   NT|s
start_lineend_lineexpand_tabseol_markmark_spacesmark_controlreturnc           
         |r|                                  } dk    rVt                              d t          t	          dd          t	          dd                    D             dd	iz            }d
nEt                              fdt          t	          dd                    dgz   D                       }|                     |          } |U|dk    rO|dk    r3t                              ddd          }|                     |          } n|                     d|          } |d}|t          |           }t          |t          |                     }t          t          d|          |          }dk    r |                                 |dz
  |         }n*d |                     d          |dz
  |         D             }|sd
S t          t          |                    t          d |D                       }	ddz   z  }
|	dk    rD|
d
                    d t	          t          |	dz  d                    D                       z   dz   }nd
}||
z   d
                    d t	          |	 dz             D                       z   dz   }|
d|	 dz   z  z   dz   }||z   d                    fdt          ||          D                       z   dz   S )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unicodec                     i | ]\  }}||	S r    r    )r"   cus      r   r$   z4pyparsing_test.with_line_numbers.<locals>.<dictcomp>  s    OOOdaQOOOr   r   !   i $  i3$     i!$   c                     i | ]}|S r    r    )r"   r   r   s     r   r$   z4pyparsing_test.with_line_numbers.<locals>.<dictcomp>  s    IIIQIIIr        i	$  i#$  )	   r   r   c                     g | ]}|d z   S )   ␊r    r"   lines     r   re   z4pyparsing_test.with_line_numbers.<locals>.<listcomp>'  s    ZZZte|ZZZr   r   c              3   4   K   | ]}t          |          V  d S r   )lenr   s     r   rk   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>,  s(      993t99999999r   c   c              3   N   K   | ] }d                      d|dz   dz            V  !dS )z{}{}zc                                                                                                   r   d   Nry   r"   is     r   rk   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>1  sL         MM(QUcM::     r   r   
c              3   L   K   | ]}d                      |dz   dz            V   dS )z         {}r   
   Nr   r   s     r   rk   z3pyparsing_test.with_line_numbers.<locals>.<genexpr><  sL         $$a!er\22     r   r   
1234567890c              3   N   K   | ]\  }}d                      ||          V   dS )z{:{}d}:{}{}Nr   )r"   r   r   r   lineno_widths      r   rk   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>F  sO        At $$QdHEE     r   )start)
expandtabsrh   	maketransrv   rangerq   	translatereplacer   minmax
splitlinessplitjoin	enumerate)r   r   r   r   r   r   r   tbls_linesmax_line_lenleadheader0header1header2r   s       ` `       @r   with_line_numbersz pyparsing_test.with_line_numbers   sn   8  	A#y((mmOOc%2,,ff8M8M&N&NOOOFm$  mmIIIId5B<<.@.@C5.HIII  C  A"{c'9'9i''mmF$;$;<<KK$$IIc;//J1vvHxQ((Q
++X66
9$$llnnZ!^h%>?GGZZzA~PX?X0YZZZG 	23x==))9999999lQ&'2''  "3|s':A#>#>??    
  G Ggg  ,"!4566      	 L=B+>)?@@4Gii     (
CCC     	
r   )NNTr   NN)rC   rD   rE   rF   rG   r   staticmethodrh   typingOptionalintboolr   r    r   r   r   r      s0        f f f f f f f fPo o o o o o o ob  ,0)- ,0-1]
 ]
]
OC(]
 /#&]
 	]

 ]
 _S)]
 oc*]
 
]
 ]
 ]
 \]
 ]
 ]
r   r   )

contextlibr   r   corer   r   r   r   r	   r   r    r   r   <module>r      s    & % % % % %              |
 |
 |
 |
 |
 |
 |
 |
 |
 |
r   