当前位置: 首页>>代码示例>>Python>>正文


Python reflect.namedAny方法代码示例

本文整理汇总了Python中twisted.python.reflect.namedAny方法的典型用法代码示例。如果您正苦于以下问题:Python reflect.namedAny方法的具体用法?Python reflect.namedAny怎么用?Python reflect.namedAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.reflect的用法示例。


在下文中一共展示了reflect.namedAny方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeTestCaseClasses

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def makeTestCaseClasses(cls):
        """
        Create a L{SynchronousTestCase} subclass which mixes in C{cls} for each
        known reactor and return a dict mapping their names to them.
        """
        classes = {}
        for reactor in cls._reactors:
            shortReactorName = reactor.split(".")[-1]
            name = (cls.__name__ + "." + shortReactorName + "Tests").replace(".", "_")
            class testcase(cls, SynchronousTestCase):
                __module__ = cls.__module__
                if reactor in cls.skippedReactors:
                    skip = cls.skippedReactors[reactor]
                try:
                    reactorFactory = namedAny(reactor)
                except:
                    skip = Failure().getErrorMessage()
            testcase.__name__ = name
            if hasattr(cls, "__qualname__"):
                testcase.__qualname__ = ".".join(cls.__qualname__.split()[0:-1] + [name])
            classes[testcase.__name__] = testcase
        return classes 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:reactormixins.py

示例2: _unpickleFunction

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def _unpickleFunction(fullyQualifiedName):
    """
    Convert a function name into a function by importing it.

    This is a synonym for L{twisted.python.reflect.namedAny}, but imported
    locally to avoid circular imports, and also to provide a persistent name
    that can be stored (and deprecated) independently of C{namedAny}.

    @param fullyQualifiedName: The fully qualified name of a function.
    @type fullyQualifiedName: native C{str}

    @return: A function object imported from the given location.
    @rtype: L{types.FunctionType}
    """
    from twisted.python.reflect import namedAny
    return namedAny(fullyQualifiedName) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:styles.py

示例3: test_attributeExceptions

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def test_attributeExceptions(self):
        """
        If segments on the end of a fully-qualified Python name represents
        attributes which aren't actually present on the object represented by
        the earlier segments, L{namedAny} should raise an L{AttributeError}.
        """
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.nosuchmoduleintheworld")
        # ImportError behaves somewhat differently between "import
        # extant.nonextant" and "import extant.nonextant.nonextant", so test
        # the latter as well.
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.nosuch.modulein.theworld")
        self.assertRaises(
            AttributeError,
            reflect.namedAny,
            "twisted.test.test_reflect.Summer.nosuchattribute") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_reflect.py

示例4: test_loadPackagesAndModules

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def test_loadPackagesAndModules(self):
        """
        Verify that we can locate and load packages, modules, submodules, and
        subpackages.
        """
        for n in ['os',
                  'twisted',
                  'twisted.python',
                  'twisted.python.reflect']:
            m = namedAny(n)
            self.failUnlessIdentical(
                modules.getModule(n).load(),
                m)
            self.failUnlessIdentical(
                self.findByIteration(n).load(),
                m) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_modules.py

示例5: makeTestCaseClasses

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def makeTestCaseClasses(cls):
        """
        Create a L{TestCase} subclass which mixes in C{cls} for each known
        reactor and return a dict mapping their names to them.
        """
        classes = {}
        for reactor in cls._reactors:
            shortReactorName = reactor.split(".")[-1]
            name = (cls.__name__ + "." + shortReactorName).replace(".", "_")
            class testcase(cls, TestCase):
                __module__ = cls.__module__
                if reactor in cls.skippedReactors:
                    skip = cls.skippedReactors[reactor]
                try:
                    reactorFactory = namedAny(reactor)
                except:
                    skip = Failure().getErrorMessage()
            testcase.__name__ = name
            classes[testcase.__name__] = testcase
        return classes 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:reactormixins.py

示例6: test_importExceptions

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def test_importExceptions(self):
        """
        Exceptions raised by modules which L{namedAny} causes to be imported
        should pass through L{namedAny} to the caller.
        """
        self.assertRaises(
            ZeroDivisionError,
            reflect.namedAny, "twisted.test.reflect_helper_ZDE")
        # Make sure that this behavior is *consistent* for 2.3, where there is
        # no post-failed-import cleanup
        self.assertRaises(
            ZeroDivisionError,
            reflect.namedAny, "twisted.test.reflect_helper_ZDE")
        self.assertRaises(
            ValueError,
            reflect.namedAny, "twisted.test.reflect_helper_VE")
        # Modules which themselves raise ImportError when imported should result in an ImportError
        self.assertRaises(
            ImportError,
            reflect.namedAny, "twisted.test.reflect_helper_IE") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_reflect.py

示例7: test_attributeExceptions

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def test_attributeExceptions(self):
        """
        If segments on the end of a fully-qualified Python name represents
        attributes which aren't actually present on the object represented by
        the earlier segments, L{namedAny} should raise an L{AttributeError}.
        """
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.nosuchmoduleintheworld")
        # ImportError behaves somewhat differently between "import
        # extant.nonextant" and "import extant.nonextant.nonextant", so test
        # the latter as well.
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.nosuch.modulein.theworld")
        self.assertRaises(
            AttributeError,
            reflect.namedAny, "twisted.python.reflect.Summer.nosuchattributeintheworld") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_reflect.py

示例8: filenameToModule

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def filenameToModule(fn):
    if not os.path.exists(fn):
        raise ValueError("%r doesn't exist" % (fn,))
    try:
        ret = reflect.namedAny(reflect.filenameToModuleName(fn))
    except (ValueError, AttributeError):
        # Couldn't find module.  The file 'fn' is not in PYTHONPATH
        return _importFromFile(fn)
    # ensure that the loaded module matches the file
    retFile = os.path.splitext(ret.__file__)[0] + '.py'
    # not all platforms (e.g. win32) have os.path.samefile
    same = getattr(os.path, 'samefile', samefile)
    if os.path.isfile(fn) and not same(fn, retFile):
        del sys.modules[ret.__name__]
        ret = _importFromFile(fn)
    return ret 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:18,代码来源:runner.py

示例9: opt_wsgi

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def opt_wsgi(self, name):
        """
        The FQPN of a WSGI application object to serve as the root resource of
        the webserver.
        """
        try:
            application = reflect.namedAny(name)
        except (AttributeError, ValueError):
            raise usage.UsageError("No such WSGI application: %r" % (name,))
        pool = threadpool.ThreadPool()
        reactor.callWhenRunning(pool.start)
        reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
        self['root'] = wsgi.WSGIResource(reactor, pool, application) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:tap.py

示例10: options

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def options():
        def get(self):
            return namedAny(self.module).Options
        return get, 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:service.py

示例11: makeService

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def makeService():
        def get(self):
            return namedAny(self.module).makeService
        return get, 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:6,代码来源:service.py

示例12: filenameToModule

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def filenameToModule(fn):
    """
    Given a filename, do whatever possible to return a module object matching
    that file.

    If the file in question is a module in Python path, properly import and
    return that module. Otherwise, load the source manually.

    @param fn: A filename.
    @return: A module object.
    @raise ValueError: If C{fn} does not exist.
    """
    if not os.path.exists(fn):
        raise ValueError("%r doesn't exist" % (fn,))
    try:
        ret = reflect.namedAny(reflect.filenameToModuleName(fn))
    except (ValueError, AttributeError):
        # Couldn't find module.  The file 'fn' is not in PYTHONPATH
        return _importFromFile(fn)

    if not hasattr(ret, "__file__"):
        # This isn't a Python module in a package, so import it from a file
        return _importFromFile(fn)

    # ensure that the loaded module matches the file
    retFile = os.path.splitext(ret.__file__)[0] + '.py'
    # not all platforms (e.g. win32) have os.path.samefile
    same = getattr(os.path, 'samefile', samefile)
    if os.path.isfile(fn) and not same(fn, retFile):
        del sys.modules[ret.__name__]
        ret = _importFromFile(fn)
    return ret 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:34,代码来源:runner.py

示例13: loadDoctests

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def loadDoctests(self, module):
        """
        Return a suite of tests for all the doctests defined in C{module}.

        @param module: A module object or a module name.
        """
        if isinstance(module, str):
            try:
                module = reflect.namedAny(module)
            except:
                return ErrorHolder(module, failure.Failure())
        if not inspect.ismodule(module):
            warnings.warn("trial only supports doctesting modules")
            return
        extraArgs = {}
        if sys.version_info > (2, 4):
            # Work around Python issue2604: DocTestCase.tearDown clobbers globs
            def saveGlobals(test):
                """
                Save C{test.globs} and replace it with a copy so that if
                necessary, the original will be available for the next test
                run.
                """
                test._savedGlobals = getattr(test, '_savedGlobals', test.globs)
                test.globs = test._savedGlobals.copy()
            extraArgs['setUp'] = saveGlobals
        return doctest.DocTestSuite(module, **extraArgs) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:29,代码来源:runner.py

示例14: test_MiceDeprecation

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def test_MiceDeprecation(self):
        """
        L{twisted.protocols.mice} is deprecated since Twisted 16.0.
        """
        reflect.namedAny("twisted.protocols.mice")
        warningsShown = self.flushWarnings()
        self.assertEqual(1, len(warningsShown))
        self.assertEqual(
            "twisted.protocols.mice was deprecated in Twisted 16.0.0: "
            "There is no replacement for this module.",
            warningsShown[0]['message']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_basic.py

示例15: load

# 需要导入模块: from twisted.python import reflect [as 别名]
# 或者: from twisted.python.reflect import namedAny [as 别名]
def load(self):
        return namedAny(self.dropin.moduleName + '.' + self.name) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:plugin.py


注:本文中的twisted.python.reflect.namedAny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。