本文整理汇总了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
示例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)
示例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")
示例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)
示例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
示例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")
示例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")
示例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
示例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)
示例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,
示例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,
示例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
示例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)
示例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'])
示例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)