本文整理汇总了Python中twisted.plugin.IPlugin方法的典型用法代码示例。如果您正苦于以下问题:Python plugin.IPlugin方法的具体用法?Python plugin.IPlugin怎么用?Python plugin.IPlugin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.plugin
的用法示例。
在下文中一共展示了plugin.IPlugin方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _testCache
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def _testCache(self):
cache = plugin.getCache(plugins)
dropin = cache['testplugin']
self.assertEquals(dropin.moduleName, 'twisted.plugins.testplugin')
self.assertNotEquals(dropin.description.find("I'm a test drop-in."), -1)
# Note, not the preferred way to get a plugin by its interface.
p1 = [p for p in dropin.plugins if plugin.ITestPlugin in p.provided][0]
self.assertIdentical(p1.dropin, dropin)
self.assertEquals(p1.name, "TestPlugin")
self.assertEquals(
p1.description.strip(),
"A plugin used solely for testing purposes.")
self.assertEquals(p1.provided, [plugin.ITestPlugin, plugin.IPlugin])
realPlugin = p1.load()
self.assertIdentical(realPlugin,
sys.modules['twisted.plugins.testplugin'].TestPlugin)
import twisted.plugins.testplugin as tp
self.assertIdentical(realPlugin, tp.TestPlugin)
示例2: test_cache
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def test_cache(self):
"""
Check that the cache returned by L{plugin.getCache} hold the plugin
B{testplugin}, and that this plugin has the properties we expect:
provide L{TestPlugin}, has the good name and description, and can be
loaded successfully.
"""
cache = plugin.getCache(self.module)
dropin = cache[self.originalPlugin]
self.assertEqual(dropin.moduleName,
'mypackage.%s' % (self.originalPlugin,))
self.assertIn("I'm a test drop-in.", dropin.description)
# Note, not the preferred way to get a plugin by its interface.
p1 = [p for p in dropin.plugins if ITestPlugin in p.provided][0]
self.assertIs(p1.dropin, dropin)
self.assertEqual(p1.name, "TestPlugin")
# Check the content of the description comes from the plugin module
# docstring
self.assertEqual(
p1.description.strip(),
"A plugin used solely for testing purposes.")
self.assertEqual(p1.provided, [ITestPlugin, plugin.IPlugin])
realPlugin = p1.load()
# The plugin should match the class present in sys.modules
self.assertIs(
realPlugin,
sys.modules['mypackage.%s' % (self.originalPlugin,)].TestPlugin)
# And it should also match if we import it classicly
import mypackage.testplugin as tp
self.assertIs(realPlugin, tp.TestPlugin)
示例3: test_cacheRepr
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def test_cacheRepr(self):
"""
L{CachedPlugin} has a helpful C{repr} which contains relevant
information about it.
"""
cachedDropin = plugin.getCache(self.module)[self.originalPlugin]
cachedPlugin = list(p for p in cachedDropin.plugins
if p.name == 'TestPlugin')[0]
self.assertEqual(
repr(cachedPlugin),
"<CachedPlugin 'TestPlugin'/'mypackage.testplugin' "
"(provides 'ITestPlugin, IPlugin')>"
)
示例4: pluginFileContents
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def pluginFileContents(name):
return (
"from zope.interface import provider\n"
"from twisted.plugin import IPlugin\n"
"from twisted.test.test_plugin import ITestPlugin\n"
"\n"
"@provider(IPlugin, ITestPlugin)\n"
"class {0}(object):\n"
" pass\n"
).format(name).encode('ascii')
示例5: test_cache
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def test_cache(self):
"""
Check that the cache returned by L{plugin.getCache} hold the plugin
B{testplugin}, and that this plugin has the properties we expect:
provide L{TestPlugin}, has the good name and description, and can be
loaded successfully.
"""
cache = plugin.getCache(self.module)
dropin = cache[self.originalPlugin]
self.assertEquals(dropin.moduleName,
'mypackage.%s' % (self.originalPlugin,))
self.assertIn("I'm a test drop-in.", dropin.description)
# Note, not the preferred way to get a plugin by its interface.
p1 = [p for p in dropin.plugins if ITestPlugin in p.provided][0]
self.assertIdentical(p1.dropin, dropin)
self.assertEquals(p1.name, "TestPlugin")
# Check the content of the description comes from the plugin module
# docstring
self.assertEquals(
p1.description.strip(),
"A plugin used solely for testing purposes.")
self.assertEquals(p1.provided, [ITestPlugin, plugin.IPlugin])
realPlugin = p1.load()
# The plugin should match the class present in sys.modules
self.assertIdentical(
realPlugin,
sys.modules['mypackage.%s' % (self.originalPlugin,)].TestPlugin)
# And it should also match if we import it classicly
import mypackage.testplugin as tp
self.assertIdentical(realPlugin, tp.TestPlugin)
示例6: pluginFileContents
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def pluginFileContents(name):
return (
"from zope.interface import classProvides\n"
"from twisted.plugin import IPlugin\n"
"from twisted.test.test_plugin import ITestPlugin\n"
"\n"
"class %s(object):\n"
" classProvides(IPlugin, ITestPlugin)\n") % (name,)
示例7: __new__
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def __new__(cls, name, bases, attrs):
newcls = type.__new__(cls, name, bases, attrs)
alsoProvides(newcls, IPlugin, IAxiomaticCommand)
return newcls
示例8: makeService
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def makeService(self, options):
"""
Construct a TCPServer from a factory defined in myproject.
"""
return HpeFactory(options["cfg"]).start_service()
# Now construct an object which *provides* the relevant interfaces
# The name of this variable is irrelevant, as long as there is *some*
# name bound to a provider of IPlugin and IServiceMakera
示例9: verify_signature
# 需要导入模块: from twisted import plugin [as 别名]
# 或者: from twisted.plugin import IPlugin [as 别名]
def verify_signature(fname, system_gpg=False):
verify_command = ['gpg', '--quiet']
td = None
status = False # pessimism!
try:
if not system_gpg:
# create temporary homedir
td = tempfile.mkdtemp()
verify_command.extend(['--homedir', td])
# add Tor project-people keys to it (the ones who
# sign releases, anyway)
keys = []
keys_path = os.path.join(td, 'keys')
os.mkdir(keys_path)
for k in pkg_resources.resource_listdir('carml', 'keys'):
if k.endswith('.asc'):
keys.append(pkg_resources.resource_filename('carml', os.path.join('keys', k)))
if len(keys) == 0:
raise RuntimeError('Internal error: failed to find shipped keys.')
try:
if subprocess.check_call(['gpg', '--quiet', '--homedir', td, '--import'] + keys):
raise RuntimeError("Key import failed.")
except IOError:
raise RuntimeError("GPG verification failed; is GnuPG installed?")
verify_command.extend(['--verify', fname])
try:
subprocess.check_call(verify_command)
status = True
except subprocess.CalledProcessError:
print(util.colors.bold(util.colors.red("Signature verification failed.")))
status = False
finally:
if td:
shutil.rmtree(td)
return status
# the IPlugin/getPlugin stuff from Twisted picks up any object from
# here than implements ICarmlCommand -- so we need to instantiate one