PRODUCT=11/2/13/6
NAME="VirtualPS/2 VMware VMMouse"
PHYS="isa0060/serio1/input1"
PROP=0
EV=b
KEY=70000 0 0 0 0
ABS=3
MODALIAS=input:b0011v0002p0013e0006-e0,1,3,k110,111,112,ra0,1,mlsfw
  7   ˆl–Ü4ý( ©¤ýÔâ�Æ^¸ÈÅ£‘äÇò 8àé	‘Š2ÿ?Âƒh¹ÁÀ¿      00000047
  5   ˆl–ß=¿Jõ4Ÿº‚ œP.\· 1hß�þB g Ùl-J9çÃƒh¹ÂÁÀ      PRODUCT=19/0/1/0
NAME="Power Button"
PHYS="LNXPWRBN/button/input0"
PROP=0
EV=3
KEY=10000000000000 0
MODALIAS=input:b0019v0000p0001e0000-e0,1,k74,ramlsfw
  A   ˆl–Ým_J
j"TýÆß¸ÛJbÑ¿�þDÉZY²€­‰á<çÄƒ|/=Ã_ŠI|¥�+Wé3ž¯ÃÂ #ä    # Copyright 2018 gevent. See LICENSE for details.

# Portions of the following are inspired by code from eventlet. I
# believe they are distinct enough that no eventlet copyright would
# apply (they are not a copy or substantial portion of the eventlot
# code).

# Added in gevent 1.3a2. Not public in that release.

from __future__ import absolute_import, print_function

import importlib
import sys

from gevent._compat import PY3
from gevent._compat import iteritems
from gevent._compat import imp_acquire_lock
from gevent._compat import imp_release_lock


from gevent.builtins import __import__ as g_import


MAPPING = {
    'gevent.local': '_threading_local',
    'gevent.socket': 'socket',
    'gevent.select': 'select',
    'gevent.selectors': 'selectors' if PY3 else 'selectors2',
    'gevent.ssl': 'ssl',
    'gevent.thread': '_thread' if PY3 else 'thread',
    'gevent.subprocess': 'subprocess',
    'gevent.os': 'os',
    'gevent.threading': 'threading',
    'gevent.builtins': 'builtins' if PY3 else '__builtin__',
    'gevent.signal': 'signal',
    'gevent.time': 'time',
    'gevent.queue': 'queue' if PY3 else 'Queue',
    'gevent.contextvars': 'contextvars',
}

OPTIONAL_STDLIB_MODULES = frozenset() if PY3 else frozenset([
    'selectors2',
])

_PATCH_PREFIX = '__g_patched_module_'

def _collect_stdlib_gevent_modules():
    """
    Return a map from standard library name to
    imported gevent module that provides the same API.

    Optional modules are skipped if they cannot be imported.
    """
    result = {}

    for gevent_name, stdlib_name in iteritems(MAPPING):
        try:
            result[stdlib_name] = importlib.import_module(gevent_name)
        except ImportError:
            if stdlib_name in OPTIONAL_STDLIB_MODULES:
                continue
            raise
    return result


class _SysModulesPatcher(object):

    def __init__(self, importing, extra_all=lambda mod_name: ()):
        # Permanent state.
        self.extra_all = extra_all
        self.importing = importing
        # green modules, replacing regularly imported modules.
        # This begins as the gevent list of modules, and
        # then gets extended with green things from the tree we import.
        self._green_modules = _collect_stdlib_gevent_modules()

        ## Transient, reset each time we're called.
        # The set of things imported before we began.
        self._t_modules_to_restore = {}

    def _save(self):
        self._t_modules_to_restore = {}

        # Copy all the things we know we are going to overwrite.
        for modname in self._green_modules:
            self._t_modules_to_restore[modname] = sys.modules.get(modname, None)

        # Copy anything else in the import tree.
        for modname, mod in list(iteritems(sys.modules)):
            if modname.startswith(self.importing):
                self._t_modules_to_restore[modname] = mod
                # And remove it. If it had been imported green, it will
                # be put right back. Otherwise, it was imported "manually"
                # outside this process and isn't green.
                del sys.modules[modname]

        # Cover the target modules so that when you import the module it
        # sees only the patched versions
        for name, mod in iteritems(self._green_modules):
            sys.modules[name] = mod

    def _restore(self):
        # Anything from the same package tree we imported this time
        # needs to be saved so we can restore it later, and so it doesn't
        # l