



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


__magic_name__       =     get_logger(__name__)


if TYPE_CHECKING:
		from .builder import DatasetBuilder





def 		__snake_case						(    _UpperCAmelCase       ,			_UpperCAmelCase = None				):
					"""simple docstring"""






					lowercase						   =       importlib.import_module(_UpperCAmelCase				)

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

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

										lowercase						   =       'wrap_auth'
										return wrapper

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





def 		__snake_case						(    _UpperCAmelCase				):
					"""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":
																				lowercase						   =       imports[1]
																				lowercase						   =       '.'.join(builder.__module__.split('.'				)[:-1] + [internal_import_name]				)
																				extend_module_for_streaming(_UpperCAmelCase       ,			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

					lowercase						   =       [
					    cls.__module__
					    for cls in type(_UpperCAmelCase				).__mro__[1:]  # make sure it's not the same module we've already patched
					    if issubclass(cls       ,			_UpperCAmelCase				) 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(_UpperCAmelCase       ,			use_auth_token=builder.use_auth_token				)











from __future__ import annotations

# Define the Gravitational Constant G and the function
__magic_name__       =     6.6743E-11  # unit of G : m^3 * kg^-1 * s^-2





def 		__snake_case						(    _UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase				):
					"""simple docstring"""






					lowercase						   =       mass_a * mass_a

					if (force, mass_a, mass_a, distance).count(0				) != 1:
										raise ValueError('One and only one argument must be 0'				)
					if force < 0:
										raise ValueError('Gravitational force can not be negative'				)
					if distance < 0:
										raise ValueError('Distance can not be negative'				)
					if mass_a < 0 or mass_a < 0:
										raise ValueError('Mass can not be negative'				)
					if force == 0:
										lowercase						   =       GRAVITATIONAL_CONSTANT * product_of_mass / (distance**2)
										return {"force": force}
					elif mass_a == 0:
										lowercase						   =       (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
										return {"mass_1": mass_a}
					elif mass_a == 0:
										lowercase						   =       (force) * (distance**2) / (GRAVITATIONAL_CONSTANT * mass_a)
										return {"mass_2": mass_a}
					elif distance == 0:
										lowercase						   =       (GRAVITATIONAL_CONSTANT * product_of_mass / (force)) ** 0.5
										return {"distance": distance}
					raise ValueError('One and only one argument must be 0'				)


# Run doctest
if __name__ == "__main__":
		import doctest

		doctest.testmod()






