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


Python TCPServer.setServiceParent方法代码示例

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


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

示例1: get_application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def get_application(config):
    app = Application('Scrapyd')
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')
    poll_interval = config.getfloat('poll_interval', 5)

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd_mongodb.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(poll_interval, poller.poll)
    webservice = TCPServer(
        http_port, server.Site(Root(config, app)),
        interface=bind_address)

    log.msg('http://%(bind_address)s:%(http_port)s/' % {'bind_address':bind_address, 'http_port':http_port})

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:Tiago-Lira,项目名称:scrapyd-mongodb,代码行数:34,代码来源:application.py

示例2: application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def application(config):
    app = Application("Scrapyd")
    http_port = int(environ.get('PORT', config.getint('http_port', 6800)))
    config.cp.set('scrapyd', 'database_url', environ.get('DATABASE_URL'))

    poller = Psycopg2QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = Psycopg2SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    launcher = Launcher(config, app)
    timer = TimerService(5, poller.poll)
    webservice = TCPServer(http_port, server.Site(Root(config, app)))
    log.msg("Scrapyd web console available at http://localhost:%s/ (HEROKU)"
        % http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:kayawaffles,项目名称:scrapy-heroku,代码行数:28,代码来源:app.py

示例3: get_application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def get_application(arguments):
    ServiceRoot = load_object(settings.SERVICE_ROOT)
    site = Site(ServiceRoot())
    application = Application('scrapyrt')
    server = TCPServer(arguments.port, site, interface=arguments.ip)
    server.setServiceParent(application)
    return application
开发者ID:SmileyJames,项目名称:scrapyrt,代码行数:9,代码来源:cmdline.py

示例4: application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def application(config):
	app = Application("Scrapyd")
	http_port = config.getint('http_port', 6800)
	
	portal = Portal(PublicHTMLRealm(config, app), [FilePasswordDB(str(config.get('passwd', '')))])
	credentialFactory = DigestCredentialFactory("md5", "Go away")
	
	poller = QueuePoller(config)
	eggstorage = FilesystemEggStorage(config)
	scheduler = SpiderScheduler(config)
	environment = Environment(config)
	
	app.setComponent(IPoller, poller)
	app.setComponent(IEggStorage, eggstorage)
	app.setComponent(ISpiderScheduler, scheduler)
	app.setComponent(IEnvironment, environment)
	
	launcher = Launcher(config, app)
	timer = TimerService(5, poller.poll)
	webservice = TCPServer(http_port, server.Site(HTTPAuthSessionWrapper(portal, [credentialFactory])))
	log.msg("Scrapyd web console available at http://localhost:%s/" % http_port)
	
	launcher.setServiceParent(app)
	timer.setServiceParent(app)
	webservice.setServiceParent(app)
	
	return app
开发者ID:trunk,项目名称:littlespider,代码行数:29,代码来源:app.py

示例5: application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def application(config):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(5, poller.poll)
    webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
    log.msg("Scrapyd web console available at http://%s:%s/" % (bind_address, http_port))

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:Root-nix,项目名称:scrapy,代码行数:30,代码来源:app.py

示例6: application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def application(config, components=interfaces):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '0.0.0.0')

    for interface, key in interfaces:
        path = config.get(key)
        cls = load_object(path)
        component = cls(config)
        app.setComponent(interface, component)
    poller = component
        
    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath) 
    launcher = laucls(config, app)

    poll_every = config.getint("poll_every", 5)
    timer = TimerService(poll_every, poller.poll)
    
    webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address)
    log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
            bind_address=bind_address, http_port=http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:llonchj,项目名称:scrapyd,代码行数:30,代码来源:app.py

示例7: createCacheService

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def createCacheService(config):
    from carbon.cache import MetricCache
    from carbon.conf import settings
    from carbon.protocols import CacheManagementHandler

    # Configure application components
    events.metricReceived.addHandler(MetricCache.store)

    root_service = createBaseService(config)
    factory = ServerFactory()
    factory.protocol = CacheManagementHandler
    service = TCPServer(int(settings.CACHE_QUERY_PORT), factory,
                        interface=settings.CACHE_QUERY_INTERFACE)
    service.setServiceParent(root_service)

    # have to import this *after* settings are defined
    from carbon.writer import WriterService

    service = WriterService()
    service.setServiceParent(root_service)

    if settings.USE_FLOW_CONTROL:
      events.cacheFull.addHandler(events.pauseReceivingMetrics)
      events.cacheSpaceAvailable.addHandler(events.resumeReceivingMetrics)

    return root_service
开发者ID:laiwei,项目名称:carbon,代码行数:28,代码来源:service.py

示例8: application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def application(config):
	app = Application("Scrapyd")
	http_port = config.getint('http_port', 6800)
	
	poller = QueuePoller(config)
	eggstorage = FilesystemEggStorage(config)
	scheduler = SpiderScheduler(config)
	environment = Environment(config)
	app.setComponent(IPoller, poller)
	app.setComponent(IEggStorage, eggstorage)
	app.setComponent(ISpiderScheduler, scheduler)
	app.setComponent(IEnvironment, environment)
	
	launcher = Launcher(config, app)
	timer = TimerService(5, poller.poll)
	root = Root(config, app)
	root = configRoot(root, config)
	
	webservice = TCPServer(http_port, server.Site(root))
	log.msg("Scrapyd web console available at http://localhost:%s/" % http_port)

	launcher.setServiceParent(app)
	timer.setServiceParent(app)
	webservice.setServiceParent(app)

	return app
开发者ID:huangpanxx,项目名称:POAS,代码行数:28,代码来源:app.py

示例9: build

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
    def build(cls, root_service):
        if not settings.ENABLE_MANHOLE:
            return

        factory = createManholeListener()
        service = TCPServer(settings.MANHOLE_PORT, factory, interface=settings.MANHOLE_INTERFACE)
        service.setServiceParent(root_service)
开发者ID:bmhatfield,项目名称:carbon,代码行数:9,代码来源:manhole.py

示例10: makeService

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def makeService(config):
    event_db = Event_DB(config['eventdb'])
    LoopingCall(event_db.prune, MAX_AGE).start(PRUNE_INTERVAL)

    broker_service = MultiService()
    if config['broadcast']:
        broadcaster_factory = VOEventBroadcasterFactory(
            config["local-ivo"], config['broadcast-test-interval']
        )
        if log.LEVEL >= log.Levels.INFO: broadcaster_factory.noisy = False
        broadcaster_service = TCPServer(
            config['broadcast-port'],
            broadcaster_factory
        )
        broadcaster_service.setName("Broadcaster")
        broadcaster_service.setServiceParent(broker_service)

        # If we're running a broadcast, we will rebroadcast any events we
        # receive to it.
        config['handlers'].append(EventRelay(broadcaster_factory))

    if config['receive']:
        receiver_factory = VOEventReceiverFactory(
            local_ivo=config['local-ivo'],
            validators=[
                CheckPreviouslySeen(event_db),
                CheckSchema(
                    os.path.join(comet.__path__[0], "schema/VOEvent-v2.0.xsd")
                ),
                CheckIVORN()
            ],
            handlers=config['handlers']
        )
        if log.LEVEL >= log.Levels.INFO: receiver_factory.noisy = False
        whitelisting_factory = WhitelistingFactory(receiver_factory, config['whitelist'])
        if log.LEVEL >= log.Levels.INFO: whitelisting_factory.noisy = False
        receiver_service = TCPServer(config['receive-port'], whitelisting_factory)
        receiver_service.setName("Receiver")
        receiver_service.setServiceParent(broker_service)

    for host, port in config["remotes"]:
        subscriber_factory = VOEventSubscriberFactory(
            local_ivo=config["local-ivo"],
            validators=[CheckPreviouslySeen(event_db)],
            handlers=config['handlers'],
            filters=config['filters']
        )
        if log.LEVEL >= log.Levels.INFO: subscriber_factory.noisy = False
        remote_service = TCPClient(host, port, subscriber_factory)
        remote_service.setName("Remote %s:%d" % (host, port))
        remote_service.setServiceParent(broker_service)

    if not broker_service.services:
        reactor.callWhenRunning(log.warning, "No services requested; stopping.")
        reactor.callWhenRunning(reactor.stop)
    return broker_service
开发者ID:timstaley,项目名称:Comet,代码行数:58,代码来源:broker.py

示例11: makeService

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
    def makeService(self, options):
        top_service = service.MultiService()

        server_service = ServerService(options["map"], int(options["numplayers"]))
        server_service.setServiceParent(top_service)

        server_factory = MyServerFactory(server_service)

        server = TCPServer(int(options["port"]), server_factory)
        server.setServiceParent(top_service)

        return top_service
开发者ID:shurtado,项目名称:SnakesOnABoat,代码行数:14,代码来源:server_plugin.py

示例12: create_status_service

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def create_status_service(storage, parent_service, port, user_id=0, ssl_context_factory=None):
    """Create the status service."""
    root = resource.Resource()
    root.putChild("status", _Status(storage, user_id))
    root.putChild("+meliae", MeliaeResource())
    root.putChild("+gc-stats", GCResource())
    site = server.Site(root)
    if ssl_context_factory is None:
        service = TCPServer(port, site)
    else:
        service = SSLServer(port, site, ssl_context_factory)
    service.setServiceParent(parent_service)
    return service
开发者ID:cloudfleet,项目名称:filesync-server,代码行数:15,代码来源:stats.py

示例13: setupReceivers

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def setupReceivers(root_service, settings):
  from carbon.protocols import MetricLineReceiver, MetricPickleReceiver, MetricDatagramReceiver

  for protocol, interface, port in [
      (MetricLineReceiver, settings.LINE_RECEIVER_INTERFACE, settings.LINE_RECEIVER_PORT),
      (MetricPickleReceiver, settings.PICKLE_RECEIVER_INTERFACE, settings.PICKLE_RECEIVER_PORT)
    ]:
    if port:
      factory = ServerFactory()
      factory.protocol = protocol
      service = TCPServer(port, factory, interface=interface)
      service.setServiceParent(root_service)

  if settings.ENABLE_UDP_LISTENER:
      service = UDPServer(int(settings.UDP_RECEIVER_PORT),
                          MetricDatagramReceiver(),
                          interface=settings.UDP_RECEIVER_INTERFACE)
      service.setServiceParent(root_service)

  if settings.ENABLE_AMQP:
    from carbon import amqp_listener
    amqp_host = settings.AMQP_HOST
    amqp_port = settings.AMQP_PORT
    amqp_user = settings.AMQP_USER
    amqp_password = settings.AMQP_PASSWORD
    amqp_verbose = settings.AMQP_VERBOSE
    amqp_vhost = settings.AMQP_VHOST
    amqp_spec = settings.AMQP_SPEC
    amqp_exchange_name = settings.AMQP_EXCHANGE

    factory = amqp_listener.createAMQPListener(
      amqp_user,
      amqp_password,
      vhost=amqp_vhost,
      spec=amqp_spec,
      exchange_name=amqp_exchange_name,
      verbose=amqp_verbose)
    service = TCPClient(amqp_host, amqp_port, factory)
    service.setServiceParent(root_service)

  if settings.ENABLE_MANHOLE:
    from carbon import manhole

    # Configure application components
    if settings.RELAY_METHOD == 'rules':
      router = RelayRulesRouter(settings["relay-rules"])
    elif settings.RELAY_METHOD == 'consistent-hashing':
      router = ConsistentHashingRouter(settings.REPLICATION_FACTOR)
    elif settings.RELAY_METHOD == 'aggregated-consistent-hashing':
      from carbon.aggregator.rules import RuleManager
      RuleManager.read_from(settings["aggregation-rules"])
      router = AggregatedConsistentHashingRouter(RuleManager, settings.REPLICATION_FACTOR)
    elif settings.RELAY_METHOD == 'remove-node-consistent-hashing':
      router = RemoveNodeConsistentHashingRouter(settings.REPLICATION_FACTOR, settings.REMOVE_NODE_INDEX)
    factory = manhole.createManholeListener()
    service = TCPServer(
      settings.MANHOLE_PORT,
      factory,
      interface=settings.MANHOLE_INTERFACE)
    service.setServiceParent(root_service)
开发者ID:zhpn,项目名称:carbon,代码行数:62,代码来源:service.py

示例14: createCacheService

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def createCacheService(config):
    from carbon.cache import MetricCache
    from carbon.conf import settings
    from carbon.protocols import CacheManagementHandler

    # Configure application components
    events.metricReceived.addHandler(MetricCache.store)

    root_service = createBaseService(config)
    factory = ServerFactory()
    factory.protocol = CacheManagementHandler
    service = TCPServer(int(settings.CACHE_QUERY_PORT), factory,
                        interface=settings.CACHE_QUERY_INTERFACE)
    service.setServiceParent(root_service)

    # have to import this *after* settings are defined
    from carbon.writer import WriterService

    service = WriterService()
    service.setServiceParent(root_service)

#    use_amqp_pub = settings.get("ENABLE_AMQP_PUB", False)
#    if use_amqp_pub:
#        from carbon import amqp_pub

#        amqp_pub_host = settings.get("AMQP_PUB_HOST", "localhost")
#        amqp_pub_port = settings.get("AMQP_PUB_PORT", 5672)
#        amqp_pub_user = settings.get("AMQP_PUB_USER", "guest")
#        amqp_pub_password = settings.get("AMQP_PUB_PASSWORD", "guest")
#        amqp_pub_verbose  = settings.get("AMQP_PUB_VERBOSE", False)
#        amqp_pub_vhost    = settings.get("AMQP_PUB_VHOST", "/")
#        amqp_pub_spec     = settings.get("AMQP_PUB_SPEC", None)
#        amqp_pub_exchange_name = settings.get("AMQP_EXCHANGE", "graphite")
#        factory = amqp_pub.createAMQPPublisher(
#            amqp_pub_user, amqp_pub_password,
#            vhost=amqp_pub_vhost, spec=amqp_pub_spec,
#            exchange_name=amqp_pub_exchange_name,
#            verbose=amqp_pub_verbose)
#        service = TCPClient(amqp_pub_host, int(amqp_pub_port), factory)
#        service.setServiceParent(root_service)

#    from carbon.amqp_pub import ProducerService
#    service = ProducerService()
#    service.setServiceParent(root_service)

    if settings.USE_FLOW_CONTROL:
      events.cacheFull.addHandler(events.pauseReceivingMetrics)
      events.cacheSpaceAvailable.addHandler(events.resumeReceivingMetrics)

    return root_service
开发者ID:pratX,项目名称:CarbonRelay_AckConsumer_d9-graphite,代码行数:52,代码来源:service.py

示例15: application

# 需要导入模块: from twisted.application.internet import TCPServer [as 别名]
# 或者: from twisted.application.internet.TCPServer import setServiceParent [as 别名]
def application(config):
    app = Application("Scrapyd")
    http_port = config.getint('http_port', 6800)
    bind_address = config.get('bind_address', '127.0.0.1')
    poll_interval = config.getfloat('poll_interval', 5)

    poller = QueuePoller(config)
    eggstorage = FilesystemEggStorage(config)
    scheduler = SpiderScheduler(config)
    environment = Environment(config)

    app.setComponent(IPoller, poller)
    app.setComponent(IEggStorage, eggstorage)
    app.setComponent(ISpiderScheduler, scheduler)
    app.setComponent(IEnvironment, environment)

    laupath = config.get('launcher', 'scrapyd.launcher.Launcher')
    laucls = load_object(laupath)
    launcher = laucls(config, app)

    timer = TimerService(poll_interval, poller.poll)

    webpath = config.get('webroot', 'scrapyd.website.Root')
    webcls = load_object(webpath)

    username = config.get('username', '')
    password = config.get('password', '')
    if username and password:
        if ':' in username:
            sys.exit("The `username` option contains illegal character ':', "
                     "check and update the configuration file of Scrapyd")
        portal = Portal(PublicHTMLRealm(webcls(config, app)),
                        [StringCredentialsChecker(username, password)])
        credential_factory = BasicCredentialFactory("Auth")
        resource = HTTPAuthSessionWrapper(portal, [credential_factory])
        log.msg("Basic authentication enabled")
    else:
        resource = webcls(config, app)
        log.msg("Basic authentication disabled as either `username` or `password` is unset")
    webservice = TCPServer(http_port, server.Site(resource), interface=bind_address)
    log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/",
            bind_address=bind_address, http_port=http_port)

    launcher.setServiceParent(app)
    timer.setServiceParent(app)
    webservice.setServiceParent(app)

    return app
开发者ID:scrapy,项目名称:scrapyd,代码行数:50,代码来源:app.py


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