
    Цi\<                     d    S SK Jr  S SKrS SKrS SKrSSKJrJrJrJ	r	J
r
  SSKJr   " S S5      rg)    )contextmanagerN   )ParserElementParseExceptionKeyword__diag__
__compat__)core_builtin_exprsc                   2   \ rS rSrSr " S S5      r " S S\R                  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:

.. testcode::

    ppt = pyparsing.pyparsing_test

    class MyTestClass(ppt.TestParseResultsAsserts):
        def test_literal(self):
            with ppt.reset_pyparsing_context():
                # test that literals used to construct
                # a grammar are automatically suppressed
                ParserElement.inline_literals_using(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    P/var/www/html/ai-image-ml/venv/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.saveA   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        [          H  nUR#                  S5        M     U R                  S   [$        l        U $ )Nr   r   r   r   r   Fr    r!   r"   r#   r	   )r   r%   r   set_default_whitespace_charsr   r   r&   inline_literals_usingitemsr   enabledisabler(   enable_packratr+   r,   r
   	set_debugr	   r$   )r   r/   valueexprs       r   restore.pyparsing_test.reset_pyparsing_context.restorea   sQ    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
 +u% + 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.copy   s,    t*,C$$T%7%78Jr   c                 "    U R                  5       $ r   )r0   r   s    r   	__enter__0pyparsing_test.reset_pyparsing_context.__enter__   s    99;r   c                 $    U R                  5         g r   )r<   )r   argss     r   __exit__/pyparsing_test.reset_pyparsing_context.__exit__   s    LLNr   r   N)__name__
__module____qualname____firstlineno____doc__r   r0   r<   rB   rE   rI   __static_attributes__ r   r   reset_pyparsing_contextr      s(    #	J	$	@#	J	
		r   rR   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_dictrX   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 :meth:`ParseResults.as_list` is equal to the ``expected_list``.
T	parse_all)r]   rX   Nparse_stringprintdumprZ   r_   )r   r;   test_stringr]   rX   verboser\   s          r   assertParseAndCheckList>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   M     &&{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 :meth:`ParseResults.as_dict` is equal to the ``expected_dict``.
Trb   )r^   rX   Nrd   )r   r;   rh   r^   rX   ri   r\   s          r   assertParseAndCheckDict>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict   rl   r   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
:meth:`~ParserElement.run_tests`.

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 ``run_tests()``
and evaluated using :meth:`assertParseResultsEquals`.
Finally, asserts that the overall
`:meth:~ParserElement.run_tests` success value is ``True``.

:param run_tests_report: the return value from :meth:`ParserElement.run_tests`
:type run_tests_report: tuple[bool, list[tuple[str, ParseResults | Exception]]]
:param expected_parse_results: (optional)
:type expected_parse_results: list[tuple[str | list | dict | Exception, ...]]
Nzfailed runTestsrW   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   )rr   r?   
issubclass	Exceptionrt   s     r   rw   rx      s2      #+C%c40 5?Y5O #+s   ??	?)expected_exceptionrX   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )rr   listrt   s     r   rw   rx           JJsD4Iry   c              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )rr   dictrt   s     r   rw   rx      r   ry   NN)r]   r^   rX   zno validation for )
assertTruezipnextassertRaisesrr   r|   r_   rf   )r   run_tests_reportexpected_parse_resultsrX   run_test_successrun_test_resultsrptexpectedmergedrh   r\   fail_msgr}   r]   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)NrW   )rr   rs   reescapeassertRaisesRegexr   )r   exc_typeexpected_msgrX   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rQ   )NNN)NTr   )rK   rL   rM   rN   rO   r_   rj   rn   r   r   r   r   rP   rQ   r   r   TestParseResultsAssertsrT      sW    	
 GK
	K GK	X GK	X FJG	R 
)$	 
	r   r   NT )indentbase_1s
start_lineend_lineexpand_tabseol_markmark_spacesmark_controlr   r   returnc          
      Z  ^^^ 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 R                  5       5      n[        U[        U R                  5       5      5      n[        [!        SU5      U5      nUS:w  a   U R                  5       [!        X-
  S5      U nO3U R#                  S5      [!        X-
  S5      U  Vs/ s H  nUS-   PM
     nnU(       d  g	[        [        U5      5      m[!        S U 5       5      nT STS-   -   3nUS:  aA  UU(       a  S	OS-   S	R%                  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-   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: string to be printed with line and column numbers
:param start_line: starting line number in s to print (default=1)
:param end_line: ending line number in s to print (default=len(s))
:param expand_tabs: expand tabs to spaces, to match the pyparsing default
:param eol_mark: string to mark the end of lines, helps visualize trailing spaces
:param mark_spaces: special character to display in place of spaces
:param mark_control: 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: string to indent with line and column numbers; if an int
               is passed, converted to ``" " * indent``
:param base_1: whether to label string using base 1; if False, string will be
               labeled based at 0

:returns: input string with leading line numbers and column number headers

.. versionchanged:: 3.2.0
   New ``indent`` and ``base_1`` arguments.
 unicoder   !   i $  i3$  i!$     r       i	$  i#$  )	   r   u   ␊c              3   8   #    U  H  n[        U5      v   M     g 7fr   )len)ru   lines     r   rw   3pyparsing_test.with_line_numbers.<locals>.<genexpr>k  s     93t99   r   c   c              3   :   #    U  H  nS  US-   S-   3v   M     g7f)zc                                                                                                   r   d   NrQ   ru   is     r   rw   r   r  s(      ?  j!a%30?s   r   
c              3   8   #    U  H  nS US-   S-   3v   M     g7f)z	         r   
   NrQ   r   s     r   rw   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:NrQ   )ru   r   r   r   r   lineno_widths      r   rw   r     s7      LGA (1l^1,-QtfXJ?Ls   !)start)
expandtabsrr   inttypingcastrs   r   range	maketransordr   	translatereplacer   
splitlinesminmax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  se   T 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1<<>*HxQ\\^!45Q
+X6
9$llnS)<a%@8LG GGEN3z/BA+FRRD uR   3x=)999#!123422S*'' "3|s':A#>?    G RsggX%<-SUBU@V:WXXY  	 &Bc*V,"9L7M-NNQUU 	  ii (V8KL  		
}" N&s   L/L# L(rQ   )NNT|NN)rK   rL   rM   rN   rO   rR   unittestTestCaser   staticmethodrs   r   Optionalr   boolUnionr   rP   rQ   r   r   r   r      s    w wrB("3"3 BH  ,0)- ,0-1x
 *,x
x
OOC(x
 //#&x
 	x

 x
 __S)x
 ooc*x
 S#X&x
 x
 
x
 x
r   r   )
contextlibr   r   r   r   corer   r   r   r   r	   r   r
   r   rQ   r   r   <module>r      s.    & 	    !{
 {
r   