





import html

from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
from ...utils import is_bsa_available, logging, requires_backends


if is_bsa_available():
	import bsa
	from bsa import BeautifulSoup


_lowerCamelCase   				=			logging.get_logger(__name__)




class   UpperCamelCase_       (     UpperCamelCase__    ):


							def __init__(							self    :Dict							,				**__A    :List[Any]		)   ->   List[Any]:



									"""simple docstring"""



									requires_backends(self							,				["""bs4"""]		)
									super().__init__(**__A		)


							def      _snake_case  (							self    :List[str]							,				__A    :Union[str, Any]		)   ->   int:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      []
									SCREAMING_SNAKE_CASE__			=      []
									SCREAMING_SNAKE_CASE__			=      element if element.name else element.parent
									for parent in child.parents:  # type: bs4.element.Tag
											SCREAMING_SNAKE_CASE__			=      parent.find_all(child.name							,				recursive=__A		)
											xpath_tags.append(child.name		)
											xpath_subscripts.append(
											    0 if 1 == len(__A		) else next(i for i, s in enumerate(__A							,				1		) if s is child		)		)
											SCREAMING_SNAKE_CASE__			=      parent
									xpath_tags.reverse()
									xpath_subscripts.reverse()
									return xpath_tags, xpath_subscripts


							def      _snake_case  (							self    :Optional[int]							,				__A    :str		)   ->   str:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      BeautifulSoup(__A							,				"""html.parser"""		)

									SCREAMING_SNAKE_CASE__			=      []
									SCREAMING_SNAKE_CASE__			=      []
									SCREAMING_SNAKE_CASE__			=      []

									for element in html_code.descendants:
											if type(__A		) == bsa.element.NavigableString:
													if type(element.parent		) != bsa.element.Tag:
															continue

													SCREAMING_SNAKE_CASE__			=      html.unescape(__A		).strip()
													if not text_in_this_tag:
															continue

													all_doc_strings.append(__A		)

													SCREAMING_SNAKE_CASE__	,						SCREAMING_SNAKE_CASE__			=      self.xpath_soup(__A		)
													stringaxtag_seq.append(__A		)
													stringaxsubs_seq.append(__A		)

									if len(__A		) != len(__A		):
											raise ValueError("""Number of doc strings and xtags does not correspond"""		)
									if len(__A		) != len(__A		):
											raise ValueError("""Number of doc strings and xsubs does not correspond"""		)

									return all_doc_strings, stringaxtag_seq, stringaxsubs_seq


							def      _snake_case  (							self    :Optional[Any]							,				__A    :str							,				__A    :str		)   ->   Optional[int]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      """"""
									for tagname, subs in zip(__A							,				__A		):
											xpath += f'''/{tagname}'''
											if subs != 0:
													xpath += f'''[{subs}]'''
									return xpath


							def __call__(							self    :Dict							,				__A    :List[Any]		)   ->   BatchFeature:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__			=      False

									# Check that strings has a valid type
									if isinstance(__A							,				__A		):
											SCREAMING_SNAKE_CASE__			=      True
									elif isinstance(__A							,				(list, tuple)		):
											if len(__A		) == 0 or isinstance(html_strings[0]							,				__A		):
													SCREAMING_SNAKE_CASE__			=      True

									if not valid_strings:
											raise ValueError(
											    """HTML strings must of type `str`, `List[str]` (batch of examples), """
											    f'''but is of type {type(__A		)}.'''		)

									SCREAMING_SNAKE_CASE__			=      bool(isinstance(__A							,				(list, tuple)		) and (isinstance(html_strings[0]							,				__A		))		)

									if not is_batched:
											SCREAMING_SNAKE_CASE__			=      [html_strings]

									# Get nodes + xpaths
									SCREAMING_SNAKE_CASE__			=      []
									SCREAMING_SNAKE_CASE__			=      []
									for html_string in html_strings:
											SCREAMING_SNAKE_CASE__	,						SCREAMING_SNAKE_CASE__	,						SCREAMING_SNAKE_CASE__			=      self.get_three_from_single(__A		)
											nodes.append(__A		)
											SCREAMING_SNAKE_CASE__			=      []
											for node, tag_list, sub_list in zip(__A							,				__A							,				__A		):
													SCREAMING_SNAKE_CASE__			=      self.construct_xpath(__A							,				__A		)
													xpath_strings.append(__A		)
											xpaths.append(__A		)

									# return as Dict
									SCREAMING_SNAKE_CASE__			=      {"""nodes""": nodes, """xpaths""": xpaths}
									SCREAMING_SNAKE_CASE__			=      BatchFeature(data=__A							,				tensor_type=__A		)

									return encoded_inputs






import warnings
from functools import wraps
from typing import Callable






def 				SCREAMING_SNAKE_CASE__							(       UpperCamelCase__:							Callable    ):

		@wraps(UpperCamelCase__    )
		def _inner_fn(*UpperCamelCase__:							Dict					,   **UpperCamelCase__:							Any    ):
				warnings.warn(
				    (f'''\'{fn.__name__}\' is experimental and might be subject to breaking changes in the future.''')					,   UpperCamelCase__					,   )
				return fn(*UpperCamelCase__					,   **UpperCamelCase__    )

		return _inner_fn