





from importlib import import_module

from .logging import get_logger


_snake_case           =			get_logger(__name__)





class  lowerCAmelCase							:







  def __init__(      self  :List[str]   ,							_lowercase  :Dict   ,							_lowercase  :List[Any]=None ):






     '''simple docstring'''





     lowercase__			       =  attrs or []
     if module is not None:
        for key in module.__dict__:
           if key in attrs or not key.startswith("__" ):
              setattr(self   ,							_lowercase   ,							getattr(_lowercase   ,							_lowercase ) )
     lowercase__			       =  module._original_module if isinstance(_lowercase   ,							_PatchedModuleObj ) else module





class  lowerCAmelCase							:
  __lowerCamelCase		=      []







  def __init__(      self  :str   ,							_lowercase  :Any   ,							_lowercase  :str   ,							_lowercase  :Optional[Any]   ,							_lowercase  :Any=None ):






     '''simple docstring'''





     lowercase__			       =  obj
     lowercase__			       =  target
     lowercase__			       =  new
     lowercase__			       =  target.split("." )[0]
     lowercase__			       =  {}
     lowercase__			       =  attrs or []







  def __enter__(      self  :Dict ):






     '''simple docstring'''





     *lowercase__       ,							lowercase__			       =  self.target.split("." )

     # Patch modules:
     # it's used to patch attributes of submodules like "os.path.join";
     # in this case we need to patch "os" and "os.path"

     for i in range(len(_lowercase ) ):
        try:
           lowercase__			       =  import_module(".".join(submodules[: i + 1] ) )
        except ModuleNotFoundError:
           continue
        # We iterate over all the globals in self.obj in case we find "os" or "os.path"
        for attr in self.obj.__dir__():
           lowercase__			       =  getattr(self.obj   ,							_lowercase )
           # We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
           # This allows to patch renamed modules like "from os import path as ospath".
           if obj_attr is submodule or (
               (isinstance(_lowercase   ,							_PatchedModuleObj ) and obj_attr._original_module is submodule)
           ):
              lowercase__			       =  obj_attr
              # patch at top level
              setattr(self.obj   ,							_lowercase   ,							_PatchedModuleObj(_lowercase   ,							attrs=self.attrs ) )
              lowercase__			       =  getattr(self.obj   ,							_lowercase )
              # construct lower levels patches
              for key in submodules[i + 1 :]:
                 setattr(_lowercase   ,							_lowercase   ,							_PatchedModuleObj(getattr(_lowercase   ,							_lowercase   ,							_lowercase )   ,							attrs=self.attrs ) )
                 lowercase__			       =  getattr(_lowercase   ,							_lowercase )
              # finally set the target attribute
              setattr(_lowercase   ,							_lowercase   ,							self.new )

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

     if submodules:  # if it's an attribute of a submodule like "os.path.join"
        try:
           lowercase__			       =  getattr(import_module(".".join(_lowercase ) )   ,							_lowercase )
        except (AttributeError, ModuleNotFoundError):
           return
        # We iterate over all the globals in self.obj in case we find "os.path.join"
        for attr in self.obj.__dir__():
           # We don't check for the name of the global, but rather if its value *is* "os.path.join".
           # This allows to patch renamed attributes like "from os.path import join as pjoin".
           if getattr(self.obj   ,							_lowercase ) is attr_value:
              lowercase__			       =  getattr(self.obj   ,							_lowercase )
              setattr(self.obj   ,							_lowercase   ,							self.new )
     elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
        lowercase__			       =  globals()["__builtins__"][target_attr]
        setattr(self.obj   ,							_lowercase   ,							self.new )
     else:
        raise RuntimeError(f'''Tried to patch attribute {target_attr} instead of a submodule.''' )







  def __exit__(      self  :int   ,							*_lowercase  :Dict ):






     '''simple docstring'''





     for attr in list(self.original ):
        setattr(self.obj   ,							_lowercase   ,							self.original.pop(_lowercase ) )







  def   UpperCAmelCase					(      self  :int ):






     '''simple docstring'''





     self.__enter__()
     self._active_patches.append(self )







  def   UpperCAmelCase					(      self  :Dict ):






     '''simple docstring'''





     try:
        self._active_patches.remove(self )
     except ValueError:
        # If the patch hasn't been started this will fail
        return None

     return self.__exit__()













from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


_snake_case           =			{
    """configuration_autoformer""": [
        """AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """AutoformerConfig""",
    ],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  _snake_case           =			[
      """AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """AutoformerForPrediction""",
      """AutoformerModel""",
      """AutoformerPreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_autoformer import (
      AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP,
      AutoformerConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_autoformer import (
        AUTOFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
        AutoformerForPrediction,
        AutoformerModel,
        AutoformerPreTrainedModel,
    )

else:
  import sys

  _snake_case           =			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






