
    DgZ9                     P    d dl mZ d dlZd dlZddlmZmZmZmZm	Z	  G d d      Z
y)    )contextmanagerN   )ParserElementParseExceptionKeyword__diag__
__compat__c                      e Zd ZdZ G d d      Z G d d      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::

            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 | _         y N)_save_contextselfs    Q/var/www/highfloat_scraper/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.save2   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         _        | 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.restoreR   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 150B0B<0PJ-Kr   c                 p     t        |              }|j                  j                  | j                         |S r   )typer   update)r   rets     r   copyz+pyparsing_test.reset_pyparsing_context.copys   s.    $t*,C$$T%7%78Jr   c                 "    | j                         S r   )r+   r   s    r   	__enter__z0pyparsing_test.reset_pyparsing_context.__enter__x   s    99;r   c                 $    | j                          y r   )r4   )r   argss     r   __exit__z/pyparsing_test.reset_pyparsing_context.__exit__{   s    LLNr   N)
__name__
__module____qualname____doc__r   r+   r4   r9   r;   r>    r   r   reset_pyparsing_contextr      s'    	0	$	@	B	
		r   rD   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_dictrI   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 ``ParseResults.asList()`` is equal to the ``expected_list``.
            T)	parse_all)rN   rI   Nparse_stringprintdumprK   rP   )r   exprtest_stringrN   rI   verboserM   s          r   assertParseAndCheckListz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckList   sO     &&{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 ``ParseResults.asDict()`` is equal to the ``expected_dict``.
            T)parseAll)rO   rI   NrS   )r   rW   rX   rO   rI   rY   rM   s          r   assertParseAndCheckDictz>pyparsing_test.TestParseResultsAsserts.assertParseAndCheckDict   sO     &&{T&BFfkkm$fnn&'))&SV)Wr   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)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)]
            Nzfailed runTestsrH   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   )r`   r6   
issubclass	Exceptionrb   s     r   re   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   s+      %c40ZY5O s   ,.)expected_exceptionrI   c              3   B   K   | ]  }t        |t              s|  y wr   )r`   listrb   s     r   re   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>        JJsD4IJrf   c              3   B   K   | ]  }t        |t              s|  y wr   )r`   dictrb   s     r   re   zNpyparsing_test.TestParseResultsAsserts.assertRunTestResults.<locals>.<genexpr>   rm   rf   NN)rN   rO   rI   zno validation for )
assertTruezipnextassertRaisesr`   ri   rP   rU   )r   run_tests_reportexpected_parse_resultsrI   run_test_successrun_test_resultsrptexpectedmergedrX   rM   fail_msgrj   rN   rO   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)NrH   )r`   ra   reescapeassertRaisesRegexrt   )r   exc_typeexpected_msgrI   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)NTrp   )r?   r@   rA   rB   rP   rZ   r]   r}   r   r   r   rC   r   r   TestParseResultsAssertsrF   ~   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                   |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        |       }t        |t        |             }t        t        d|      |      }|dk7  r| j!                         ||z
  | }n'| j#                  d      ||z
  | D cg c]  }|dz   	 }}|sy	t        t        |            t        d |D              }ddz   z  z   }|dk\  rA||rd	ndz   d	j%                  d t        |rdnd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   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: 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   2   K   | ]  }t        |        y wr   )len)rc   lines     r   re   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>J  s     93t99   r   c   c              3   4   K   | ]  }d  |dz   dz     yw)zc                                                                                                   r   d   NrC   rc   is     r   re   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>P  s)        j!a%30s   r   
c              3   2   K   | ]  }d |dz   dz     yw)z	         r   
   NrC   r   s     r   re   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>[  s     XQ	1q5B,0Xr   r   
12345678900c              3   B   K   | ]  \  }} | d d|    yw)d:NrC   )rc   r   r   r   r   lineno_widths      r   re   z3pyparsing_test.with_line_numbers.<locals>.<genexpr>e  s:      At (1l^1,-QtfXJ?s   )start)
expandtabsr`   inttypingcastra   rr   range	maketransordrl   	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_numbersz pyparsing_test.with_line_numbers   s9   H 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1vHxQ(Q
+X6
9$llnZ&%88DG *+
V8Kh)W!%uG  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   ?K!
K<K)NNT|NN)r?   r@   rA   rB   rD   r   staticmethodra   r   Optionalr   boolUnionr   rC   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   rC   r   r   <module>r      s&    & 	  Y
 Y
r   