






from importlib import import_module

from .logging import get_logger


_SCREAMING_SNAKE_CASE      :			List[Any]      				=   get_logger(__name__)

class   A__ :







    """simple docstring"""

    def __init__(	self      , __snake_case      , __snake_case=None   ):
         snake_case					=    attrs or []
         if module is not None:
              for key in module.__dict__:
                   if key in attrs or not key.startswith('''__'''   ):
                        setattr(self      , lowerCAmelCase__      , getattr(lowerCAmelCase__      , lowerCAmelCase__   )   )
         snake_case					=    module._original_module if isinstance(lowerCAmelCase__      , _PatchedModuleObj   ) else module






class   A__ :







    """simple docstring"""

    __magic_name__        =		[]
    def __init__(	self      , __snake_case      , __snake_case      , __snake_case      , __snake_case=None   ):
         snake_case					=    obj
         snake_case					=    target
         snake_case					=    new
         snake_case					=    target.split('''.'''   )[0]
         snake_case					=    {}
         snake_case					=    attrs or []
    def __enter__(	self   ):
         snake_case					=    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(lowerCAmelCase__   )   ):
              try:
                   snake_case					=    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__():
                   snake_case					=    getattr(self.obj      , lowerCAmelCase__   )
                   # 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(lowerCAmelCase__      , _PatchedModuleObj   ) and obj_attr._original_module is submodule)
                   ):
                        snake_case					=    obj_attr
                        # patch at top level
                        setattr(self.obj      , lowerCAmelCase__      , _PatchedModuleObj(lowerCAmelCase__      , attrs=self.attrs   )   )
                        snake_case					=    getattr(self.obj      , lowerCAmelCase__   )
                        # construct lower levels patches
                        for key in submodules[i + 1 :]:
                             setattr(lowerCAmelCase__      , lowerCAmelCase__      , _PatchedModuleObj(getattr(lowerCAmelCase__      , lowerCAmelCase__      , lowerCAmelCase__   )      , attrs=self.attrs   )   )
                             snake_case					=    getattr(lowerCAmelCase__      , lowerCAmelCase__   )
                        # finally set the target attribute
                        setattr(lowerCAmelCase__      , lowerCAmelCase__      , 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:
                   snake_case					=    getattr(import_module('''.'''.join(lowerCAmelCase__   )   )      , lowerCAmelCase__   )
              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      , lowerCAmelCase__   ) is attr_value:
                        snake_case					=    getattr(self.obj      , lowerCAmelCase__   )
                        setattr(self.obj      , lowerCAmelCase__      , self.new   )
         elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
              snake_case					=    globals()["__builtins__"][target_attr]
              setattr(self.obj      , lowerCAmelCase__      , self.new   )
         else:
              raise RuntimeError(F'''Tried to patch attribute {target_attr} instead of a submodule.'''   )
    def __exit__(	self      , *__snake_case   ):




         for attr in list(self.original   ):
              setattr(self.obj      , lowerCAmelCase__      , self.original.pop(lowerCAmelCase__   )   )
    def 		a_      (	self   ):
         self.__enter__()
         self._active_patches.append(self   )




    def 		a_      (	self   ):




         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

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_SCREAMING_SNAKE_CASE      :			Dict      				=   {"configuration_van": ["VAN_PRETRAINED_CONFIG_ARCHIVE_MAP", "VanConfig"]}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _SCREAMING_SNAKE_CASE      :			Dict      				=   [
     "VAN_PRETRAINED_MODEL_ARCHIVE_LIST",
     "VanForImageClassification",
     "VanModel",
     "VanPreTrainedModel",
 ]

if TYPE_CHECKING:
 from .configuration_van import VAN_PRETRAINED_CONFIG_ARCHIVE_MAP, VanConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_van import (
      VAN_PRETRAINED_MODEL_ARCHIVE_LIST,
      VanForImageClassification,
      VanModel,
      VanPreTrainedModel,
  )

else:
 import sys

 _SCREAMING_SNAKE_CASE      :			str      				=   _LazyModule(__name__, globals()["__file__"], _import_structure)




