




"""simple docstring"""






class 	a__      :





						def __init__(				self   :						str)    ->							List[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Optional[Any]						=	0
											_lowerCAmelCase:List[Any]						=	0
											_lowerCAmelCase:List[Any]						=	{}





						def    __UpperCamelCase  (				self   :						List[str]  ,a__   :						List[Any])    ->							Dict:




											"""simple docstring"""







											if vertex not in self.adjacency:
																_lowerCAmelCase:List[str]						=	{}
																self.num_vertices += 1





						def    __UpperCamelCase  (				self   :						List[Any]  ,a__   :						Optional[Any]  ,a__   :						Optional[Any]  ,a__   :						int)    ->							int:




											"""simple docstring"""







											self.add_vertex(a__)
											self.add_vertex(a__)

											if head == tail:
																return

											_lowerCAmelCase:Tuple						=	weight
											_lowerCAmelCase:Optional[Any]						=	weight





						def    __UpperCamelCase  (				self   :						Optional[int])    ->							Optional[Any]:




											"""simple docstring"""







											_lowerCAmelCase:Any						=	self.get_edges()
											for edge in edges:
																_lowerCAmelCase:Union[str, Any]						=	edge
																edges.remove((tail, head, weight))
											for i in range(len(a__)):
																_lowerCAmelCase:Optional[int]						=	list(edges[i])

											edges.sort(key=lambda a__: e[2])
											for i in range(len(a__) - 1):
																if edges[i][2] >= edges[i + 1][2]:
																					_lowerCAmelCase:Optional[Any]						=	edges[i][2] + 1
											for edge in edges:
																_lowerCAmelCase:Union[str, Any]						=	edge
																_lowerCAmelCase:List[Any]						=	weight
																_lowerCAmelCase:Dict						=	weight





						def __str__(				self   :						Optional[Any])    ->							Optional[int]:




											"""simple docstring"""







											_lowerCAmelCase:int						=	""""""
											for tail in self.adjacency:
																for head in self.adjacency[tail]:
																					_lowerCAmelCase:Union[str, Any]						=	self.adjacency[head][tail]
																					string += F'{head} -> {tail} == {weight}\n'
											return string.rstrip('''\n''')





						def    __UpperCamelCase  (				self   :						int)    ->							List[str]:




											"""simple docstring"""







											_lowerCAmelCase:int						=	[]
											for tail in self.adjacency:
																for head in self.adjacency[tail]:
																					output.append((tail, head, self.adjacency[head][tail]))
											return output





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




											"""simple docstring"""







											return self.adjacency.keys()





						@staticmethod
						def    __UpperCamelCase  (				a__   :						int=None  ,a__   :						List[str]=None)    ->							Tuple:




											"""simple docstring"""







											_lowerCAmelCase:Dict						=	Graph()
											if vertices is None:
																_lowerCAmelCase:Tuple						=	[]
											if edges is None:
																_lowerCAmelCase:Optional[Any]						=	[]
											for vertex in vertices:
																g.add_vertex(a__)
											for edge in edges:
																g.add_edge(*a__)
											return g




						class 	a__      :





												def __init__(				self   :						int)    ->							Tuple:




																	"""simple docstring"""







																	_lowerCAmelCase:Optional[int]						=	{}
																	_lowerCAmelCase:Union[str, Any]						=	{}





												def __len__(				self   :						Tuple)    ->							Optional[int]:




																	"""simple docstring"""







																	return len(self.parent)





												def    __UpperCamelCase  (				self   :						str  ,a__   :						int)    ->							Optional[Any]:




																	"""simple docstring"""







																	if item in self.parent:
																						return self.find(a__)

																	_lowerCAmelCase:Any						=	item
																	_lowerCAmelCase:str						=	0
																	return item





												def    __UpperCamelCase  (				self   :						List[Any]  ,a__   :						str)    ->							List[Any]:




																	"""simple docstring"""







																	if item not in self.parent:
																						return self.make_set(a__)
																	if item != self.parent[item]:
																						_lowerCAmelCase:int						=	self.find(self.parent[item])
																	return self.parent[item]







												def    __UpperCamelCase  (				self   :						List[str]  ,a__   :						Dict  ,a__   :						Optional[int])    ->							List[str]:




																	"""simple docstring"""







																	_lowerCAmelCase:List[str]						=	self.find(a__)
																	_lowerCAmelCase:List[str]						=	self.find(a__)

																	if roota == roota:
																						return roota

																	if self.rank[roota] > self.rank[roota]:
																						_lowerCAmelCase:int						=	roota
																						return roota

																	if self.rank[roota] < self.rank[roota]:
																						_lowerCAmelCase:Union[str, Any]						=	roota
																						return roota

																	if self.rank[roota] == self.rank[roota]:
																						self.rank[roota] += 1
																						_lowerCAmelCase:Union[str, Any]						=	roota
																						return roota
																	return None





						@staticmethod
						def    __UpperCamelCase  (				a__   :						int)    ->							Union[str, Any]:




											"""simple docstring"""







											_lowerCAmelCase:Any						=	graph.num_vertices

											_lowerCAmelCase:Dict						=	Graph.UnionFind()
											_lowerCAmelCase:Dict						=	[]
											while num_components > 1:
																_lowerCAmelCase:Optional[int]						=	{}
																for vertex in graph.get_vertices():
																					_lowerCAmelCase:Union[str, Any]						=	-1

																_lowerCAmelCase:Optional[Any]						=	graph.get_edges()
																for edge in edges:
																					_lowerCAmelCase:Union[str, Any]						=	edge
																					edges.remove((tail, head, weight))
																for edge in edges:
																					_lowerCAmelCase:Optional[Any]						=	edge
																					_lowerCAmelCase:List[Any]						=	union_find.find(a__)
																					_lowerCAmelCase:Union[str, Any]						=	union_find.find(a__)
																					if seta != seta:
																										if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																															_lowerCAmelCase:str						=	[head, tail, weight]

																										if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																															_lowerCAmelCase:Optional[int]						=	[head, tail, weight]
																for vertex in cheap_edge:
																					if cheap_edge[vertex] != -1:
																										_lowerCAmelCase:Any						=	cheap_edge[vertex]
																										if union_find.find(a__) != union_find.find(a__):
																															union_find.union(a__  ,a__)
																															mst_edges.append(cheap_edge[vertex])
																															_lowerCAmelCase:int						=	num_components - 1
											_lowerCAmelCase:Optional[int]						=	Graph.build(edges=a__)
											return mst













'''simple docstring'''






import json
import os
from pathlib import Path

import pytest

from datasets.download.download_config import DownloadConfig
from datasets.download.download_manager import DownloadManager
from datasets.utils.file_utils import hash_url_to_filename


__UpperCamelCase					    =	"http://www.mocksite.com/file1.txt"
__UpperCamelCase					    =	"\"text\": [\"foo\", \"foo\"]"
__UpperCamelCase					    =	"6d8ce9aa78a471c7477201efbeabd3bb01ac2e7d100a6dc024ba1608361f90a8"




class  _A :
		lowercase__:   str				     =   200
		lowercase__:   List[str]				     =   {'''Content-Length''': '''100'''}
		lowercase__:   Union[str, Any]				     =   {}

		def 	lowercase__     (   self					:   Any  ,      **__magic_name__					:   List[Any]			)					->    Dict:


					"""simple docstring"""

					return [bytes(__magic_name__  ,      """utf-8"""			)]







def 					_a						(       *_lowerCamelCase    ,	**_lowerCamelCase ) ->				List[str]:



			"""simple docstring"""


			return MockResponse()







@pytest.mark.parametrize("""urls_type"""    ,	[str, list, dict] )
def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase ) ->				List[str]:



			"""simple docstring"""


			import requests

			monkeypatch.setattr(_lowerCamelCase    ,	"""request"""    ,	_lowerCamelCase )

			__snake_case					:      Union[str, Any]							      =     URL
			if issubclass(_lowerCamelCase    ,	_lowerCamelCase ):
						__snake_case					:      str							      =     url
			elif issubclass(_lowerCamelCase    ,	_lowerCamelCase ):
						__snake_case					:      Dict							      =     [url]
			elif issubclass(_lowerCamelCase    ,	_lowerCamelCase ):
						__snake_case					:      Union[str, Any]							      =     {"""train""": url}
			__snake_case					:      Dict							      =     """dummy"""
			__snake_case					:      List[str]							      =     """downloads"""
			__snake_case					:      List[Any]							      =     tmp_path
			__snake_case					:      List[Any]							      =     DownloadConfig(
			    cache_dir=os.path.join(_lowerCamelCase    ,	_lowerCamelCase )    ,	use_etag=_lowerCamelCase    ,	)
			__snake_case					:      List[str]							      =     DownloadManager(dataset_name=_lowerCamelCase    ,	download_config=_lowerCamelCase )
			__snake_case					:      int							      =     dl_manager.download(_lowerCamelCase )
			__snake_case					:      Tuple							      =     urls
			for downloaded_paths in [downloaded_paths]:
						if isinstance(_lowerCamelCase    ,	_lowerCamelCase ):
									__snake_case					:      Any							      =     [downloaded_paths]
									__snake_case					:      List[Any]							      =     [urls]
						elif isinstance(_lowerCamelCase    ,	_lowerCamelCase ):
									assert "train" in downloaded_paths.keys()
									__snake_case					:      Tuple							      =     downloaded_paths.values()
									__snake_case					:      Optional[int]							      =     urls.values()
						assert downloaded_paths
						for downloaded_path, input_url in zip(_lowerCamelCase    ,	_lowerCamelCase ):
									assert downloaded_path == dl_manager.downloaded_paths[input_url]
									__snake_case					:      List[str]							      =     Path(_lowerCamelCase )
									__snake_case					:      Any							      =     downloaded_path.parts
									assert parts[-1] == HASH
									assert parts[-2] == cache_subdir
									assert downloaded_path.exists()
									__snake_case					:      Union[str, Any]							      =     downloaded_path.read_text()
									assert content == CONTENT
									__snake_case					:      List[str]							      =     downloaded_path.with_suffix(""".json""" )
									assert metadata_downloaded_path.exists()
									__snake_case					:      Union[str, Any]							      =     json.loads(metadata_downloaded_path.read_text() )
									assert metadata_content == {"url": URL, "etag": None}







@pytest.mark.parametrize("""paths_type"""    ,	[str, list, dict] )
def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase    ,	_lowerCamelCase ) ->				List[Any]:



			"""simple docstring"""


			__snake_case					:      Any							      =     str(_lowerCamelCase )
			if issubclass(_lowerCamelCase    ,	_lowerCamelCase ):
						__snake_case					:      Optional[int]							      =     filename
			elif issubclass(_lowerCamelCase    ,	_lowerCamelCase ):
						__snake_case					:      Tuple							      =     [filename]
			elif issubclass(_lowerCamelCase    ,	_lowerCamelCase ):
						__snake_case					:      Dict							      =     {"""train""": filename}
			__snake_case					:      Optional[Any]							      =     """dummy"""
			__snake_case					:      List[Any]							      =     xz_file.parent
			__snake_case					:      int							      =     """extracted"""
			__snake_case					:      Dict							      =     DownloadConfig(
			    cache_dir=_lowerCamelCase    ,	use_etag=_lowerCamelCase    ,	)
			__snake_case					:      List[str]							      =     DownloadManager(dataset_name=_lowerCamelCase    ,	download_config=_lowerCamelCase )
			__snake_case					:      Optional[Any]							      =     dl_manager.extract(_lowerCamelCase )
			__snake_case					:      Union[str, Any]							      =     paths
			for extracted_paths in [extracted_paths]:
						if isinstance(_lowerCamelCase    ,	_lowerCamelCase ):
									__snake_case					:      Dict							      =     [extracted_paths]
									__snake_case					:      int							      =     [paths]
						elif isinstance(_lowerCamelCase    ,	_lowerCamelCase ):
									assert "train" in extracted_paths.keys()
									__snake_case					:      int							      =     extracted_paths.values()
									__snake_case					:      int							      =     paths.values()
						assert extracted_paths
						for extracted_path, input_path in zip(_lowerCamelCase    ,	_lowerCamelCase ):
									assert extracted_path == dl_manager.extracted_paths[input_path]
									__snake_case					:      Any							      =     Path(_lowerCamelCase )
									__snake_case					:      str							      =     extracted_path.parts
									assert parts[-1] == hash_url_to_filename(_lowerCamelCase    ,	etag=_lowerCamelCase )
									assert parts[-2] == extracted_subdir
									assert extracted_path.exists()
									__snake_case					:      Optional[int]							      =     extracted_path.read_text()
									__snake_case					:      str							      =     text_file.read_text()
									assert extracted_file_content == expected_file_content







def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase ) ->				Optional[int]:



			"""simple docstring"""


			assert path.endswith(""".jsonl""" )
			for num_items, line in enumerate(_lowerCamelCase    ,	start=1 ):
						__snake_case					:      Tuple							      =     json.loads(line.decode("""utf-8""" ) )
						assert item.keys() == {"col_1", "col_2", "col_3"}
			assert num_items == 4







@pytest.mark.parametrize("""archive_jsonl"""    ,	["""tar_jsonl_path""", """zip_jsonl_path"""] )
def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase ) ->				Optional[int]:



			"""simple docstring"""


			__snake_case					:      Any							      =     request.getfixturevalue(_lowerCamelCase )
			__snake_case					:      str							      =     DownloadManager()
			for num_jsonl, (path, file) in enumerate(dl_manager.iter_archive(_lowerCamelCase )    ,	start=1 ):
						_test_jsonl(_lowerCamelCase    ,	_lowerCamelCase )
			assert num_jsonl == 2







@pytest.mark.parametrize("""archive_nested_jsonl"""    ,	["""tar_nested_jsonl_path""", """zip_nested_jsonl_path"""] )
def 					_a						(       _lowerCamelCase    ,	_lowerCamelCase ) ->				List[str]:



			"""simple docstring"""


			__snake_case					:      int							      =     request.getfixturevalue(_lowerCamelCase )
			__snake_case					:      List[str]							      =     DownloadManager()
			for num_tar, (path, file) in enumerate(dl_manager.iter_archive(_lowerCamelCase )    ,	start=1 ):
						for num_jsonl, (subpath, subfile) in enumerate(dl_manager.iter_archive(_lowerCamelCase )    ,	start=1 ):
									_test_jsonl(_lowerCamelCase    ,	_lowerCamelCase )
			assert num_tar == 1
			assert num_jsonl == 2







def 					_a						(       _lowerCamelCase ) ->				Any:



			"""simple docstring"""


			__snake_case					:      List[str]							      =     DownloadManager()
			for num_file, file in enumerate(dl_manager.iter_files(_lowerCamelCase )    ,	start=1 ):
						assert os.path.basename(_lowerCamelCase ) == ("test.txt" if num_file == 1 else "train.txt")
			assert num_file == 2


