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