Did I find the right examples for you? yes no

All Samples(7)  |  Call(6)  |  Derive(0)  |  Import(1)

        def _checkRequirements():
    # Don't allow the user to run a version of Python we don't support.
    import sys

    version = getattr(sys, "version_info", (0,))
    if version < (2, 6):
        raise ImportError("Twisted requires Python 2.6 or later.")
    if version < (3, 0):
        required = "3.6.0"
    else:
        required = "4.0.0"

    if ("setuptools" in sys.modules and
        getattr(sys.modules["setuptools"],
                "_TWISTED_NO_CHECK_REQUIREMENTS", None) is not None):
        # Skip requirement checks, setuptools ought to take care of installing
        # the dependencies.
        return

    # Don't allow the user to run with a version of zope.interface we don't
    # support.
    required = "Twisted requires zope.interface %s or later" % (required,)
    try:
        from zope import interface
    except ImportError:
        # It isn't installed.
        raise ImportError(required + ": no module named zope.interface.")
    except:
        # It is installed but not compatible with this version of Python.
        raise ImportError(required + ".")
    try:
        # Try using the API that we need, which only works right with
        # zope.interface 3.6 (or 4.0 on Python 3)
        class IDummy(interface.Interface):
            pass
        @interface.implementer(IDummy)
        class Dummy(object):
            pass
    except TypeError:
        # It is installed but not compatible with this version of Python.
        raise ImportError(required + ".")
        


src/t/w/Twisted-13.2.0/twisted/test/test_twisted.py   Twisted(Download)
from unittest import TestCase
 
from twisted import _checkRequirements
from twisted.python.compat import _PY3
 
        sys.version_info = self.unsupportedPythonVersion
        with self.assertRaises(ImportError) as raised:
            _checkRequirements()
        self.assertEqual(
            "Twisted requires Python %d.%d or later." % self.supportedPythonVersion,
            sys.modules["zope"] = None
            with self.assertRaises(ImportError) as raised:
                _checkRequirements()
            self.assertEqual(
                "Twisted requires zope.interface %d.%d.%d or later: no module "
            sys.modules["zope"] = ModuleType("zope")
            with self.assertRaises(ImportError) as raised:
                _checkRequirements()
            self.assertEqual(
                "Twisted requires zope.interface %d.%d.%d or later: no module "
            with SetAsideModule("zope"):
                sys.modules["zope"] = None
                _checkRequirements()