# Path: selene/core/exceptions.py
# class TimeoutException(AssertionError):
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         exception_msg = "Message: %s\n" % self.msg
#         return exception_msg
# 
# Path: selene/common/fp.py
# def identity(it: T) -> T:
#     return it


import time
from abc import abstractmethod, ABC
from typing import Generic, Callable, TypeVar, Optional
from selene.core.exceptions import TimeoutException
from selene.common.fp import identity

    def __call__(self, entity: T) -> R:
        return self._fn(entity)

    def __str__(self):
        return self._description


class Command(Query[T, None]):
    pass


# todo: provide sexy fluent implementation via builder, i.e. Wait.the(element).atMost(3).orFailWith(hook)
class Wait(Generic[E]):

    # todo: provide the smallest possible timeout default, something like 1ms
    def __init__(
        self,
        entity: E,
        at_most: int,
        or_fail_with: Optional[Callable[[TimeoutException], Exception]] = None,
    ):
        self._entity = entity
        self._timeout = at_most
        self._hook_failure = or_fail_with or identity

    def at_most(self, timeout: int) -> Wait[E]:
        return Wait(self._entity, timeout, self._hook_failure)

    def or_fail_with(

# Path: selene/core/exceptions.py
# class TimeoutException(AssertionError):
#     def __init__(self, msg=None):
#         self.msg = msg
# 
#     def __str__(self):
#         exception_msg = "Message: %s\n" % self.msg
#         return exception_msg
# 
# Path: selene/common/fp.py
# def identity(it: T) -> T:
#     return it


# Path: selene/core/wait.py
import time
from abc import abstractmethod, ABC
from typing import Generic, Callable, TypeVar, Optional
from selene.core.exceptions import TimeoutException
from selene.common.fp import identity


    def __call__(self, entity: T) -> R:
        return self._fn(entity)

    def __str__(self):
        return self._description


class Command(Query[T, None]):
    pass


# todo: provide sexy fluent implementation via builder, i.e. Wait.the(element).atMost(3).orFailWith(hook)
class Wait(Generic[E]):

    # todo: provide the smallest possible timeout default, something like 1ms
    def __init__(
        self,
        entity: E,
        at_most: int,
        or_fail_with: Optional[Callable[[TimeoutException], Exception]] = None,
    ):
        self._entity = entity
        self._timeout = at_most
        self._hook_failure = or_fail_with or identity

    def at_most(self, timeout: int) -> Wait[E]:
        return Wait(self._entity, timeout, self._hook_failure)

    def or_fail_with(

        self, hook_failure: Optional[Callable[[TimeoutException], Exception]]