
"""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	 =							get_logger(__name__)


if TYPE_CHECKING:
    from .builder import DatasetBuilder







def 			__a  (	__lowerCamelCase,	__lowerCamelCase = None						):
   UpperCAmelCase_      :      int      =					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						)

      UpperCAmelCase_      :      Tuple      =					"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()
   UpperCAmelCase_      :      List[str]      =					True







def 			__a  (	__lowerCamelCase						):
   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_      :      Tuple      =					imports[1]
            UpperCAmelCase_      :      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

   UpperCAmelCase_      :      Union[str, 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"""





from __future__ import annotations

from typing import Any


class A_			:




  '''simple docstring'''







  def __init__(	self       ,     lowercase_       ,     lowercase_						):  # noqa: A002

     """simple docstring"""
     UpperCAmelCase_      :      Optional[Any]      =					item
     UpperCAmelCase_      :      Optional[Any]      =					next




class A_			:




  '''simple docstring'''







  def __init__(	self						):

     """simple docstring"""
     UpperCAmelCase_      :      Node | None      =					None
     UpperCAmelCase_      :      Optional[int]      =					0







  def  UpperCamelCase__      (	self       ,     lowercase_						):

     """simple docstring"""
     UpperCAmelCase_      :      int      =					Node(lowercase_       ,     self.head						)
     self.size += 1







  def  UpperCamelCase__      (	self						):

     """simple docstring"""
     # Switched 'self.is_empty()' to 'self.head is None'
     # because mypy was considering the possibility that 'self.head'
     # can be None in below else part and giving error
     if self.head is None:
        return None
     else:
        UpperCAmelCase_      :      int      =					self.head.item
        UpperCAmelCase_      :      str      =					self.head.next
        self.size -= 1
        return item







  def  UpperCamelCase__      (	self						):

     """simple docstring"""
     return self.head is None







  def __str__(	self						):

     """simple docstring"""
     if self.is_empty():
        return ""
     else:
        UpperCAmelCase_      :      str      =					self.head
        UpperCAmelCase_      :      str      =					""
        UpperCAmelCase_      :      list[str]      =					[]
        while iterate:
           item_list.append(str(iterate.item						)						)
           UpperCAmelCase_      :      Tuple      =					iterate.next

        UpperCAmelCase_      :      Optional[Any]      =					" --> ".join(lowercase_						)

        return item_str







  def __len__(	self						):

     """simple docstring"""
     return self.size


