# Path: guv/hubs/hub.py
# def get_hub():
#     """Get the current event hub singleton object
# 
#     .. note :: |internal|
#     """
#     try:
#         hub = _threadlocal.hub
#     except AttributeError:
#         # instantiate a Hub
#         try:
#             _threadlocal.Hub
#         except AttributeError:
#             use_hub()
# 
#         hub = _threadlocal.hub = _threadlocal.Hub()
#     return hub


import greenlet
from .hubs.hub import get_hub
    `seconds` is None, the timer is not scheduled, and is only useful if you're planning to raise it
    directly.

    Timeout objects are context managers, and so can be used in with statements. When used in a with
    statement, if `exception` is ``False``, the timeout is still raised, but the context manager
    suppresses it, so the code outside the with-block won't see it.
    """

    def __init__(self, seconds=None, exception=None):
        """
        :param float seconds: timeout seconds
        :param exception: exception to raise when timeout occurs
        """
        self.seconds = seconds
        self.exception = exception
        self.timer = None
        self.start()

    def start(self):
        """Schedule the timeout.  This is called on construction, so
        it should not be called explicitly, unless the timer has been
        canceled."""
        assert not self.pending, \
            '%r is already started; to restart it, cancel it first' % self
        if self.seconds is None:  # "fake" timeout (never expires)
            self.timer = None
        elif self.exception is None or isinstance(self.exception, bool):  # timeout that raises self
            self.timer = get_hub().schedule_call_global(
                self.seconds, greenlet.getcurrent().throw, self)
        else:  # regular timeout with user-provided exception

# Path: guv/hubs/hub.py
# def get_hub():
#     """Get the current event hub singleton object
# 
#     .. note :: |internal|
#     """
#     try:
#         hub = _threadlocal.hub
#     except AttributeError:
#         # instantiate a Hub
#         try:
#             _threadlocal.Hub
#         except AttributeError:
#             use_hub()
# 
#         hub = _threadlocal.hub = _threadlocal.Hub()
#     return hub


# Path: guv/timeout.py
import greenlet
from .hubs.hub import get_hub

    `seconds` is None, the timer is not scheduled, and is only useful if you're planning to raise it
    directly.

    Timeout objects are context managers, and so can be used in with statements. When used in a with
    statement, if `exception` is ``False``, the timeout is still raised, but the context manager
    suppresses it, so the code outside the with-block won't see it.
    """

    def __init__(self, seconds=None, exception=None):
        """
        :param float seconds: timeout seconds
        :param exception: exception to raise when timeout occurs
        """
        self.seconds = seconds
        self.exception = exception
        self.timer = None
        self.start()

    def start(self):
        """Schedule the timeout.  This is called on construction, so
        it should not be called explicitly, unless the timer has been
        canceled."""
        assert not self.pending, \
            '%r is already started; to restart it, cancel it first' % self
        if self.seconds is None:  # "fake" timeout (never expires)
            self.timer = None
        elif self.exception is None or isinstance(self.exception, bool):  # timeout that raises self
            self.timer = get_hub().schedule_call_global(
                self.seconds, greenlet.getcurrent().throw, self)
        else:  # regular timeout with user-provided exception

            self.timer = get_hub().schedule_call_global(