





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       __A     (						unittest.TestCase    ):


				def __init__(		self   , UpperCAmelCase_							):
								lowerCamelCase	 =parent


				def _snake_case       (		self							):
								return {}





def      _lowercase					(						)						->  str:
				lowerCamelCase	 ="""<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>"""

				lowerCamelCase	 ="""
    <!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       __A     (						a    ,					unittest.TestCase    ):
				__A      =				MarkupLMFeatureExtractor if is_bsa_available() else None


				def _snake_case       (		self							):
								lowerCamelCase	 =MarkupLMFeatureExtractionTester(self							)


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


				def _snake_case       (		self							):
								# Initialize feature_extractor
								lowerCamelCase	 =self.feature_extraction_class()

								# Test not batched input
								lowerCamelCase	 =get_html_strings()[0]
								lowerCamelCase	 =feature_extractor(UpperCAmelCase_							)

								# fmt: off
								lowerCamelCase	 =[["""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"""]]
								lowerCamelCase	 =[["""/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
								lowerCamelCase	 =get_html_strings()
								lowerCamelCase	 =feature_extractor(UpperCAmelCase_							)

								# fmt: off
								lowerCamelCase	 =expected_nodes + [["""My First Heading""", """My first paragraph."""]]
								lowerCamelCase	 =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      _lowercase					(						_UpperCAmelCase				)						->  Tuple:

				def decorator(_UpperCAmelCase				):
								lowerCamelCase	 =getattr(_UpperCAmelCase			,      """handle_key"""			,      []				)
								handle += [key]
								setattr(_UpperCAmelCase			,      """handle_key"""			,      _UpperCAmelCase				)
								return func

				return decorator





def      _lowercase					(						*_UpperCAmelCase				)						->  Tuple:

				def decorator(_UpperCAmelCase				):
								lowerCamelCase	 =getattr(_UpperCAmelCase			,      """handle_key"""			,      []				)
								handle += keys
								setattr(_UpperCAmelCase			,      """handle_key"""			,      _UpperCAmelCase				)
								return func

				return decorator

class       __A     (						a    ):


				def __new__(		cls   , UpperCAmelCase_   , UpperCAmelCase_   , UpperCAmelCase_							):
								lowerCamelCase	 =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():
												lowerCamelCase	 =getattr(UpperCAmelCase_   , """handle_key"""   , []							)
												for key in handled_keys:
																lowerCamelCase	 =value
								return new_cls


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





def      _lowercase					(						cls				)						->  List[str]:
				return KeyHandler(cls.__name__			,      cls.__bases__			,      cls.__dict__.copy()				)





