northisup committed f642d38

Added monkey.is_module_patched and monkey.are_modules_patched functions.

Comments (0)

Files changed (1)

 # Copyright (c) 2009-2012 Denis Bilenko. See LICENSE for details.
 """Make the standard library cooperative.
-The functions in this module patch parts of the standard library with compatible cooperative counterparts
+The functions in this modul ## only works on monkey_patches that involve 'monkey_original'
 from :mod:`gevent` package.
 To patch an individual module call the corresponding ``patch_*`` function. For example, to patch
 socket module only, call :func:`patch_socket`. To patch all default modules, call ``gevent.monkey.patch_all()``.
+def is_module_patched(name):
+    # only works on monkey_patches that involve 'monkey_original'
+    # i.e. does not work for 'time', 'sleep'
+    source = getattr(__import__('gevent.' + name), name)
+    target = getattr(source, '__target__', name)
+    dest = __import__(target)
+    original = getattr(dest, 'monkey_original', None)
+    return True if original else False
+def are_modules_patched(names=None):
+    if not names:
+        names = ["socket", "ssl", "thread", ]
+    ret = {}
+    for name in names:
+        ret[name] = is_module_patched(name)
+    return ret
 def get_unpatched(name, items):
     # QQQ would prefer to avoid importing module just to get __target__
     # XXX does not work for 'time', 'sleep'