
    eiX<                     d    d dl mZ d dlZd dlZd dlZddlmZmZmZm	Z	m
Z
 ddlmZ  G d d      Zy)    )contextmanagerN   )ParserElementParseExceptionKeyword__diag__
__compat__)core_builtin_exprsc                   $   e Zd ZdZ G d d      Z G d dej                        Ze	 	 	 	 	 	 ddd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
j                  e	ef   dede	fd       Zy)pyparsing_testzB
    namespace class for classes useful in writing unit tests
    c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	&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:

        .. 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                     i | _         y N)_save_contextselfs    S/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/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<   t        j                  D ci c]  }|t        t        |       c}| j                  d	<   d
t        j                   i| j                  d<   | S c c}w )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   savez+pyparsing_test.reset_pyparsing_context.saveA   sJ   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.26gh--.Dz*
 )**K*K0D|, K.s   %E.c                 
   t         j                  | j                  d   k7  r"t        j                  | j                  d          | j                  d   t         _        | j                  d   t
        _        t        j                  | j                  d          | j                  d   j                         D ]-  \  }} |rt        j                  nt        j                  |       / dt         _        | j                  d   r#t        j                  | j                  d          n| j                  d	   t         _        | j                  d
   t         _        t         D ]  }|j#                  d        | j                  d   t$        _        | S )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   restorez.pyparsing_test.reset_pyparsing_context.restorea   s]    11%%&:;< ::&&';< 04/A/ABV/WM,,0,>,>?V,WG)//""#9:  $11*=CCE Ge?Ex/?/?FG -2M)!!"34,,T-?-?@T-UV'+'9'9/'J$484F4F#5M1
 + &u%& 150B0B<0PJ-Kr   c                 p     t        |              }|j                  j                  | j                         |S r   )typer   update)r   rets     r   copyz+pyparsing_test.reset_pyparsing_context.copy   s.    $t*,C$$T%7%78Jr   c                 "    | j                         S r   )r,   r   s    r   	__enter__z0pyparsing_test.reset_pyparsing_context.__enter__   s    99;r   c                 $    | j                          y r   )r7   )r   argss     r   __exit__z/pyparsing_test.reset_pyparsing_context.__exit__   s    LLNr   N)
__name__
__module____qualname____doc__r   r,   r7   r<   r>   rA    r   r   reset_pyparsing_contextr      s(    #	J	$	@#	J	
		r   rG   c                   P    e Zd ZdZ	 ddZ	 d	dZ	 d	dZ	 d
dZee	ddfd       Z
y)&pyparsing_test.TestParseResultsAssertszk
        A mixin class to add parse results assertion methods to normal unittest.TestCase classes.
        Nc                     |"| j                  ||j                         |       |#| j                  ||j                         |       yy)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   sM     (  0@c J(  0@c J )r   c                     |j                  |d      }|rt        |j                                nt        |j                                | j	                  |||       y)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)rQ   rL   Nparse_stringprintdumprN   rS   )r   r6   test_stringrQ   rL   verboserP   s          r   assertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   O     &&{d&CFfkkm$fnn&'))&SV)Wr   c                     |j                  |d      }|rt        |j                                nt        |j                                | j	                  |||       y)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``.
            TrU   )rR   rL   NrW   )r   r6   r[   rR   rL   r\   rP   s          r   assertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict   r^   r   c                 j   |\  }}|| j                  |||       yd       yt        ||      D cg c]  \  }}g || }}}|D ]  \  }	}
}t        d |D        d      }t        d |D        d      }|4| j                  ||xs |      5  t	        |
t
              r|
	 ddd       ct        d |D        d      }t        d |D        d      }||fd	k7  r| j                  |
|||xs |
       t        d|	        | j                  |||       yd       yc c}}w # 1 sw Y   xY w)a2  
            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 runTestsrK   c              3   B   K   | ]  }t        |t              s|  y wr   )
isinstancestr.0exps     r   	<genexpr>zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s      QJsC<P Q   c              3   `   K   | ]&  }t        |t              rt        |t              r| ( y wr   )rc   r9   
issubclass	Exceptionre   s     r   rh   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s+      %c40ZY5O s   ,.)expected_exceptionrL   c              3   B   K   | ]  }t        |t              s|  y wr   )rc   listre   s     r   rh   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>        JJsD4IJri   c              3   B   K   | ]  }t        |t              s|  y wr   )rc   dictre   s     r   rh   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   rp   ri   NN)rQ   rR   rL   zno validation for )
assertTruezipnextassertRaisesrc   rl   rS   rY   )r   run_tests_reportexpected_parse_resultsrL   run_test_successrun_test_resultsrptexpectedmergedr[   rP   fail_msgrm   rQ   rR   s                  r   assertRunTestResultsz;pyparsing_test.TestParseResultsAsserts.assertRunTestResults   s   & 2B..%-$#     GX     &))9;Q%R!C !# x F  28 #D-VX   Q QSWX%)#+
 &" &1**+=8?s +  ) &fi8"(L 9) ) %)JJD%M %)JJD%M &}5E55"*7*7 (C	 6   2;/BCG#DL OO S_c  BS  U$) )s   D#D))D2	c              #     K   |Gt        |t              rt        j                  |      }| j	                  |||      5 }| d d d        y | j                  ||      5 }| d d d        y # 1 sw Y   y xY w# 1 sw Y   y xY ww)NrK   )rc   rd   reescapeassertRaisesRegexrw   )r   exc_typeexpected_msgrL   ctxs        r   assertRaisesParseExceptionzApyparsing_test.TestParseResultsAsserts.assertRaisesParseException  s      'lC0#%99\#:L++Hl+L PSI  &&xS&9 SI 	  s4   <BA-BA9$	B-A62B9B>B)NNN)NTrs   )rB   rC   rD   rE   rS   r]   r`   r   r   r   r   rF   r   r   TestParseResultsAssertsrI      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          
         |r| j                         } t        t              rdz  j                         |t        j                  t
        |      }|dk(  rPt        t        dd      t        dd            D 	
ci c]  \  }	}
|	|

 }}	}
d|d<   t
        j                  |      }d	nFt        |      }t
        j                  t        t        dd
            dgz   D 	ci c]  }	|	| c}	      }| j                  |      } |F|dk7  rA|dk(  r*t
        j                  ddd      }| j                  |      } n| j                  d|      } |d}|t        | j                               }t        |t        | j                                     }t        t!        d|      |      }|dk7  r!| j                         t!        ||z
  d      | }n1| j#                  d      t!        ||z
  d      | D cg c]  }|dz   	 }}|sy	t        t        |            t!        d |D              }ddz   z  z   }|dk\  r<||rd	ndz   d	j%                  d t        t!        |dz  d            D              z   dz   }nd	}|rd	nd|z   d	j%                  d t        | dz         D              z   dz   }d}||rd	ndz   || dz   z  z   dz   }||z   |z   dj%                  fdt'        |||z         D              z   dz   S c c}
}	w c c}	w c c}w )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   2   K   | ]  }t        |        y wr   )len)rf   lines     r   rh   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>k  s     93t99   r   c   c              3   4   K   | ]  }d  |dz   dz     yw)zc                                                                                                   r   d   NrF   rf   is     r   rh   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>r  s)        j!a%30s   r   
c              3   2   K   | ]  }d |dz   dz     yw)z	         r   
   NrF   r   s     r   rh   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>~  s     XQ	1q5B,0Xr   r   
12345678900c              3   B   K   | ]  \  }} | d d|    yw)d:NrF   )rf   r   r   r   r   lineno_widths      r   rh   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>  s:      At (1l^1,-QtfXJ?s   )start)
expandtabsrc   inttypingcastrd   ru   range	maketransordro   	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_numbersz pyparsing_test.with_line_numbers  s]   T Afc"6\F""$#!;;sL9Ly(%(q"uVV7L%M"!QAqD" " '-s#mmN3#&|#4 mm26uQ|2Du2LMQQ((M C A"{c'9i'mmF$;<KK$IIc;/J1<<>*HxQ\\^!45Q
+X6
9$llnSf)<a%@8LG GGEN3zF/BA+FR uG  3x=)999|a/00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   ?K3!
K9,K>)NNT|NN)rB   rC   rD   rE   rG   unittestTestCaser   staticmethodrd   r   Optionalr   boolUnionr   rF   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   rF   r   r   <module>r      s.    & 	    !{
 {
r   