
    hZ9                     P    S SK Jr  S SKrS SKrSSKJrJrJrJrJ	r	   " S S5      r
g)    )contextmanagerN   )ParserElementParseExceptionKeyword__diag__
__compat__c                      \ rS rSrSr " S S5      r " S S5      r\      SS	SS
.S\S\	R                  \   S\	R                  \   S\S\S\	R                  \   S\	R                  \   S\	R                  \\4   S\S\4S jjj5       rSrg)pyparsing_test   z:
namespace class for classes useful in writing unit tests
c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)&pyparsing_test.reset_pyparsing_context   a  
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                     0 U l         g N_save_contextselfs    C/var/www/html/env/lib/python3.13/site-packages/pyparsing/testing.py__init__/pyparsing_test.reset_pyparsing_context.__init__/   s
    !#D    c                    [         R                  U R                  S'   [        R                  U R                  S'   [         R
                  U R                  S'   [         R                  U R                  S'   [         R                  U R                  S'   [         R                  (       a(  [         R                  R                  U R                  S'   OS U R                  S'   [         R                  U R                  S'   [         R                  U R                  S'   [        R                   Vs0 s H  o[        [        U5      _M     snU R                  S	'   S
[        R                   0U R                  S'   U $ s  snf )Ndefault_whitespacedefault_keyword_charsliteral_string_classverbose_stacktracepackrat_enabledpackrat_cache_sizepackrat_parserecursion_enabledr   collect_all_And_tokensr	   )r   DEFAULT_WHITE_CHARSr   r   DEFAULT_KEYWORD_CHARS_literalStringClassr   _packratEnabledpackrat_cachesize_parse_left_recursion_enabledr   
_all_namesgetattrr	   r#   )r   names     r   save+pyparsing_test.reset_pyparsing_context.save2   sM   7D7X7XD34:A:W:WD67 11 56 8E7W7WD344A4Q4QD01,,!//44 ""#78 <@""#782?2F2FD/55 23
 ;C:M:M.:M$gh--:M.Dz*
 )**K*K0D|, K.s   *E5c                    [         R                  U R                  S   :w  a#  [         R                  " U R                  S   5        U R                  S   [         l        U R                  S   [
        l        [         R                  " U R                  S   5        U R                  S   R                  5        H2  u  pU(       a  [        R                  O[        R                  " U5        M4     S[         l        U R                  S   (       a$  [         R                  " U R                  S   5        OU R                  S	   [         l        U R                  S
   [         l        U R                  S   [         l        U $ )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   restore.pyparsing_test.reset_pyparsing_context.restoreR   s9    11%%&:;< ::&&';< 04/A/ABV/WM,,0,>,>?V,WG)--""#9:  $11*=CCE$)x/?/??F  F -2M)!!"34,,T-?-?@T-UV'+'9'9/'J$484F4F#5M1 150B0B<0PJ-Kr   c                 p    [        U 5      " 5       nUR                  R                  U R                  5        U$ r   )typer   update)r   rets     r   copy+pyparsing_test.reset_pyparsing_context.copys   s,    t*,C$$T%7%78Jr   c                 "    U R                  5       $ r   )r/   r   s    r   	__enter__0pyparsing_test.reset_pyparsing_context.__enter__x   s    99;r   c                 $    U R                  5         g r   )r9   )r   argss     r   __exit__/pyparsing_test.reset_pyparsing_context.__exit__{   s    LLNr   r   N)__name__
__module____qualname____firstlineno____doc__r   r/   r9   r?   rB   rF   __static_attributes__ r   r   reset_pyparsing_contextr      s'    	0	$	@	B	
		r   rO   c                   b    \ 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4S j5       rS	rg)&pyparsing_test.TestParseResultsAsserts~   z[
A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
Nc                     Ub  U R                  X!R                  5       US9  Ub  U R                  X1R                  5       US9  gg)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_dictrU   s        r   assertParseResultsEquals?pyparsing_test.TestParseResultsAsserts.assertParseResultsEquals   sI     (  0@c J(  0@c J )r   c                     UR                  USS9nU(       a  [        UR                  5       5        O[        UR                  5       5        U R	                  XcUS9  g)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)rZ   rU   Nparse_stringprintdumprW   r\   )r   exprtest_stringrZ   rU   verboserY   s          r   assertParseAndCheckList>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   sM     &&{d&CFfkkm$fnn&'))&SV)Wr   c                     UR                  USS9nU(       a  [        UR                  5       5        O[        UR                  5       5        U R	                  XcUS9  g)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)r[   rU   Nr`   )r   rd   re   r[   rU   rf   rY   s          r   assertParseAndCheckDict>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict   sM     &&{T&BFfkkm$fnn&'))&SV)Wr   c                 n   Uu  pEUc  U R                  XCb  UOSS9  g[        XR5       VVs/ s H  u  pg/ UQUP7PM     nnnU H  u  pn[        S U 5       S5      n[        S U 5       S5      nUb;  U R                  X=(       d    US9   [	        U
[
        5      (       a  U
e SSS5        Mj  [        S U 5       S5      n[        S U 5       S5      nX4S	:w  a  U R                  U
UUU=(       d    US
9  M  [        SU	< 35        M     U R                  XCb  UOSS9  gs  snnf ! , (       d  f       M  = f)a  
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)]
Nzfailed runTestsrT   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )
isinstancestr.0exps     r   	<genexpr>Npyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s      QJsC<P   (	(c              3      #    U  H5  n[        U[        5      (       d  M  [        U[        5      (       d  M1  Uv   M7     g 7fr   )ro   r<   
issubclass	Exceptionrq   s     r   rt   ru      s2      #+C%c40 5?Y5O #+s   ??	?)expected_exceptionrU   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )ro   listrq   s     r   rt   ru           JJsD4Irv   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )ro   dictrq   s     r   rt   ru      r}   rv   NN)rZ   r[   rU   zno validation for )
assertTruezipnextassertRaisesro   ry   r\   rb   )r   run_tests_reportexpected_parse_resultsrU   run_test_successrun_test_resultsrptexpectedmergedre   rY   fail_msgrz   rZ   r[   s                  r   assertRunTestResults;pyparsing_test.TestParseResultsAsserts.assertRunTestResults   s    2B.%-$#FW     &))9%R%RMC !# x %R   28-X   Q QSWX%)#+
 &" &1**+=?s +  &fi88"(L 9  %)JJD%M %)JJD%M &5E55"*7*7 (C	 6   2;/BCG 28L OO _cBS  U$ s   D
D%%
D4	c              #      #    UbI  [        U[        5      (       a  [        R                  " U5      nU R	                  XUS9 nUv   S S S 5        g U R                  XS9 nUv   S S S 5        g ! , (       d  f       g = f! , (       d  f       g = f7f)NrT   )ro   rp   reescapeassertRaisesRegexr   )r   exc_typeexpected_msgrU   ctxs        r   assertRaisesParseExceptionApyparsing_test.TestParseResultsAsserts.assertRaisesParseException   s      'lC00#%99\#:L++H+LPSI ML &&x&9SI :9	 ML :9s5   ?BA,BA=#	B,
A:6B=
BBrN   )NNN)NTr   )rH   rI   rJ   rK   rL   r\   rg   rk   r   r   r   r   rM   rN   r   r   TestParseResultsAssertsrQ   ~   sW    	
 GK
	K GK	X GK	X FJ@	D 
)$	 
	r   r   NT )indentbase_1s
start_lineend_lineexpand_tabseol_markmark_spacesmark_controlr   r   returnc                  ^^^ U(       a  U R                  5       n [        T[        5      (       a  ST-  mTR                  5       mUb  [        R                  " [
        U5      nUS:X  aQ  [        [        SS5      [        SS5      5       V	V
s0 s H  u  pX_M	     nn	n
SUS'   [
        R                  U5      nS	mOH[        U5      n[
        R                  [        [        SS
5      5      S/-    V	s0 s H  oU_M     sn	5      nU R                  U5      n UbH  US:w  aB  US:X  a*  [
        R                  SSS.5      nU R                  U5      n OU R                  SU5      n Uc  SnUc  [        U 5      n[        U[        U 5      5      n[        [        SU5      U5      nUS:w  a  U R!                  5       X-
  U nO(U R#                  S5      X-
  U  Vs/ s H  oS-   PM	     nnU(       d  g	[        [        U5      5      m[        S U 5       5      nTSTS-   -  -   nUS:  aK  UU(       a  S	OS-   S	R%                  S [        U(       a  SOS[        US-  S5      5       5       5      -   S-   nOS	nU(       a  S	OSU-   S	R%                  S [        U* S-  * 5       5       5      -   S-   nSnUU(       a  S	OS-   UU* S-  * -  -   S-   nUU-   SR%                  UUU4S j['        XU-   S9 5       5      -   S-   $ s  sn
n	f s  sn	f s  snf )u?  
Helpful method for debugging a parser - prints a string with line and column numbers.
(Line and column numbers are 1-based by default - if debugging a parse action,
pass base_1=False, to correspond to the loc value passed to the parse action.)

: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
:param indent: str | int - (optional) string to indent with line and column numbers; if an int
                           is passed, converted to " " * indent
:param base_1: bool - (optional) whether to label string using base 1; if False, string will be
                      labeled based at 0 (default=True)

:return: str - input string with leading line numbers and column number headers
 unicoder   !   i $  i3$  i!$     r       i	$  i#$  )	   r   u   ␊c              3   8   #    U  H  n[        U5      v   M     g 7fr   )len)rr   lines     r   rt   3pyparsing_test.with_line_numbers.<locals>.<genexpr>J  s     93t99   r   c   c              3   :   #    U  H  nS  US-   S-   3v   M     g7f)zc                                                                                                   r   d   NrN   rr   is     r   rt   r   P  s(      S  j!a%30Ss   r   
c              3   8   #    U  H  nS US-   S-   3v   M     g7f)z	         r   
   NrN   r   s     r   rt   r   [  s!     X:WQ	1q5B,0:Wr   r   
12345678900c              3   F   >#    U  H  u  pT UT S 3 SU T 3v   M     g7f)d:NrN   )rr   r   r   r   r   lineno_widths      r   rt   r   e  s7      LGA (1l^1,-QtfXJ?Ls   !)start)
expandtabsro   inttypingcastrp   r   range	maketransordr|   	translatereplacer   minmax
splitlinessplitjoin	enumerate)r   r   r   r   r   r   r   r   r   cutranstable_maptblord_mark_controls_linesr   max_line_lenleadheader0header1digitsheader2r   s       `  `              @r   with_line_numbers pyparsing_test.with_line_numbers   s:   H Afc""6\F""$#!;;sL9Ly(%(q"uVV7L%M"%MTQAD%M  " '-s#mmN3#&|#4 mm26uQ|2Du2LM2LQ((2LM C A"{c'9i'mmF$;<KK$IIc;/J1vHxQ(Q
+X6
9$llnZ%88DG *+
8Kh)W)Wu)W   3x=)999|a/0022S*'' "1As<3;NPQ7RS    GRsggX%<-SUBU@V:WXXY  	 &Bc*V,"9L7M-NNQUU 	 ii (V8KL  	
w" N&s   K2/K8K=rN   )NNT|NN)rH   rI   rJ   rK   rL   rO   r   staticmethodrp   r   Optionalr   boolUnionr   rM   rN   r   r   r   r      s    f fP{ {z  ,0)- ,0-1n
 *,n
n
OOC(n
 //#&n
 	n

 n
 __S)n
 ooc*n
 S#X&n
 n
 
n
 n
r   r   )
contextlibr   r   r   corer   r   r   r   r	   r   rN   r   r   <module>r      s&    & 	  Y
 Y
r   