

'''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				: Dict         =  get_logger(__name__)


if TYPE_CHECKING:
  from .builder import DatasetBuilder







def      a__ (						a__   ,					a__ = None		)     ->   Optional[Any]:




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   importlib.import_module(a__		)

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

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

          __SCREAMING_SNAKE_CASE						     =   """wrap_auth"""
          return wrapper

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







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




     """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":
                    __SCREAMING_SNAKE_CASE						     =   imports[1]
                    __SCREAMING_SNAKE_CASE						     =   """.""".join(builder.__module__.split("""."""		)[:-1] + [internal_import_name]		)
                    extend_module_for_streaming(a__   ,					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

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









'''simple docstring'''



from __future__ import annotations

from collections.abc import Callable







def      a__ (						a__   ,					a__   ,					a__   ,					a__ = 1_00   ,					):




     """simple docstring"""


     __SCREAMING_SNAKE_CASE						     =   x_start
     __SCREAMING_SNAKE_CASE						     =   fnc(a__		)
     __SCREAMING_SNAKE_CASE						     =   0.0

     for _ in range(a__		):
          # Approximates small segments of curve as linear and solve
          # for trapezoidal area
          __SCREAMING_SNAKE_CASE						     =   (x_end - x_start) / steps + xa
          __SCREAMING_SNAKE_CASE						     =   fnc(a__		)
          area += abs(fxa + fxa		) * (xa - xa) / 2

          # Increment step
          __SCREAMING_SNAKE_CASE						     =   xa
          __SCREAMING_SNAKE_CASE						     =   fxa
     return area


if __name__ == "__main__":







  def      a__ (						a__		):




       """simple docstring"""


       return x**3

  print('f(x) = x^3')
  print('The area between the curve, x = -10, x = 10 and the x axis is:')
  UpperCAmelCase				: Optional[Any]         =  1_0
  while i <= 1_0_0_0_0_0:
    UpperCAmelCase				: Union[str, Any]         =  trapezoidal_area(f, -5, 5, i)
    print(f"""with {i} steps: {area}""")
    i *= 1_0






