





'''simple docstring'''






import importlib
import inspect
from functools import wraps
from typing import TYPE_CHECKING, Optional, Union

from .download.streaming_download_manager import (
    xbasename,
    xdirname,
    xet_parse,
    xexists,
    xgetsize,
    xglob,
    xgzip_open,
    xisdir,
    xisfile,
    xjoin,
    xlistdir,
    xnumpy_load,
    xopen,
    xpandas_read_csv,
    xpandas_read_excel,
    xPath,
    xrelpath,
    xsio_loadmat,
    xsplit,
    xsplitext,
    xwalk,
    xxml_dom_minidom_parse,
)
from .utils.logging import get_logger
from .utils.patching import patch_submodule
from .utils.py_utils import get_imports


__UpperCamelCase										=  get_logger(__name__)


if TYPE_CHECKING:
	from .builder import DatasetBuilder







def 				_a	(					_lowerCamelCase						,  _lowerCamelCase = None   )   ->							str:



			"""simple docstring"""


			__snake_case				:			Any       			=    importlib.import_module(_lowerCamelCase   )

			# TODO(QL): always update the module to add subsequent new authentication
			if hasattr(_lowerCamelCase						,  """_patched_for_streaming"""   ) and module._patched_for_streaming:
						return

			def wrap_auth(_lowerCamelCase   ):
						@wraps(_lowerCamelCase   )
						def wrapper(*_lowerCamelCase						,  **_lowerCamelCase   ):
									return function(*_lowerCamelCase						,  use_auth_token=_lowerCamelCase						,  **_lowerCamelCase   )

						__snake_case				:			Union[str, Any]       			=    """wrap_auth"""
						return wrapper

			# open files in a streaming fashion
			patch_submodule(_lowerCamelCase						,  """open"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """os.listdir"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """os.walk"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """glob.glob"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			# allow to navigate in remote zip files
			patch_submodule(_lowerCamelCase						,  """os.path.join"""						,  _lowerCamelCase   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.dirname"""						,  _lowerCamelCase   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.basename"""						,  _lowerCamelCase   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.relpath"""						,  _lowerCamelCase   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.split"""						,  _lowerCamelCase   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.splitext"""						,  _lowerCamelCase   ).start()
			# allow checks on paths
			patch_submodule(_lowerCamelCase						,  """os.path.exists"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.isdir"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.isfile"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """os.path.getsize"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """pathlib.Path"""						,  _lowerCamelCase   ).start()
			# file readers
			patch_submodule(_lowerCamelCase						,  """gzip.open"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """numpy.load"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """pandas.read_csv"""						,  wrap_auth(_lowerCamelCase   )						,  attrs=["""__version__"""]   ).start()
			patch_submodule(_lowerCamelCase						,  """pandas.read_excel"""						,  wrap_auth(_lowerCamelCase   )						,  attrs=["""__version__"""]   ).start()
			patch_submodule(_lowerCamelCase						,  """scipy.io.loadmat"""						,  wrap_auth(_lowerCamelCase   )						,  attrs=["""__version__"""]   ).start()
			patch_submodule(_lowerCamelCase						,  """xml.etree.ElementTree.parse"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			patch_submodule(_lowerCamelCase						,  """xml.dom.minidom.parse"""						,  wrap_auth(_lowerCamelCase   )   ).start()
			__snake_case				:			Any       			=    True







def 				_a	(					_lowerCamelCase   )   ->							str:



			"""simple docstring"""


			extend_module_for_streaming(builder.__module__						,  use_auth_token=builder.use_auth_token   )
			# if needed, we also have to extend additional internal imports (like wmt14 -> wmt_utils)
			if not builder.__module__.startswith("""datasets."""   ):  # check that it's not a packaged builder like csv
						for imports in get_imports(inspect.getfile(builder.__class__   )   ):
									if imports[0] == "internal":
												__snake_case				:			Dict       			=    imports[1]
												__snake_case				:			Optional[int]       			=    """.""".join(builder.__module__.split("""."""   )[:-1] + [internal_import_name]   )
												extend_module_for_streaming(_lowerCamelCase						,  use_auth_token=builder.use_auth_token   )

    # builders can inherit from other builders that might use streaming functionality
    # (for example, ImageFolder and AudioFolder inherit from FolderBuilder which implements examples generation)
    # but these parents builders are not patched automatically as they are not instantiated, so we patch them here
			from .builder import DatasetBuilder

			__snake_case				:			Any       			=    [
			    cls.__module__
			    for cls in type(_lowerCamelCase   ).__mro__[1:]  # make sure it's not the same module we've already patched
			    if issubclass(cls						,  _lowerCamelCase   ) and cls.__module__ != DatasetBuilder.__module__
			]  # check it's not a standard builder from datasets.builder
			for module in parent_builder_modules:
						extend_module_for_streaming(_lowerCamelCase						,  use_auth_token=builder.use_auth_token   )









'''simple docstring'''






def 				_a	(					_lowerCamelCase   )   ->							bool:



			"""simple docstring"""


			__snake_case				:			Optional[Any]       			=    [list(_lowerCamelCase   ) for row in matrix]
			if matrix and isinstance(_lowerCamelCase						,  _lowerCamelCase   ):
						if isinstance(matrix[0]						,  _lowerCamelCase   ):
									__snake_case				:			str       			=    0
									for row in matrix:
												if prev_len == 0:
															__snake_case				:			Dict       			=    len(_lowerCamelCase   )
															__snake_case				:			List[Any]       			=    True
												else:
															__snake_case				:			Union[str, Any]       			=    prev_len == len(_lowerCamelCase   )
						else:
									__snake_case				:			List[Any]       			=    True
			else:
						__snake_case				:			List[str]       			=    False

			return result







def 				_a	(					_lowerCamelCase   )   ->							None:



			"""simple docstring"""


			if check_matrix(_lowerCamelCase   ) and len(_lowerCamelCase   ) > 0:
						__snake_case				:			List[str]       			=    [list(_lowerCamelCase   ) for row in a]
						__snake_case				:			Optional[Any]       			=    len(_lowerCamelCase   )
						if isinstance(a[0]						,  _lowerCamelCase   ):
									__snake_case				:			Tuple       			=    len(a[0]   )
						else:
									for dat in a:
												print(_lowerCamelCase   )
									return

						# horizotal printing increasing
						for i in range(0						,  _lowerCamelCase   ):
									print(a[0][i]   )
						# vertical printing down
						for i in range(1						,  _lowerCamelCase   ):
									print(a[i][mat_col - 1]   )
						# horizotal printing decreasing
						if mat_row > 1:
									for i in range(mat_col - 2						,  -1						,  -1   ):
												print(a[mat_row - 1][i]   )
        # vertical printing up
						for i in range(mat_row - 2						,  0						,  -1   ):
									print(a[i][0]   )
						__snake_case				:			Union[str, Any]       			=    [row[1 : mat_col - 1] for row in a[1 : mat_row - 1]]
						if len(_lowerCamelCase   ) > 0:
									spiral_print_clockwise(_lowerCamelCase   )
						else:
									return
			else:
						print("""Not a valid matrix"""   )
						return







def 				_a	(					_lowerCamelCase   )   ->							list[int]:



			"""simple docstring"""


			if matrix:
						return list(matrix.pop(0   )   ) + spiral_traversal(list(zip(*_lowerCamelCase   )   )[::-1]   )
			else:
						return []


# driver code
if __name__ == "__main__":
	import doctest

	doctest.testmod()

	__UpperCamelCase										=  [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
	spiral_print_clockwise(a)


