本文整理汇总了Python中twisted.web.resource.Resource.putChild方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.putChild方法的具体用法?Python Resource.putChild怎么用?Python Resource.putChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.resource.Resource
的用法示例。
在下文中一共展示了Resource.putChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_server
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def start_server(port, destport):
revproxy = ReverseProxyResource("127.0.0.1", destport, "/blobs")
resource = Resource()
resource.putChild("", DummyResource())
resource.putChild("blobs", revproxy)
site = Site(resource)
reactor.listenTCP(port, site)
示例2: create_api_service
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def create_api_service(persistence_service, cluster_state_service, endpoint,
context_factory, clock=reactor):
"""
Create a Twisted Service that serves the API on the given endpoint.
:param ConfigurationPersistenceService persistence_service: Service
for retrieving and setting desired configuration.
:param ClusterStateService cluster_state_service: Service that
knows about the current state of the cluster.
:param endpoint: Twisted endpoint to listen on.
:param context_factory: TLS context factory.
:param IReactorTime clock: The clock to use for time. By default
global reactor.
:return: Service that will listen on the endpoint using HTTP API server.
"""
api_root = Resource()
user = ConfigurationAPIUserV1(persistence_service, cluster_state_service,
clock)
api_root.putChild('v1', user.app.resource())
api_root._v1_user = user # For unit testing purposes, alas
return StreamServerEndpointService(
endpoint,
TLSMemoryBIOFactory(
context_factory,
False,
Site(api_root)
)
)
示例3: setUp
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def setUp(self):
super(FlockerDeployTests, self).setUp()
ca_set, _ = get_credential_sets()
self.certificate_path = FilePath(self.mktemp())
self.certificate_path.makedirs()
ca_set.copy_to(self.certificate_path, user=True)
self.persistence_service = ConfigurationPersistenceService(
reactor, FilePath(self.mktemp()))
self.persistence_service.startService()
self.cluster_state_service = ClusterStateService(reactor)
self.cluster_state_service.startService()
self.cluster_state_service.apply_changes([
NodeState(uuid=uuid4(), hostname=ip)
for ip in COMPLEX_DEPLOYMENT_YAML[u"nodes"].keys()
])
self.addCleanup(self.cluster_state_service.stopService)
self.addCleanup(self.persistence_service.stopService)
app = ConfigurationAPIUserV1(self.persistence_service,
self.cluster_state_service).app
api_root = Resource()
api_root.putChild('v1', app.resource())
# Simplest possible TLS context that presents correct control
# service certificate; no need to validate flocker-deploy here.
self.port = reactor.listenSSL(
0,
Site(api_root),
DefaultOpenSSLContextFactory(
ca_set.path.child(b"control-127.0.0.1.key").path,
ca_set.path.child(b"control-127.0.0.1.crt").path),
interface="127.0.0.1")
self.addCleanup(self.port.stopListening)
self.port_number = self.port.getHost().port
示例4: build_resource
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def build_resource():
root = Resource()
for key, val in RESOURCE_MAPPING.iteritems():
root.putChild(key, val)
return root
示例5: __init__
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def __init__(self, config, port=None):
super(IdentityServer, self).__init__(config)
self.plugin_mapping = config["plugin_mapping"]
self.setupMySQL(config)
self.setupIdentityQueue(config)
self.cassandra_cf_identity = config["cassandra_cf_identity"]
self.cassandra_cf_connections = config["cassandra_cf_connections"]
self.cassandra_cf_recommendations = config["cassandra_cf_recommendations"]
self.cassandra_cf_reverse_recommendations = config["cassandra_cf_reverse_recommendations"]
self.cassandra_client = CassandraClusterPool(
config["cassandra_servers"],
keyspace=config["cassandra_keyspace"],
pool_size=len(config["cassandra_servers"]) * 2)
self.cassandra_client.startService()
resource = Resource()
self.function_resource = Resource()
resource.putChild("function", self.function_resource)
if port is None:
port = config["identity_server_port"]
self.site_port = reactor.listenTCP(port, server.Site(resource))
self.expose(self.updateConnections)
self.expose(self.updateAllConnections)
self.expose(self.updateAllIdentities)
self.expose(self.getRecommendations)
self.expose(self.getReverseRecommendations)
self.expose(self.updateIdentity)
# setup manhole
manhole_namespace = {
'service': self,
'globals': globals(),
}
reactor.listenTCP(config["manhole_identity_port"], self.getManholeFactory(manhole_namespace, admin=config["manhole_password"]))
示例6: startService
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def startService(self):
app = self._prov_service.app
dhcp_request_processing_service = self._dhcp_process_service.dhcp_request_processing_service
if self._config['general.rest_authentication']:
credentials = (self._config['general.rest_username'],
self._config['general.rest_password'])
server_resource = new_restricted_server_resource(app, dhcp_request_processing_service, credentials)
logger.info('Authentication is required for REST API')
else:
server_resource = new_server_resource(app, dhcp_request_processing_service)
logger.warning('No authentication is required for REST API')
root_resource = Resource()
root_resource.putChild('provd', server_resource)
rest_site = Site(root_resource)
port = self._config['general.rest_port']
interface = self._config['general.rest_ip']
if interface == '*':
interface = ''
logger.info('Binding HTTP REST API service to "%s:%s"', interface, port)
if self._config['general.rest_ssl']:
logger.info('SSL enabled for REST API')
context_factory = ssl.DefaultOpenSSLContextFactory(self._config['general.rest_ssl_keyfile'],
self._config['general.rest_ssl_certfile'])
self._tcp_server = internet.SSLServer(port, rest_site, context_factory, interface=interface)
else:
self._tcp_server = internet.TCPServer(port, rest_site, interface=interface)
self._tcp_server.startService()
Service.startService(self)
示例7: run_twisted
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def run_twisted(apps, port, static_dir='.'):
"""Twisted wrapper for the rpclib.server.wsgi.Application
Takes a list of tuples containing application, url pairs, and a port to
to listen to.
"""
if static_dir != None:
static_dir = os.path.abspath(static_dir)
logging.info("registering static folder %r on /" % static_dir)
root = twisted.web.static.File(static_dir)
else:
root = Resource()
for app, url in apps:
resource = WSGIResource(reactor, reactor, app)
logging.info("registering %r on /%s" % (app, url))
root.putChild(url, resource)
site = twisted.web.server.Site(root)
reactor.listenTCP(port, site)
logging.info("listening on: 0.0.0.0:%d" % port)
return reactor.run()
示例8: setUp
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def setUp():
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
log.startLogging(sys.stdout)
debug = True
else:
debug = False
try:
import autobahn
import twisted
except ImportError:
sys.exit("Install all dependencies")
root = Resource()
# root.putChild(constants.WEB_DYNAMIC_BRANCH, resource)
from autobahn.twisted.resource import WebSocketResource, HTTPChannelHixie76Aware
from twisted.web.server import Site
factory = BroadcastServerFactory("ws://127.0.0.1:8888", debug=debug, debugCodePaths=debug)
#если используется proxy
#factory.proxy={'host': '192.168.200.105', 'port': '8088'}
factory.protocol = BroadcastServerProtocol
factory.setProtocolOptions(allowHixie76=True)
ws_resource = WebSocketResource(factory)
root.putChild("ws", ws_resource)
site = Site(root)
site.protocol = HTTPChannelHixie76Aware
listenWS(factory)
reactor.run()
示例9: create_root
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def create_root(config):
from scrapy import log
from scrapy.settings import CrawlerSettings
from slyd.crawlerspec import (CrawlerSpecManager,
create_crawler_spec_resource)
from slyd.bot import create_bot_resource
import slyd.settings
from slyd.projects import ProjectsResource
root = Resource()
root.putChild("static", File(config['docroot']))
crawler_settings = CrawlerSettings(settings_module=slyd.settings)
spec_manager = CrawlerSpecManager(crawler_settings)
# add project management at /projects
projects = ProjectsResource(crawler_settings)
root.putChild('projects', projects)
# add crawler at /projects/PROJECT_ID/bot
log.msg("Slybot specs loading from %s/[PROJECT]" % spec_manager.basedir,
level=log.DEBUG)
projects.putChild("bot", create_bot_resource(spec_manager))
# add spec at /projects/PROJECT_ID/spec
spec = create_crawler_spec_resource(spec_manager)
projects.putChild("spec", spec)
return root
示例10: __init__
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def __init__(self):
Resource.__init__(self)
Loggable.__init__(self)
log = Resource()
log.putChild("client", LogClientResource())
self.putChild("log", log)
示例11: __init__
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def __init__(self, config):
Resource.__init__(self)
self._triggerid = reactor.addSystemEventTrigger('before', 'shutdown', self.shutdownEvent)
# Create Envisalink client connection
self._envisalinkClientFactory = EnvisalinkClientFactory(config)
self._envisaconnect = reactor.connectTCP(config.ENVISALINKHOST, config.ENVISALINKPORT, self._envisalinkClientFactory)
# Store config
self._config = config
root = Resource()
rootFilePath = sys.path[0] + os.sep + 'ext'
root.putChild('app', File(rootFilePath))
root.putChild('img', File(rootFilePath))
root.putChild('api', self)
factory = Site(root)
# conditionally import twisted ssl to help avoid unwanted depdencies and import issues on some systems
if config.LISTENTYPE.lower() == "tcp":
self._port = reactor.listenTCP(config.LISTENPORT, factory)
elif config.LISTENTYPE.lower() == "ssl":
from twisted.internet import ssl
self._port = reactor.listenSSL(config.LISTENPORT, factory,
ssl.DefaultOpenSSLContextFactory(config.KEYFILE, config.CERTFILE))
else:
logging.warning("AlarmServer listen type %s unknown, server not started.", config.LISTENTYPE)
示例12: test
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def test():
import sys
from twisted.internet import reactor
from twisted.python.log import startLogging
from twisted.web.server import Site
startLogging(sys.stderr)
properties = {
'playlist-entry': [
{'stream-url':
'http://example.com/iphone/low/stream.m3u8',
'bitrate': 100000},
{'stream-url':
'http://example.com/iphone/medium/stream.m3u8',
'bitrate': 200000},
{'stream-url':
'http://example.com/iphone/high/stream.m3u8',
'bitrate': 400000},
]}
root = Resource()
mount_point = Resource()
playlist = PlaylistResource(properties['playlist-entry'])
root.putChild('test', mount_point)
mount_point.putChild('main.m3u8', playlist)
site = Site(root)
reactor.listenTCP(8080, site)
reactor.run()
示例13: __init__
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def __init__(self,service_config, hwios_config):
self.hwios_config = hwios_config
self.config = service_config
root = Resource()
root.putChild("tiles",TileService(os.path.join(self.config.location,self.config.get('map','tilepath'))))
site = server.Site(root)
site.displayTracebacks = False
self.config.tilepath = os.path.join(self.config.location,'tiles')
self.tiler = Tiler(self.config)
self.get_client_settings()
#override hwios general ssl setting
if self.hwios_config.has_option('general','ssl'):
from twisted.internet import ssl
from hwios.core.connection import ServerContextFactory
self.__service = SSLServer(self.config.getint('service', 'port'),site,ServerContextFactory())
else:
if self.config.getboolean('service','ssl'):
from twisted.internet import ssl
from hwios.core.connection import ServerContextFactory
self.client_settings['ssl'] = True
self.__service = SSLServer(self.config.getint('service', 'port'),site,ServerContextFactory())
else:
self.client_settings['ssl'] = False
self.__service = TCPServer(self.config.getint('service','port'),site,100,self.config.get('service','listen'))
示例14: __init__
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def __init__(self, irc):
'''
Initialize the twisted web server with the proper
ports and URI values.
'''
callbacks.Plugin.__init__(self, irc)
if not reactor:
self.irc.error('Twisted is not installed.')
root = Resource()
pathmaps = self.registryValue('pathmaps')
path_dict = {}
for i in range(0, len(pathmaps), 2):
path_dict[pathmaps[i]] = pathmaps[i+1]
for uri, channel in path_dict.items():
post_page = PostPage(irc)
post_page.set_channel(channel)
root.putChild(uri, post_page)
factory = Site(root)
reactor.listenTCP(self.registryValue('port'), factory)
示例15: __init__
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import putChild [as 别名]
def __init__(self):
root = Resource()
## downloads server -- client grabs patch info from here
root.putChild('u', VirtualFile('webRoot/downloads/u'))
## MOST OF THE BELOW DONT WORK SO ARE COMMENTED OUT
## redalert3pc.sake.gamespy.com
sakeStorageServer = Resource()
sakeStorageServer.putChild('StorageServer.asmx', StorageServer())
#root.putChild('SakeStorageServer', sakeStorageServer)
## redalert3pc.auth.pubsvs.gamespy.com -- used to auth before reporting results
authService = Resource()
authService.putChild('AuthService.asmx', AuthService())
#root.putChild('AuthService', authService)
## redalert3pc.comp.pubsvs.gamespy.com -- used to report match results
compSvc = Resource()
compSvc.putChild('competitionservice.asmx', CompetitionService())
#compSvc.putChild('CompetitionService.asmx', CompetitionService())
root.putChild('competitionservice', compSvc)
#root.putChild('CompetitionService', compSvc)
## TODO: psweb.gamespy.com -- SOAP service that serves Clan-related requests
## TODO: redalert3services.gamespy.com -- HTTP GET requests that serve rank icons
## /GetPlayerRankIcon.aspx?gp=fgErop[sap9faZeJJELRac__&pid=<pid of player> retrieves that player's rank icon
## /GetPlayerLadderRatings.aspx?gp=fgErop[sap9faZeJJELRac__ retrieves CSV of ladder ratings
Site.__init__(self, root)