本文整理汇总了Python中twisted.application.service.IService方法的典型用法代码示例。如果您正苦于以下问题:Python service.IService方法的具体用法?Python service.IService怎么用?Python service.IService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.application.service
的用法示例。
在下文中一共展示了service.IService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testLoadApplication
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def testLoadApplication(self):
"""
Test loading an application file in different dump format.
"""
a = service.Application("hello")
baseconfig = {'file': None, 'source': None, 'python':None}
for style in 'source pickle'.split():
config = baseconfig.copy()
config[{'pickle': 'file'}.get(style, style)] = 'helloapplication'
sob.IPersistable(a).setStyle(style)
sob.IPersistable(a).save(filename='helloapplication')
a1 = app.getApplication(config, None)
self.assertEqual(service.IService(a1).name, "hello")
config = baseconfig.copy()
config['python'] = 'helloapplication'
with open("helloapplication", 'w') as f:
f.writelines([
"from twisted.application import service\n",
"application = service.Application('hello')\n",
])
a1 = app.getApplication(config, None)
self.assertEqual(service.IService(a1).name, "hello")
示例2: test_everythingThere
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def test_everythingThere(self):
"""
L{twisted.application.internet} dynamically defines a set of
L{service.Service} subclasses that in general have corresponding
reactor.listenXXX or reactor.connectXXX calls.
"""
trans = 'TCP UNIX SSL UDP UNIXDatagram Multicast'.split()
for tran in trans[:]:
if not getattr(interfaces, "IReactor" + tran)(reactor, None):
trans.remove(tran)
for tran in trans:
for side in 'Server Client'.split():
if tran == "Multicast" and side == "Client":
continue
if tran == "UDP" and side == "Client":
continue
self.assertTrue(hasattr(internet, tran + side))
method = getattr(internet, tran + side).method
prefix = {'Server': 'listen', 'Client': 'connect'}[side]
self.assertTrue(hasattr(reactor, prefix + method) or
(prefix == "connect" and method == "UDP"))
o = getattr(internet, tran + side)()
self.assertEqual(service.IService(o), o)
示例3: test_applicationRunnerGetsCorrectApplication
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def test_applicationRunnerGetsCorrectApplication(self):
"""
Ensure that a twistd plugin gets used in appropriate ways: it
is passed its Options instance, and the service it returns is
added to the application.
"""
arunner = CrippledApplicationRunner(self.config)
arunner.run()
self.assertIs(
self.serviceMaker.options, self.config.subOptions,
"ServiceMaker.makeService needs to be passed the correct "
"sub Command object.")
self.assertIs(
self.serviceMaker.service,
service.IService(arunner.application).services[0],
"ServiceMaker.makeService's result needs to be set as a child "
"of the Application.")
示例4: test_defaultService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def test_defaultService(self):
"""
Test the value of a Slave service in it's simplest
configuration.
"""
service = CalDAVServiceMaker().makeService(self.options)
self.failUnless(
IService(service),
"%s does not provide IService" % (service,)
)
self.failUnless(
service.services,
"No services configured"
)
self.failUnless(
isinstance(service, CalDAVService),
"%s is not a CalDAVService" % (service,)
)
示例5: test_simpleStoreAndLoad
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def test_simpleStoreAndLoad(self):
a = service.Application("hello")
p = sob.IPersistable(a)
for style in 'source pickle'.split():
p.setStyle(style)
p.save()
a1 = service.loadApplication("hello.ta"+style[0], style)
self.assertEqual(service.IService(a1).name, "hello")
f = open("hello.tac", 'w')
f.writelines([
"from twisted.application import service\n",
"application = service.Application('hello')\n",
])
f.close()
a1 = service.loadApplication("hello.tac", 'python')
self.assertEqual(service.IService(a1).name, "hello")
示例6: test_everythingThere
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def test_everythingThere(self):
"""
L{twisted.application.internet} dynamically defines a set of
L{service.Service} subclasses that in general have corresponding
reactor.listenXXX or reactor.connectXXX calls.
"""
trans = 'TCP UNIX SSL UDP UNIXDatagram Multicast'.split()
for tran in trans[:]:
if not getattr(interfaces, "IReactor" + tran)(reactor, None):
trans.remove(tran)
if interfaces.IReactorArbitrary(reactor, None) is not None:
trans.insert(0, "Generic")
for tran in trans:
for side in 'Server Client'.split():
if tran == "Multicast" and side == "Client":
continue
self.assertTrue(hasattr(internet, tran + side))
method = getattr(internet, tran + side).method
prefix = {'Server': 'listen', 'Client': 'connect'}[side]
self.assertTrue(hasattr(reactor, prefix + method) or
(prefix == "connect" and method == "UDP"))
o = getattr(internet, tran + side)()
self.assertEquals(service.IService(o), o)
示例7: testLoadApplication
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def testLoadApplication(self):
a = service.Application("hello")
baseconfig = {'file': None, 'xml': None, 'source': None, 'python':None}
for style in 'source xml pickle'.split():
if style == 'xml' and not gotMicrodom:
continue
config = baseconfig.copy()
config[{'pickle': 'file'}.get(style, style)] = 'helloapplication'
sob.IPersistable(a).setStyle(style)
sob.IPersistable(a).save(filename='helloapplication')
a1 = app.getApplication(config, None)
self.assertEqual(service.IService(a1).name, "hello")
config = baseconfig.copy()
config['python'] = 'helloapplication'
open("helloapplication", 'w').writelines([
"from twisted.application import service\n",
"application = service.Application('hello')\n",
])
a1 = app.getApplication(config, None)
self.assertEqual(service.IService(a1).name, "hello")
示例8: testSimpleInternet
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def testSimpleInternet(self):
# XXX - replace this test with one that does the same thing, but
# with no web dependencies.
if not gotMicrodom:
raise unittest.SkipTest("Need twisted.web to run this test.")
s = "(dp0\nS'udpConnectors'\np1\n(lp2\nsS'unixConnectors'\np3\n(lp4\nsS'twisted.internet.app.Application.persistenceVersion'\np5\nI12\nsS'name'\np6\nS'web'\np7\nsS'sslConnectors'\np8\n(lp9\nsS'sslPorts'\np10\n(lp11\nsS'tcpPorts'\np12\n(lp13\n(I8080\n(itwisted.web.server\nSite\np14\n(dp16\nS'resource'\np17\n(itwisted.web.demo\nTest\np18\n(dp19\nS'files'\np20\n(lp21\nsS'paths'\np22\n(dp23\nsS'tmpl'\np24\n(lp25\nS'\\n Congratulations, twisted.web appears to work!\\n <ul>\\n <li>Funky Form:\\n '\np26\naS'self.funkyForm()'\np27\naS'\\n <li>Exception Handling:\\n '\np28\naS'self.raiseHell()'\np29\naS'\\n </ul>\\n '\np30\nasS'widgets'\np31\n(dp32\nsS'variables'\np33\n(dp34\nsS'modules'\np35\n(lp36\nsS'children'\np37\n(dp38\nsbsS'logPath'\np39\nNsS'timeOut'\np40\nI43200\nsS'sessions'\np41\n(dp42\nsbI5\nS''\np43\ntp44\nasS'unixPorts'\np45\n(lp46\nsS'services'\np47\n(dp48\nsS'gid'\np49\nI1000\nsS'tcpConnectors'\np50\n(lp51\nsS'extraConnectors'\np52\n(lp53\nsS'udpPorts'\np54\n(lp55\nsS'extraPorts'\np56\n(lp57\nsS'persistStyle'\np58\nS'pickle'\np59\nsS'uid'\np60\nI1000\ns."
d = pickle.loads(s)
a = Dummy()
a.__dict__ = d
appl = compat.convert(a)
self.assertEqual(service.IProcess(appl).uid, 1000)
self.assertEqual(service.IProcess(appl).gid, 1000)
self.assertEqual(service.IService(appl).name, "web")
services = list(service.IServiceCollection(appl))
self.assertEqual(len(services), 1)
s = services[0]
self.assertEqual(s.parent, service.IServiceCollection(appl))
self.assert_(s.privileged)
self.assert_(isinstance(s, internet.TCPServer))
args = s.args
self.assertEqual(args[0], 8080)
self.assertEqual(args[3], '')
示例9: testEverythingThere
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def testEverythingThere(self):
trans = 'TCP UNIX SSL UDP UNIXDatagram Multicast'.split()
for tran in trans[:]:
if not getattr(interfaces, "IReactor"+tran)(reactor, None):
trans.remove(tran)
if interfaces.IReactorArbitrary(reactor, None) is not None:
trans.insert(0, "Generic")
for tran in trans:
for side in 'Server Client'.split():
if tran == "Multicast" and side == "Client":
continue
self.assert_(hasattr(internet, tran+side))
method = getattr(internet, tran+side).method
prefix = {'Server': 'listen', 'Client': 'connect'}[side]
self.assert_(hasattr(reactor, prefix+method) or
(prefix == "connect" and method == "UDP"))
o = getattr(internet, tran+side)()
self.assertEqual(service.IService(o), o)
示例10: runApp
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def runApp(config):
passphrase = app.getPassphrase(config['encrypted'])
app.installReactor(config['reactor'])
application = app.getApplication(config, passphrase)
oldstdout = sys.stdout
oldstderr = sys.stderr
startLogging(config['logfile'])
app.initialLog()
os.chdir(config['rundir'])
service.IService(application).privilegedStartService()
app.startApplication(application, not config['no_save'])
app.startApplication(internet.TimerService(0.1, lambda:None), 0)
app.runReactorWithLogging(config, oldstdout, oldstderr)
app.reportProfile(config['report-profile'],
service.IProcess(application).processName)
log.msg("Server Shut Down.")
示例11: storeBatchServiceSpecialCase
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def storeBatchServiceSpecialCase(st, pups):
"""
Adapt a L{Store} to L{IBatchService}.
If C{st} is a substore, return a simple wrapper that delegates to the site
store's L{IBatchService} powerup. Return C{None} if C{st} has no
L{BatchProcessingControllerService}.
"""
if st.parent is not None:
try:
return _SubStoreBatchChannel(st)
except TypeError:
return None
storeService = service.IService(st)
try:
return storeService.getServiceNamed("Batch Processing Controller")
except KeyError:
return None
示例12: startApplication
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def startApplication(application, save):
from twisted.internet import reactor
service.IService(application).startService()
if save:
p = sob.IPersistable(application)
reactor.addSystemEventTrigger('after', 'shutdown', p.save, 'shutdown')
reactor.addSystemEventTrigger('before', 'shutdown',
service.IService(application).stopService)
示例13: test_applicationComponents
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def test_applicationComponents(self):
"""
Check L{twisted.application.service.Application} instantiation.
"""
app = Application('app-name')
self.assertTrue(verifyObject(IService, IService(app)))
self.assertTrue(
verifyObject(IServiceCollection, IServiceCollection(app)))
self.assertTrue(verifyObject(IProcess, IProcess(app)))
self.assertTrue(verifyObject(IPersistable, IPersistable(app)))
示例14: testService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def testService(self):
self.assertTrue(service.IService.providedBy(service.Service()))
示例15: testMultiService
# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import IService [as 别名]
def testMultiService(self):
self.assertTrue(service.IService.providedBy(service.MultiService()))
self.assertTrue(service.IServiceCollection.providedBy(
service.MultiService()))