"""
This type stub file was generated by pyright.
"""

import types
import temporalio.workflow
from dataclasses import dataclass
from typing import Any, Callable, ClassVar, Mapping, Optional, Sequence, Set, Type, TypeVar

"""Restrictions for workflow sandbox.

.. warning::
    This API for this module is considered unstable and may change in future.
"""
logger = ...
LOG_TRACE = ...
class RestrictedWorkflowAccessError(temporalio.workflow.NondeterminismError):
    """Error that occurs when a workflow accesses something non-deterministic.

    Attributes:
        qualified_name: Fully qualified name of what was accessed.
    """
    def __init__(self, qualified_name: str) -> None:
        """Create restricted workflow access error."""
        ...
    


@dataclass(frozen=True)
class SandboxRestrictions:
    """Set of restrictions that can be applied to a sandbox."""
    passthrough_modules: Set[str]
    invalid_modules: SandboxMatcher
    invalid_module_members: SandboxMatcher
    passthrough_modules_minimum: ClassVar[Set[str]]
    passthrough_modules_with_temporal: ClassVar[Set[str]]
    passthrough_modules_maximum: ClassVar[Set[str]]
    passthrough_modules_default: ClassVar[Set[str]]
    invalid_module_members_default: ClassVar[SandboxMatcher]
    default: ClassVar[SandboxRestrictions]
    def with_passthrough_modules(self, *modules: str) -> SandboxRestrictions:
        """Create a new restriction set with the given modules added to the
        :py:attr:`passthrough_modules` set.
        """
        ...
    


@dataclass(frozen=True)
class SandboxMatcher:
    """Matcher that is used to match modules and members during restriction and
    pass through checks.

    This class is intentionally immutable. Changes need to be made as new
    instances.
    """
    @staticmethod
    def nested_child(path: Sequence[str], child: SandboxMatcher) -> SandboxMatcher:
        """Create a matcher where the given child is put at the given path.

        Args:
            path: Path to the child.
            child: Child matcher to set

        Returns:
            Created matcher.
        """
        ...
    
    access: Set[str] = ...
    use: Set[str] = ...
    children: Mapping[str, SandboxMatcher] = ...
    match_self: bool = ...
    only_runtime: bool = ...
    all: ClassVar[SandboxMatcher]
    all_runtime: ClassVar[SandboxMatcher]
    none: ClassVar[SandboxMatcher]
    all_uses: ClassVar[SandboxMatcher]
    all_uses_runtime: ClassVar[SandboxMatcher]
    def match_access(self, context: RestrictionContext, *child_path: str, include_use: bool = ...) -> bool:
        """Perform a match check.

        Args:
            context: Current restriction context.
            child_path: Full path to the child being accessed.
            include_use: Whether to include the :py:attr:`use` set in the check.

        Returns:
            ``True`` if matched.
        """
        ...
    
    def child_matcher(self, *child_path: str) -> Optional[SandboxMatcher]:
        """Return a child matcher for the given path.

        Unlike :py:meth:`match_access`, this will match if in py:attr:`use` in
        addition to :py:attr:`access`. If in neither, it uses the child mapping.

        Args:
            child_path: Full path to the child to get matcher for.

        Returns:
            Matcher that can be used to check children.
        """
        ...
    
    def __or__(self, other: SandboxMatcher) -> SandboxMatcher:
        """Combine this matcher with another."""
        ...
    
    def with_child_unrestricted(self, *child_path: str) -> SandboxMatcher:
        """Create new matcher with the given child path removed.

        Traverses the child mapping, if present, until on leaf of path where it
        is removed from :py:attr:`access`, :py:attr:`use`, and
        :py:attr:`children`.

        Args:
            child_path: Full path to the child to remove restrictions for.

        Returns:
            Copied matcher from this matcher without this child restricted.
        """
        ...
    


_stdlib_module_names = ...
class RestrictionContext:
    """Context passed around restrictions.

    Attributes:
        is_runtime: ``True`` if we're currently running the workflow, ``False``
            if we're just importing it.
    """
    @staticmethod
    def unwrap_if_proxied(v: Any) -> Any:
        """Unwrap a proxy object if proxied."""
        ...
    
    def __init__(self) -> None:
        """Create a restriction context."""
        ...
    


@dataclass
class _RestrictionState:
    @staticmethod
    def from_proxy(v: _RestrictedProxy) -> _RestrictionState:
        ...
    
    name: str
    obj: object
    context: RestrictionContext
    matcher: SandboxMatcher
    def assert_child_not_restricted(self, name: str) -> None:
        ...
    
    def set_on_proxy(self, v: _RestrictedProxy) -> None:
        ...
    


class _RestrictedProxyLookup:
    def __init__(self, access_func: Optional[Callable] = ..., *, fallback_func: Optional[Callable] = ..., class_value: Optional[Any] = ..., is_attr: bool = ...) -> None:
        ...
    
    def __set_name__(self, owner: _RestrictedProxy, name: str) -> None:
        ...
    
    def __get__(self, instance: _RestrictedProxy, owner: Optional[Type] = ...) -> Any:
        ...
    
    def __repr__(self) -> str:
        ...
    
    def __call__(self, instance: _RestrictedProxy, *args: Any, **kwargs: Any) -> Any:
        """Support calling unbound methods from the class. For example,
        this happens with ``copy.copy``, which does
        ``type(x).__copy__(x)``. ``type(x)`` can't be proxied, so it
        returns the proxy type and descriptor.
        """
        ...
    


class _RestrictedProxyIOp(_RestrictedProxyLookup):
    __slots__ = ...
    def __init__(self, access_func: Optional[Callable] = ..., *, fallback_func: Optional[Callable] = ...) -> None:
        ...
    


_OpF = TypeVar("_OpF", bound=Callable[..., Any])
class _RestrictedProxy:
    def __init__(self, *args, **kwargs) -> None:
        ...
    
    def __getattribute__(self, __name: str) -> Any:
        ...
    
    def __setattr__(self, __name: str, __value: Any) -> None:
        ...
    
    def __call__(self, *args, **kwargs) -> _RestrictedProxy:
        ...
    
    def __getitem__(self, key: Any) -> Any:
        ...
    
    __doc__ = ...
    __wrapped__ = ...
    __repr__ = ...
    __str__ = ...
    __bytes__ = ...
    __format__ = ...
    __lt__ = ...
    __le__ = ...
    __eq__ = ...
    __ne__ = ...
    __gt__ = ...
    __ge__ = ...
    __hash__ = ...
    __bool__ = ...
    __getattr__ = ...
    __delattr__ = ...
    __dir__ = ...
    __class__ = ...
    __instancecheck__ = ...
    __subclasscheck__ = ...
    __len__ = ...
    __length_hint__ = ...
    __setitem__ = ...
    __delitem__ = ...
    __iter__ = ...
    __next__ = ...
    __reversed__ = ...
    __contains__ = ...
    __add__ = ...
    __sub__ = ...
    __mul__ = ...
    __matmul__ = ...
    __truediv__ = ...
    __floordiv__ = ...
    __mod__ = ...
    __divmod__ = ...
    __pow__ = ...
    __lshift__ = ...
    __rshift__ = ...
    __and__ = ...
    __xor__ = ...
    __or__ = ...
    __radd__ = ...
    __rsub__ = ...
    __rmul__ = ...
    __rmatmul__ = ...
    __rtruediv__ = ...
    __rfloordiv__ = ...
    __rmod__ = ...
    __rdivmod__ = ...
    __rpow__ = ...
    __rlshift__ = ...
    __rrshift__ = ...
    __rand__ = ...
    __rxor__ = ...
    __ror__ = ...
    __iadd__ = ...
    __isub__ = ...
    __imul__ = ...
    __imatmul__ = ...
    __itruediv__ = ...
    __ifloordiv__ = ...
    __imod__ = ...
    __ipow__ = ...
    __ilshift__ = ...
    __irshift__ = ...
    __iand__ = ...
    __ixor__ = ...
    __ior__ = ...
    __neg__ = ...
    __pos__ = ...
    __abs__ = ...
    __invert__ = ...
    __complex__ = ...
    __int__ = ...
    __float__ = ...
    __index__ = ...
    __round__ = ...
    __trunc__ = ...
    __floor__ = ...
    __ceil__ = ...
    __enter__ = ...
    __exit__ = ...
    __await__ = ...
    __aiter__ = ...
    __anext__ = ...
    __aenter__ = ...
    __aexit__ = ...
    __copy__ = ...
    __deepcopy__ = ...


class RestrictedModule(_RestrictedProxy, types.ModuleType):
    """Module that is restricted."""
    def __init__(self, mod: types.ModuleType, context: RestrictionContext, matcher: SandboxMatcher) -> None:
        """Create a restricted module."""
        ...
    


