0000000b
  8   ˆl–Ãa¾””Ò~ê
€fãOÜh*bÑ¿�þYm÷–n@=+o¶ehÏÊ„.ˆÉÁÀÆ 5˜    # pylint: disable=too-many-lines, protected-access, redefined-outer-name, not-callable
# pylint: disable=no-member
from __future__ import absolute_import, print_function
import sys

# pylint: disable=undefined-all-variable
__all__ = [
    'get_version',
    'get_header_version',
    'supported_backends',
    'recommended_backends',
    'embeddable_backends',
    'time',
    'loop',
]

from zope.interface import implementer

from gevent._interfaces import ILoop

from gevent.libev import _corecffi # pylint:disable=no-name-in-module,import-error

ffi = _corecffi.ffi # pylint:disable=no-member
libev = _corecffi.lib # pylint:disable=no-member

if hasattr(libev, 'vfd_open'):
    # Must be on windows
    # pylint:disable=c-extension-no-member
    assert sys.platform.startswith("win"), "vfd functions only needed on windows"
    vfd_open = libev.vfd_open
    vfd_free = libev.vfd_free
    vfd_get = libev.vfd_get
else:
    vfd_open = vfd_free = vfd_get = lambda fd: fd

libev.gevent_set_ev_alloc()

#####
## NOTE on Windows:
# The C implementation does several things specially for Windows;
# a possibly incomplete list is:
#
# - the loop runs a periodic signal checker;
# - the io watcher constructor is different and it has a destructor;
# - the child watcher is not defined
#
# The CFFI implementation does none of these things, and so
# is possibly NOT FUNCTIONALLY CORRECT on Win32
#####


from gevent._ffi.loop import AbstractCallbacks
from gevent._ffi.loop import assign_standard_callbacks

class _Callbacks(AbstractCallbacks):
    # pylint:disable=arguments-differ,arguments-renamed

    def python_check_callback(self, *args):
        # There's a pylint bug (pylint 2.9.3, astroid 2.6.2) that causes pylint to crash
        # with an AttributeError on certain types of arguments-differ errors
        # But code in _ffi/loop depends on being able to find the watcher_ptr
        # argument is the local frame. BUT it gets invoked before the function body runs.
        # Hence the override of _find_watcher_ptr_in_traceback.
        # pylint:disable=unused-variable
        _loop, watcher_ptr, _events = args
        AbstractCallbacks.python_check_callback(self, watcher_ptr)

    def _find_watcher_ptr_in_traceback(self, tb):
        if tb is not None:
            l = tb.tb_frame.f_locals
            if 'watcher_ptr' in l:
                return l['watcher_ptr']
            if 'args' in l and len(l['args']) == 3:
                return l['args'][1]
        return AbstractCallbacks._find_watcher_ptr_in_traceback(self, tb)

    def python_prepare_callback(self, _loop_ptr, watcher_ptr, _events):
        AbstractCallbacks.python_prepare_callback(self, watcher_ptr)

    def _find_loop_from_c_watcher(self, watcher_ptr):
        loop_handle = ffi.cast('struct ev_watcher*', watcher_ptr).data
        return self.from_handle(loop_handle)

_callbacks = assign_standard_callbacks(ffi, libev, _Callbacks)


UNDEF = libev.EV_UNDEF
NONE = libev.EV_NONE
READ = libev.EV_READ
WRITE = libev.EV_WRITE
TIMER = libev.EV_TIMER
PERIODIC = libev.EV_PERIODIC
SIGNAL = libev.EV_SIGNAL
CHILD = libev.EV_CHILD
STAT = libev.EV_STAT
IDLE = libev.EV_IDLE
PREPARE = libev.EV_PREPARE
CHECK = libev.EV_CHECK
EMBED = libev.EV_EMBED
FORK = libev.EV_FORK
CLEANUP = libev.EV_CLEANUP
ASYNC = libev.EV_ASYNC
CUSTOM = libev.EV_CUSTOM
ERROR = libev.EV_ERROR

READWRITE = libev.EV_READ | libev.EV_WRITE

MINPRI = libev.EV_MINPRI
MAXPRI = libev.EV_MAXPRI

BACKEND_PORT = libev.EVBACKEND_PORT
BACKEND_KQUEUE = libev.EVBACKEND_KQUEUE
BACKEND_EPOLL = libev.EVBACKEND_EPOLL
BACKEND_POLL = libev.EVBACKEND_POLL
BACKEND_SELECT = libev.EVBACKEND_SELECT
FORKCHECK = libev.EVFLAG_FORKCHECK
NOINOTIFY = libev.EVFLAG_NOINOTIFY
SIGNALFD = libev.EVFLAG_SIGNALFD
NOSIGMASK = libev.EVFLAG_NOSIGMASK


from gevent._ffi.loop import EVENTS
GEVENT_CORE_EVENTS = EVENTS


def get_version():
    return 'libev-%d.%02d' % (libev.ev_version_major(), libev.ev_version_minor())


def get_header_version():
    return 'libev-%d.%02d' % (libev.EV_VERSION_MAJO