# 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

ERROR = 'error'

__patched__ = ['select']


def get_fileno(obj):
    # The purpose of this function is to exactly replicate
    # the behavior of the select module when confronted with
    # abnormal filenos; the details are extensively tested in
    # the stdlib test/test_select.py.
    try:
        f = obj.fileno
    except AttributeError:
        if not isinstance(obj, int):
            raise TypeError("Expected int or long, got " + type(obj))
        return obj
    else:
        rv = f()
        if not isinstance(rv, int):
            raise TypeError("Expected int or long, got " + type(rv))
        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:

# 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


ERROR = 'error'

__patched__ = ['select']


def get_fileno(obj):
    # The purpose of this function is to exactly replicate
    # the behavior of the select module when confronted with
    # abnormal filenos; the details are extensively tested in
    # the stdlib test/test_select.py.
    try:
        f = obj.fileno
    except AttributeError:
        if not isinstance(obj, int):
            raise TypeError("Expected int or long, got " + type(obj))
        return obj
    else:
        rv = f()
        if not isinstance(rv, int):
            raise TypeError("Expected int or long, got " + type(rv))
        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')