# 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/const.py
# READ = 1
# 
# WRITE = 2


import select as select_orig
from greenlet import getcurrent
from ..hubs import get_hub
from ..const import READ, WRITE
        return rv


def select(read_list, write_list, error_list, timeout=None):
    # error checking like this is required by the stdlib unit tests
    if timeout is not None:
        try:
            timeout = float(timeout)
        except ValueError:
            raise TypeError('Expected number for timeout')

    hub = get_hub()
    timers = []
    current = getcurrent()
    assert hub is not current, 'do not call blocking functions from the mainloop'
    files = {}  # dict of socket objects or file descriptor integers
    for r in read_list:
        files[get_fileno(r)] = {READ: r}
    for w in write_list:
        files.setdefault(get_fileno(w), {})[WRITE] = w
    for e in error_list:
        files.setdefault(get_fileno(e), {})[ERROR] = e

    listeners = []

    def on_read(d):
        original = files[get_fileno(d)][READ]
        current.switch(([original], [], []))

    def on_write(d):

# 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/const.py
# READ = 1
# 
# WRITE = 2


# Path: guv/green/select.py
import select as select_orig
from greenlet import getcurrent
from ..hubs import get_hub
from ..const import READ, WRITE

        return rv


def select(read_list, write_list, error_list, timeout=None):
    # error checking like this is required by the stdlib unit tests
    if timeout is not None:
        try:
            timeout = float(timeout)
        except ValueError:
            raise TypeError('Expected number for timeout')

    hub = get_hub()
    timers = []
    current = getcurrent()
    assert hub is not current, 'do not call blocking functions from the mainloop'
    files = {}  # dict of socket objects or file descriptor integers
    for r in read_list:
        files[get_fileno(r)] = {READ: r}
    for w in write_list:
        files.setdefault(get_fileno(w), {})[WRITE] = w
    for e in error_list:
        files.setdefault(get_fileno(e), {})[ERROR] = e

    listeners = []

    def on_read(d):
        original = files[get_fileno(d)][READ]
        current.switch(([original], [], []))

    def on_write(d):

        original = files[get_fileno(d)][WRITE]