

'''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


_a			:	Tuple								=  get_logger(__name__)


if TYPE_CHECKING:
  from .builder import DatasetBuilder


def  lowerCamelCase__						(  SCREAMING_SNAKE_CASE :				Tuple    ,				SCREAMING_SNAKE_CASE :				Optional[Union[str, bool]] = None  ):
  UpperCAmelCase  							=		importlib.import_module(SCREAMING_SNAKE_CASE  )

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

  def wrap_auth(SCREAMING_SNAKE_CASE :				List[Any]  ):
    @wraps(SCREAMING_SNAKE_CASE  )
    def wrapper(*SCREAMING_SNAKE_CASE :				Any    ,				**SCREAMING_SNAKE_CASE :				Tuple  ):
      return function(*SCREAMING_SNAKE_CASE    ,				use_auth_token=SCREAMING_SNAKE_CASE    ,				**SCREAMING_SNAKE_CASE  )

    UpperCAmelCase  							=		'wrap_auth'
    return wrapper

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



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

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





'''simple docstring'''




from collections import namedtuple

_a			:	int								=  namedtuple('from_to', 'from_ to')

_a			:	Dict								=  {
    'atm': from_to(1, 1),
    'pascal': from_to(0.0000098, 101_325),
    'bar': from_to(0.986923, 1.01325),
    'kilopascal': from_to(0.00986923, 101.325),
    'megapascal': from_to(9.86923, 0.101325),
    'psi': from_to(0.068046, 14.6959),
    'inHg': from_to(0.0334211, 29.9213),
    'torr': from_to(0.00131579, 760),
}


def  lowerCamelCase__						(  SCREAMING_SNAKE_CASE :				float    ,				SCREAMING_SNAKE_CASE :				str    ,				SCREAMING_SNAKE_CASE :				str  ):
  if from_type not in PRESSURE_CONVERSION:
    raise ValueError(
        f'''Invalid \'from_type\' value: {from_type!r}  Supported values are:\n'''
        + ', '.join(SCREAMING_SNAKE_CASE  )  )
  if to_type not in PRESSURE_CONVERSION:
    raise ValueError(
        f'''Invalid \'to_type\' value: {to_type!r}.  Supported values are:\n'''
        + ', '.join(SCREAMING_SNAKE_CASE  )  )
  return (
      value * PRESSURE_CONVERSION[from_type].from_ * PRESSURE_CONVERSION[to_type].to
  )


if __name__ == "__main__":
  import doctest

  doctest.testmod()


