






from importlib import import_module

from .logging import get_logger


_SCREAMING_SNAKE_CASE   =  get_logger(__name__)






class 					SCREAMING_SNAKE_CASE_  :
       """simple docstring"""


       def __init__(				self	:Any,      snake_case	:str,      snake_case	:Tuple=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,      snake_case,      getattr(snake_case,      snake_case))
          _lowercase              =module._original_module if isinstance(snake_case,      _PatchedModuleObj) else module






class 					SCREAMING_SNAKE_CASE_  :
       """simple docstring"""


       __lowerCAmelCase    :		Union[str, Any]					=[]





       def __init__(				self	:Tuple,      snake_case	:int,      snake_case	:str,      snake_case	:Optional[int],      snake_case	:Optional[int]=None):



          """simple docstring"""

          _lowercase              =obj
          _lowercase              =target
          _lowercase              =new
          _lowercase              =target.split('.')[0]
          _lowercase              ={}
          _lowercase              =attrs or []





       def __enter__(				self	:List[Any]):



          """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(snake_case)):
             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,      snake_case)
                # 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(snake_case,      _PatchedModuleObj) and obj_attr._original_module is submodule)
                ):
                   _lowercase              =obj_attr
                   # patch at top level
                   setattr(self.obj,      snake_case,      _PatchedModuleObj(snake_case,      attrs=self.attrs))
                   _lowercase              =getattr(self.obj,      snake_case)
                   # construct lower levels patches
                   for key in submodules[i + 1 :]:
                      setattr(snake_case,      snake_case,      _PatchedModuleObj(getattr(snake_case,      snake_case,      snake_case),      attrs=self.attrs))
                      _lowercase              =getattr(snake_case,      snake_case)
                   # finally set the target attribute
                   setattr(snake_case,      snake_case,      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(snake_case)),      snake_case)
             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,      snake_case) is attr_value:
                   _lowercase              =getattr(self.obj,      snake_case)
                   setattr(self.obj,      snake_case,      self.new)
          elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
             _lowercase              =globals()['__builtins__'][target_attr]
             setattr(self.obj,      snake_case,      self.new)
          else:
             raise RuntimeError(f'''Tried to patch attribute {target_attr} instead of a submodule.''')





       def __exit__(				self	:List[Any],      *snake_case	:Optional[int]):



          """simple docstring"""

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





       def 				UpperCamelCase__						(				self	:Optional[int]):



          """simple docstring"""

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





       def 				UpperCamelCase__						(				self	:str):



          """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 dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available






@dataclass
class 					SCREAMING_SNAKE_CASE_  (       _a ):
       """simple docstring"""


       __lowerCAmelCase    :		Union[List[PIL.Image.Image], np.ndarray]
       __lowerCAmelCase    :		Optional[List[bool]]


if is_transformers_available() and is_torch_available():
    from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline


