# 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
    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]
        current.switch(([], [original], []))

    def on_error(d, _err=None):
        original = files[get_fileno(d)][ERROR]
        current.switch(([], [], [original]))

    def on_timeout2():
        current.switch(([], [], []))

    def on_timeout():
        timers.append(hub.schedule_call_global(0, on_timeout2))

    if timeout is not None:
        timers.append(hub.schedule_call_global(timeout, on_timeout))
    try:
        for fd, v in files.items():
            if v.get(READ):

# 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

    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]
        current.switch(([], [original], []))

    def on_error(d, _err=None):
        original = files[get_fileno(d)][ERROR]
        current.switch(([], [], [original]))

    def on_timeout2():
        current.switch(([], [], []))

    def on_timeout():
        timers.append(hub.schedule_call_global(0, on_timeout2))

    if timeout is not None:
        timers.append(hub.schedule_call_global(timeout, on_timeout))
    try:
        for fd, v in files.items():
            if v.get(READ):

                listeners.append(hub.add(READ, fd, on_read, on_error, (fd,)))