



'''simple docstring'''




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


UpperCamelCase__ :			str												=				logging.get_logger(__name__)






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			def __init__(							self  :				Tuple							,  **lowerCAmelCase__  :				Any		):





					"""simple docstring"""






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

			def UpperCamelCase__      (							self  :				int							,  lowerCAmelCase__  :				Optional[Any]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Tuple					 =	[]
					__SCREAMING_SNAKE_CASE :	Any					 =	[]
					__SCREAMING_SNAKE_CASE :	Dict					 =	element if element.name else element.parent
					for parent in child.parents:  # type: bs4.element.Tag
							__SCREAMING_SNAKE_CASE :	List[str]					 =	parent.find_all(child.name							,  recursive=lowerCAmelCase__		)
							xpath_tags.append(child.name		)
							xpath_subscripts.append(
							    0 if 1 == len(lowerCAmelCase__		) else next(i for i, s in enumerate(lowerCAmelCase__							,  1		) if s is child		)		)
							__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	parent
					xpath_tags.reverse()
					xpath_subscripts.reverse()
					return xpath_tags, xpath_subscripts

			def UpperCamelCase__      (							self  :				Optional[Any]							,  lowerCAmelCase__  :				str		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	List[str]					 =	BeautifulSoup(lowerCAmelCase__							,  """html.parser"""		)

					__SCREAMING_SNAKE_CASE :	Tuple					 =	[]
					__SCREAMING_SNAKE_CASE :	int					 =	[]
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	[]

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

									__SCREAMING_SNAKE_CASE :	str					 =	html.unescape(lowerCAmelCase__		).strip()
									if not text_in_this_tag:
											continue

									all_doc_strings.append(lowerCAmelCase__		)

									__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Dict					 =	self.xpath_soup(lowerCAmelCase__		)
									stringaxtag_seq.append(lowerCAmelCase__		)
									stringaxsubs_seq.append(lowerCAmelCase__		)

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

					return all_doc_strings, stringaxtag_seq, stringaxsubs_seq

			def UpperCamelCase__      (							self  :				Optional[Any]							,  lowerCAmelCase__  :				str							,  lowerCAmelCase__  :				Tuple		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	""""""
					for tagname, subs in zip(lowerCAmelCase__							,  lowerCAmelCase__		):
							xpath += F"/{tagname}"
							if subs != 0:
									xpath += F"[{subs}]"
					return xpath



			def __call__(							self  :				Optional[Any]							,  lowerCAmelCase__  :				Union[str, Any]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	int					 =	False

					# Check that strings has a valid type
					if isinstance(lowerCAmelCase__							,  lowerCAmelCase__		):
							__SCREAMING_SNAKE_CASE :	int					 =	True
					elif isinstance(lowerCAmelCase__							,  (list, tuple)		):
							if len(lowerCAmelCase__		) == 0 or isinstance(html_strings[0]							,  lowerCAmelCase__		):
									__SCREAMING_SNAKE_CASE :	List[Any]					 =	True

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

					__SCREAMING_SNAKE_CASE :	str					 =	bool(isinstance(lowerCAmelCase__							,  (list, tuple)		) and (isinstance(html_strings[0]							,  lowerCAmelCase__		))		)

					if not is_batched:
							__SCREAMING_SNAKE_CASE :	Optional[int]					 =	[html_strings]

					# Get nodes + xpaths
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	[]
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	[]
					for html_string in html_strings:
							__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	self.get_three_from_single(lowerCAmelCase__		)
							nodes.append(lowerCAmelCase__		)
							__SCREAMING_SNAKE_CASE :	Any					 =	[]
							for node, tag_list, sub_list in zip(lowerCAmelCase__							,  lowerCAmelCase__							,  lowerCAmelCase__		):
									__SCREAMING_SNAKE_CASE :	Tuple					 =	self.construct_xpath(lowerCAmelCase__							,  lowerCAmelCase__		)
									xpath_strings.append(lowerCAmelCase__		)
							xpaths.append(lowerCAmelCase__		)

					# return as Dict
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	{"""nodes""": nodes, """xpaths""": xpaths}
					__SCREAMING_SNAKE_CASE :	Dict					 =	BatchFeature(data=lowerCAmelCase__							,  tensor_type=lowerCAmelCase__		)

					return encoded_inputs




'''simple docstring'''




import warnings

from ...utils import logging
from .image_processing_deit import DeiTImageProcessor


UpperCamelCase__ :			List[str]												=				logging.get_logger(__name__)






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			def __init__(							self  :				Union[str, Any]							,  *lowerCAmelCase__  :				str							,  **lowerCAmelCase__  :				Any		):





					"""simple docstring"""






					warnings.warn(
					    """The class DeiTFeatureExtractor is deprecated and will be removed in version 5 of Transformers. Please"""
					    """ use DeiTImageProcessor instead."""							,  lowerCAmelCase__							,  )
					super().__init__(*lowerCAmelCase__							,  **lowerCAmelCase__		)