GRAYBYTE WORDPRESS FILE MANAGER2323

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /opt/alt/python312/lib64/python3.12/asyncio/
Upload Files :
Current_dir [ Not Writeable ] Document_root [ Writeable ]

Command :


Current File : /opt/alt/python312/lib64/python3.12/asyncio//timeouts.py
import enum

from types import TracebackType
from typing import final, Optional, Type

from . import events
from . import exceptions
from . import tasks


__all__ = (
    "Timeout",
    "timeout",
    "timeout_at",
)


class _State(enum.Enum):
    CREATED = "created"
    ENTERED = "active"
    EXPIRING = "expiring"
    EXPIRED = "expired"
    EXITED = "finished"


@final
class Timeout:
    """Asynchronous context manager for cancelling overdue coroutines.

    Use `timeout()` or `timeout_at()` rather than instantiating this class directly.
    """

    def __init__(self, when: Optional[float]) -> None:
        """Schedule a timeout that will trigger at a given loop time.

        - If `when` is `None`, the timeout will never trigger.
        - If `when < loop.time()`, the timeout will trigger on the next
          iteration of the event loop.
        """
        self._state = _State.CREATED

        self._timeout_handler: Optional[events.TimerHandle] = None
        self._task: Optional[tasks.Task] = None
        self._when = when

    def when(self) -> Optional[float]:
        """Return the current deadline."""
        return self._when

    def reschedule(self, when: Optional[float]) -> None:
        """Reschedule the timeout."""
        if self._state is not _State.ENTERED:
            if self._state is _State.CREATED:
                raise RuntimeError("Timeout has not been entered")
            raise RuntimeError(
                f"Cannot change state of {self._state.value} Timeout",
            )

        self._when = when

        if self._timeout_handler is not None:
            self._timeout_handler.cancel()

        if when is None:
            self._timeout_handler = None
        else:
            loop = events.get_running_loop()
            if when <= loop.time():
                self._timeout_handler = loop.call_soon(self._on_timeout)
            else:
                self._timeout_handler = loop.call_at(when, self._on_timeout)

    def expired(self) -> bool:
        """Is timeout expired during execution?"""
        return self._state in (_State.EXPIRING, _State.EXPIRED)

    def __repr__(self) -> str:
        info = ['']
        if self._state is _State.ENTERED:
            when = round(self._when, 3) if self._when is not None else None
            info.append(f"when={when}")
        info_str = ' '.join(info)
        return f"<Timeout [{self._state.value}]{info_str}>"

    async def __aenter__(self) -> "Timeout":
        if self._state is not _State.CREATED:
            raise RuntimeError("Timeout has already been entered")
        task = tasks.current_task()
        if task is None:
            raise RuntimeError("Timeout should be used inside a task")
        self._state = _State.ENTERED
        self._task = task
        self._cancelling = self._task.cancelling()
        self.reschedule(self._when)
        return self

    async def __aexit__(
        self,
        exc_type: Optional[Type[BaseException]],
        exc_val: Optional[BaseException],
        exc_tb: Optional[TracebackType],
    ) -> Optional[bool]:
        assert self._state in (_State.ENTERED, _State.EXPIRING)

        if self._timeout_handler is not None:
            self._timeout_handler.cancel()
            self._timeout_handler = None

        if self._state is _State.EXPIRING:
            self._state = _State.EXPIRED

            if self._task.uncancel() <= self._cancelling and exc_type is exceptions.CancelledError:
                # Since there are no new cancel requests, we're
                # handling this.
                raise TimeoutError from exc_val
        elif self._state is _State.ENTERED:
            self._state = _State.EXITED

        return None

    def _on_timeout(self) -> None:
        assert self._state is _State.ENTERED
        self._task.cancel()
        self._state = _State.EXPIRING
        # drop the reference early
        self._timeout_handler = None


def timeout(delay: Optional[float]) -> Timeout:
    """Timeout async context manager.

    Useful in cases when you want to apply timeout logic around block
    of code or in cases when asyncio.wait_for is not suitable. For example:

    >>> async with asyncio.timeout(10):  # 10 seconds timeout
    ...     await long_running_task()


    delay - value in seconds or None to disable timeout logic

    long_running_task() is interrupted by raising asyncio.CancelledError,
    the top-most affected timeout() context manager converts CancelledError
    into TimeoutError.
    """
    loop = events.get_running_loop()
    return Timeout(loop.time() + delay if delay is not None else None)


def timeout_at(when: Optional[float]) -> Timeout:
    """Schedule the timeout at absolute time.

    Like timeout() but argument gives absolute time in the same clock system
    as loop.time().

    Please note: it is not POSIX time but a time with
    undefined starting base, e.g. the time of the system power on.

    >>> async with asyncio.timeout_at(loop.time() + 10):
    ...     await long_running_task()


    when - a deadline when timeout occurs or None to disable timeout logic

    long_running_task() is interrupted by raising asyncio.CancelledError,
    the top-most affected timeout() context manager converts CancelledError
    into TimeoutError.
    """
    return Timeout(when)

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
May 13 2025 08:36:47
root / linksafe
0755
__pycache__
--
May 13 2025 08:36:47
root / linksafe
0755
__init__.py
1.191 KB
April 25 2025 20:47:43
root / linksafe
0644
__main__.py
3.409 KB
April 25 2025 20:47:43
root / linksafe
0644
base_events.py
76.726 KB
April 25 2025 20:47:43
root / linksafe
0644
base_futures.py
1.928 KB
April 25 2025 20:47:43
root / linksafe
0644
base_subprocess.py
8.661 KB
April 25 2025 20:47:43
root / linksafe
0644
base_tasks.py
2.609 KB
April 25 2025 20:47:43
root / linksafe
0644
constants.py
1.38 KB
April 25 2025 20:47:43
root / linksafe
0644
coroutines.py
3.264 KB
April 25 2025 20:47:43
root / linksafe
0644
events.py
28.651 KB
April 25 2025 20:47:43
root / linksafe
0644
exceptions.py
1.711 KB
April 25 2025 20:47:43
root / linksafe
0644
format_helpers.py
2.348 KB
April 25 2025 20:47:43
root / linksafe
0644
futures.py
14.004 KB
April 25 2025 20:47:43
root / linksafe
0644
locks.py
18.55 KB
April 25 2025 20:47:43
root / linksafe
0644
log.py
0.121 KB
April 25 2025 20:47:43
root / linksafe
0644
mixins.py
0.47 KB
April 25 2025 20:47:43
root / linksafe
0644
proactor_events.py
32.715 KB
April 25 2025 20:47:43
root / linksafe
0644
protocols.py
6.794 KB
April 25 2025 20:47:43
root / linksafe
0644
queues.py
7.787 KB
April 25 2025 20:47:43
root / linksafe
0644
runners.py
7.061 KB
April 25 2025 20:47:43
root / linksafe
0644
selector_events.py
47.199 KB
April 25 2025 20:47:43
root / linksafe
0644
sslproto.py
31.151 KB
April 25 2025 20:47:43
root / linksafe
0644
staggered.py
6.911 KB
April 25 2025 20:47:43
root / linksafe
0644
streams.py
26.972 KB
April 25 2025 20:47:43
root / linksafe
0644
subprocess.py
7.556 KB
April 25 2025 20:47:43
root / linksafe
0644
taskgroups.py
9.335 KB
April 25 2025 20:47:43
root / linksafe
0644
tasks.py
36.486 KB
April 25 2025 20:47:43
root / linksafe
0644
threads.py
0.771 KB
April 25 2025 20:47:43
root / linksafe
0644
timeouts.py
5.196 KB
April 25 2025 20:47:43
root / linksafe
0644
transports.py
10.471 KB
April 25 2025 20:47:43
root / linksafe
0644
trsock.py
2.417 KB
April 25 2025 20:47:43
root / linksafe
0644
unix_events.py
51.879 KB
April 25 2025 20:47:43
root / linksafe
0644
windows_events.py
31.823 KB
April 25 2025 20:47:43
root / linksafe
0644
windows_utils.py
4.941 KB
April 25 2025 20:47:43
root / linksafe
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF