





import unittest

from transformers.testing_utils import require_bsa
from transformers.utils import is_bsa_available

from ...test_feature_extraction_common import FeatureExtractionSavingTestMixin


if is_bsa_available():
   from transformers import MarkupLMFeatureExtractor




class 			__UpperCamelCase    (							unittest.TestCase    ):





     def __init__(     self				,							_UpperCamelCase					):
        _UpperCAmelCase           =   parent





     def 		UpperCamelCase(     self					):
        return {}




def      A__       (    )  ->  Union[str, Any]:






   """simple docstring"""







   _UpperCAmelCase           =   '''<HTML>

    <HEAD>
    <TITLE>sample document</TITLE>
    </HEAD>

    <BODY BGCOLOR="FFFFFF">
    <HR>
    <a href="http://google.com">Goog</a>
    <H1>This is one header</H1>
    <H2>This is a another Header</H2>
    <P>Travel from
        <P>
        <B>SFO to JFK</B>
        <BR>
        <B><I>on May 2, 2015 at 2:00 pm. For details go to confirm.com </I></B>
        <HR>
        <div style="color:#0000FF">
            <h3>Traveler <b> name </b> is
            <p> John Doe </p>
        </div>'''

   _UpperCAmelCase           =   '''
    <!DOCTYPE html>
    <html>
    <body>

    <h1>My First Heading</h1>
    <p>My first paragraph.</p>

    </body>
    </html>
    '''

   return [html_string_a, html_string_a]




@require_bsa
class 			__UpperCamelCase    (							A__	, unittest.TestCase    ):
     __A	:  Optional[int]							  =   MarkupLMFeatureExtractor if is_bsa_available() else None





     def 		UpperCamelCase(     self					):
        _UpperCAmelCase           =   MarkupLMFeatureExtractionTester(self					)





     @property
     def 		UpperCamelCase(     self					):
        return self.feature_extract_tester.prepare_feat_extract_dict()





     def 		UpperCamelCase(     self					):
        # Initialize feature_extractor
        _UpperCAmelCase           =   self.feature_extraction_class()

        # Test not batched input
        _UpperCAmelCase           =   get_html_strings()[0]
        _UpperCAmelCase           =   feature_extractor(_UpperCamelCase					)

        # fmt: off
        _UpperCAmelCase           =   [['''sample document''', '''Goog''', '''This is one header''', '''This is a another Header''', '''Travel from''', '''SFO to JFK''', '''on May 2, 2015 at 2:00 pm. For details go to confirm.com''', '''Traveler''', '''name''', '''is''', '''John Doe''']]
        _UpperCAmelCase           =   [['''/html/head/title''', '''/html/body/a''', '''/html/body/h1''', '''/html/body/h2''', '''/html/body/p''', '''/html/body/p/p/b[1]''', '''/html/body/p/p/b[2]/i''', '''/html/body/p/p/div/h3''', '''/html/body/p/p/div/h3/b''', '''/html/body/p/p/div/h3''', '''/html/body/p/p/div/h3/p''']]
        # fmt: on

        self.assertEqual(encoding.nodes				,							_UpperCamelCase					)
        self.assertEqual(encoding.xpaths				,							_UpperCamelCase					)

        # Test batched
        _UpperCAmelCase           =   get_html_strings()
        _UpperCAmelCase           =   feature_extractor(_UpperCamelCase					)

        # fmt: off
        _UpperCAmelCase           =   expected_nodes + [['''My First Heading''', '''My first paragraph.''']]
        _UpperCAmelCase           =   expected_xpaths + [['''/html/body/h1''', '''/html/body/p''']]

        self.assertEqual(len(encoding.nodes					)				,							2					)
        self.assertEqual(len(encoding.xpaths					)				,							2					)

        self.assertEqual(encoding.nodes				,							_UpperCamelCase					)
        self.assertEqual(encoding.xpaths				,							_UpperCamelCase					)






from typing import List

from .keymap import KEYMAP, get_character
def      A__       (    SCREAMING_SNAKE_CASE_   :      str						)  ->  List[str]:






   """simple docstring"""







   def decorator(SCREAMING_SNAKE_CASE_   :      List[Any]						):
      _UpperCAmelCase           =   getattr(SCREAMING_SNAKE_CASE_				,	'''handle_key'''				,	[]						)
      handle += [key]
      setattr(SCREAMING_SNAKE_CASE_				,	'''handle_key'''				,	SCREAMING_SNAKE_CASE_						)
      return func

   return decorator
def      A__       (    *SCREAMING_SNAKE_CASE_   :      List[str]						)  ->  Dict:






   """simple docstring"""







   def decorator(SCREAMING_SNAKE_CASE_   :      Any						):
      _UpperCAmelCase           =   getattr(SCREAMING_SNAKE_CASE_				,	'''handle_key'''				,	[]						)
      handle += keys
      setattr(SCREAMING_SNAKE_CASE_				,	'''handle_key'''				,	SCREAMING_SNAKE_CASE_						)
      return func

   return decorator




class 			__UpperCamelCase    (							A__    ):





     def __new__(     cls				,							_UpperCamelCase				,							_UpperCamelCase				,							_UpperCamelCase					):
        _UpperCAmelCase           =   super().__new__(cls				,							_UpperCamelCase				,							_UpperCamelCase				,							_UpperCamelCase					)
        if not hasattr(_UpperCamelCase				,							'''key_handler'''					):
           setattr(_UpperCamelCase				,							'''key_handler'''				,							{}					)
        setattr(_UpperCamelCase				,							'''handle_input'''				,							KeyHandler.handle_input					)

        for value in attrs.values():
           _UpperCAmelCase           =   getattr(_UpperCamelCase				,							'''handle_key'''				,							[]					)
           for key in handled_keys:
              _UpperCAmelCase           =   value
        return new_cls





     @staticmethod
     def 		UpperCamelCase(     cls					):
        _UpperCAmelCase           =   get_character()
        if char != KEYMAP["undefined"]:
           _UpperCAmelCase           =   ord(_UpperCamelCase					)
        _UpperCAmelCase           =   cls.key_handler.get(_UpperCamelCase					)
        if handler:
           _UpperCAmelCase           =   char
           return handler(cls					)
        else:
           return None




def      A__       (    cls   :      Union[str, Any]						)  ->  Any:






   """simple docstring"""







   return KeyHandler(cls.__name__				,	cls.__bases__				,	cls.__dict__.copy()						)