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


Python service.MultiService方法代码示例

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


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

示例1: run

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def run():

    config.read()
    logs.api()

    top_service = service.MultiService()

    db = Db()
    datalib.db = db
    db.setServiceParent(top_service)

    http_service = internet.TCPServer(config.HTTP_PORT, Site(db), interface=config.HTTP_ADDR)
    http_service.setServiceParent(top_service)

    top_service.startService()

    reactor.addSystemEventTrigger('before', 'shutdown', top_service.stopService)

    reactor.run() 
开发者ID:moira-alert,项目名称:worker,代码行数:21,代码来源:server.py

示例2: __init__

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def __init__(self):
        service.MultiService.__init__(self)

        bf = BonafideService
        self.init('bonafide', bf, '/tmp/')

        km = mail_services.KeymanagerService
        self.init('keymanager', km)

        sol = mail_services.SoledadService
        self.init('soledad', sol)

        mail = mail_services.StandardMailService
        self.init('mail', mail)

        self.core_cmds = BackendCommands(self)
        self.tokens = {} 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:19,代码来源:test_web_api.py

示例3: makeService

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def makeService(config):
    credCheckers = config.get('credCheckers', [])
    wordsRealm = service.InMemoryWordsRealm(config['hostname'])
    wordsPortal = portal.Portal(wordsRealm, credCheckers)

    msvc = MultiService()

    # XXX Attribute lookup on config is kind of bad - hrm.
    for plgName in config.interfacePlugins:
        port = config.get(plgName + '-port')
        if port is not None:
            factory = config.interfacePlugins[plgName].getFactory(wordsRealm, wordsPortal)
            svc = strports.service(port, factory)
            svc.setServiceParent(msvc)

    # This is bogus.  createGroup is async.  makeService must be
    # allowed to return a Deferred or some crap.
    for g in config['groups']:
        wordsRealm.createGroup(g)

    return msvc 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:tap.py

示例4: test_sshPort

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def test_sshPort(self):
        """
        L{manhole_tap.makeService} will make a SSH service on the port
        defined by C{--sshPort}. It will not make a telnet service.
        """
        # Why the sshKeyDir and sshKeySize params? To prevent it stomping over
        # (or using!) the user's private key, we just make a super small one
        # which will never be used in a temp directory.
        self.options.parseOptions(["--sshKeyDir", self.mktemp(),
                                   "--sshKeySize", "512",
                                   "--sshPort", "tcp:223"])
        service = manhole_tap.makeService(self.options)
        self.assertIsInstance(service, MultiService)
        self.assertEqual(len(service.services), 1)
        self.assertIsInstance(service.services[0], StreamServerEndpointService)
        self.assertIsInstance(service.services[0].factory,
                              manhole_ssh.ConchFactory)
        self.assertEqual(service.services[0].endpoint._port, 223) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_manhole_tap.py

示例5: testUNIX

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def testUNIX(self):
        # FIXME: This test is far too dense.  It needs comments.
        #  -- spiv, 2004-11-07
        s = service.MultiService()
        s.startService()
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        t = internet.UNIXServer('echo.skt', factory)
        t.setServiceParent(s)
        factory = protocol.ClientFactory()
        factory.protocol = Foo
        factory.d = defer.Deferred()
        factory.line = None
        internet.UNIXClient('echo.skt', factory).setServiceParent(s)
        factory.d.addCallback(self.assertEqual, b'lalala')
        factory.d.addCallback(lambda x : s.stopService())
        factory.d.addCallback(lambda x : TestEcho.d)
        factory.d.addCallback(self._cbTestUnix, factory, s)
        return factory.d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_application.py

示例6: testTCP

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def testTCP(self):
        s = service.MultiService()
        s.startService()
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        t = internet.TCPServer(0, factory)
        t.setServiceParent(s)
        num = t._port.getHost().port
        factory = protocol.ClientFactory()
        factory.d = defer.Deferred()
        factory.protocol = Foo
        factory.line = None
        internet.TCPClient('127.0.0.1', num, factory).setServiceParent(s)
        factory.d.addCallback(self.assertEqual, b'lalala')
        factory.d.addCallback(lambda x : s.stopService())
        factory.d.addCallback(lambda x : TestEcho.d)
        return factory.d 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:test_application.py

示例7: main

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def main():
    with open('/tmp/server.pem', 'rb') as fp:
        certData = fp.read()
    sslcert = ssl.PrivateCertificate.loadPEM(certData)

    logging.basicConfig(level=logging.INFO)

    socks = MySOCKSv4Factory("http://127.0.0.1:2357", "http://127.0.0.1:8080", sslcert)
    socks.protocol = MySOCKSv4

    srv = service.MultiService()
    srv.addService(internet.TCPServer(9050, socks))
    srv.addService(internet.TCPServer(2357, server.Site(WebEchoService())))

    application = service.Application("Receive Request")
    srv.setServiceParent(application)
    srv.startService()
    reactor.run() 
开发者ID:mrschyte,项目名称:socksmon,代码行数:20,代码来源:socksmon.py

示例8: test_service_maker

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def test_service_maker(self):
        #-----------------------------------------------------------------------
        # Incorrect HTTP config
        #-----------------------------------------------------------------------
        config_class = Mock()
        config = build_mock_config(self.config)
        config_class.return_value = config
        options = self.service_maker.options()
        with patch('scrapy_do.app.Config', config_class):
            self.config['web']['interfaces'] = ''
            service = self.service_maker.makeService(options)
            self.assertIsInstance(service, MultiService)
            self.config['web']['interfaces'] = 'localhost:7654'

        #-----------------------------------------------------------------------
        # Broken controller
        #-----------------------------------------------------------------------
        with patch('scrapy_do.app.Config', config_class):
            self.config['scrapy-do']['project-store'] = '/dev/null/foo'
            service = self.service_maker.makeService(options)
            self.assertIsInstance(service, MultiService)
            self.config['scrapy-do']['project-store'] = self.pstore_path

    #--------------------------------------------------------------------------- 
开发者ID:ljanyst,项目名称:scrapy-do,代码行数:26,代码来源:test_app.py

示例9: makeService

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def makeService(config):
    import client, cache, hosts

    ca, cl = [], []
    if config['cache']:
        ca.append(cache.CacheResolver(verbose=config['verbose']))
    if config['recursive']:
        cl.append(client.createResolver(resolvconf=config['resolv-conf']))
    if config['hosts-file']:
        cl.append(hosts.Resolver(file=config['hosts-file']))

    f = server.DNSServerFactory(config.zones, ca, cl, config['verbose'])
    p = dns.DNSDatagramProtocol(f)
    f.noisy = 0
    ret = service.MultiService()
    for (klass, arg) in [(internet.TCPServer, f), (internet.UDPServer, p)]:
        s = klass(config['port'], arg, interface=config['interface'])
        s.setServiceParent(ret)
    for svc in config.svcs:
        svc.setServiceParent(ret)
    return ret 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:tap.py

示例10: testTCP

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def testTCP(self):
        s = service.MultiService()
        s.startService()
        factory = protocol.ServerFactory()
        factory.protocol = TestEcho
        TestEcho.d = defer.Deferred()
        t = internet.TCPServer(0, factory)
        t.setServiceParent(s)
        num = t._port.getHost().port
        factory = protocol.ClientFactory()
        factory.d = defer.Deferred()
        factory.protocol = Foo
        factory.line = None
        internet.TCPClient('127.0.0.1', num, factory).setServiceParent(s)
        factory.d.addCallback(self.assertEqual, 'lalala')
        factory.d.addCallback(lambda x : s.stopService())
        factory.d.addCallback(lambda x : TestEcho.d)
        return factory.d 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:20,代码来源:test_application.py

示例11: test_defaults

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def test_defaults(self):
        o = server_tap.Options()
        o.parseOptions([])
        cdb = object()
        udb = object()
        r = mock.Mock()
        ws = object()
        with mock.patch("wormhole_mailbox_server.server_tap.create_or_upgrade_channel_db", return_value=cdb) as ccdb:
            with mock.patch("wormhole_mailbox_server.server_tap.create_or_upgrade_usage_db", return_value=udb) as ccub:
                with mock.patch("wormhole_mailbox_server.server_tap.make_server", return_value=r) as ms:
                    with mock.patch("wormhole_mailbox_server.server_tap.make_web_server", return_value=ws) as mws:
                        s = server_tap.makeService(o)
        self.assertEqual(ccdb.mock_calls, [mock.call("relay.sqlite")])
        self.assertEqual(ccub.mock_calls, [mock.call(None)])
        self.assertEqual(ms.mock_calls, [mock.call(cdb, allow_list=True,
                                                   advertise_version=None,
                                                   signal_error=None,
                                                   blur_usage=None,
                                                   usage_db=udb,
                                                   log_file=None)])
        self.assertEqual(mws.mock_calls, [mock.call(r, True, [])])
        self.assertIsInstance(s, MultiService)
        self.assertEqual(len(r.mock_calls), 1) # setServiceParent 
开发者ID:warner,项目名称:magic-wormhole-mailbox-server,代码行数:25,代码来源:test_service.py

示例12: __init__

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def __init__(self, jid, password):
        service.MultiService.__init__(self)

        # Setup defaults
        self.jabberId = jid
        self.xmlstream = None

        # Internal buffer of packets
        self._packetQueue = []

        # Setup the xmlstream factory
        self._xsFactory = componentFactory(self.jabberId, password)

        # Register some lambda functions to keep the self.xmlstream var up to date
        self._xsFactory.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, self._connected)
        self._xsFactory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self._authd)
        self._xsFactory.addBootstrap(xmlstream.STREAM_END_EVENT, self._disconnected)

        # Map addBootstrap and removeBootstrap to the underlying factory -- is this
        # right? I have no clue...but it'll work for now, until i can think about it
        # more.
        self.addBootstrap = self._xsFactory.addBootstrap
        self.removeBootstrap = self._xsFactory.removeBootstrap 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:25,代码来源:component.py

示例13: startService

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def startService(self):
        service.MultiService.startService(self)
        for i in range(max(1, multiprocessing.cpu_count() - 1)):
            checker = reactor.spawnProcess(
                CheckerProcessProtocol(), sys.executable,
                ['moira-checker', WORKER_PATH, "-n", str(i), "-c", config.CONFIG_PATH, "-l", config.LOG_DIRECTORY],
                childFDs={0: 'w', 1: 1, 2: 2}, env=os.environ)
            self.checkers.append(checker) 
开发者ID:moira-alert,项目名称:worker,代码行数:10,代码来源:server.py

示例14: __init__

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def __init__(self, basedir=DEFAULT_BASEDIR):
        service.MultiService.__init__(self)
        self.cfg = Configuration(self.config_file, basedir, DEFAULT_CONFIG)
        self.basedir = basedir 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:6,代码来源:configurable.py

示例15: makeService

# 需要导入模块: from twisted.application import service [as 别名]
# 或者: from twisted.application.service import MultiService [as 别名]
def makeService(self, options):
        """Override IServiceMaker.makeService."""
        factory = bashplex.DelimitedBashReceiverFactory()
        factory.ping_interval = int(options['ping-interval'])
        factory.ping_timeout = int(options['ping-timeout'])
        factory.startup_commands = filter_bash(
            '/usr/share/epoptes/client-functions')

        if config.system['ENCRYPTION']:
            client_service = internet.SSLServer(
                int(config.system['PORT']), factory, ServerContextFactory())
        else:
            client_service = internet.TCPServer(
                int(config.system['PORT']), factory)

        gid = grp.getgrnam(config.system['SOCKET_GROUP'])[2]

        if not os.path.isdir(config.system['DIR']):
            # TODO: for some reason this does 0750 instead
            os.makedirs(config.system['DIR'], 0o2770)
        os.chmod(config.system['DIR'], 0o2770)
        os.chown(config.system['DIR'], -1, gid)

        gui_service = internet.UNIXServer(
            "%s/epoptes.socket" % config.system['DIR'],
            guiplex.GUIFactory())

        top_service = service.MultiService()
        top_service.addService(client_service)
        top_service.addService(gui_service)

        return top_service 
开发者ID:epoptes,项目名称:epoptes,代码行数:34,代码来源:epoptesd.py


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