本文整理汇总了Python中twisted.web.wsgi.WSGIResource方法的典型用法代码示例。如果您正苦于以下问题:Python wsgi.WSGIResource方法的具体用法?Python wsgi.WSGIResource怎么用?Python wsgi.WSGIResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.wsgi
的用法示例。
在下文中一共展示了wsgi.WSGIResource方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: boot_frontend
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def boot_frontend(config, debug=False):
"""
Boot a Pyramid WSGI application as Twisted component
"""
http_port = int(config.get('config-web', 'http_port'))
websocket_uri = unicode(config.get('wamp', 'listen'))
# https://stackoverflow.com/questions/13122519/serving-pyramid-application-using-twistd/13138610#13138610
config = resource_filename('kotori.frontend', 'development.ini')
application = get_app(config, 'main')
# https://twistedmatrix.com/documents/13.1.0/web/howto/web-in-60/wsgi.html
resource = WSGIResource(reactor, reactor.getThreadPool(), application)
reactor.listenTCP(http_port, Site(resource))
示例2: test_wsgi
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def test_wsgi(self):
"""
The I{--wsgi} option takes the fully-qualifed Python name of a WSGI
application object and creates a L{WSGIResource} at the root which
serves that application.
"""
options = Options()
options.parseOptions(['--wsgi', __name__ + '.application'])
root = options['root']
self.assertTrue(root, WSGIResource)
self.assertIdentical(root._reactor, reactor)
self.assertTrue(isinstance(root._threadpool, ThreadPool))
self.assertIdentical(root._application, application)
# The threadpool should start and stop with the reactor.
self.assertFalse(root._threadpool.started)
reactor.fireSystemEvent('startup')
self.assertTrue(root._threadpool.started)
self.assertFalse(root._threadpool.joined)
reactor.fireSystemEvent('shutdown')
self.assertTrue(root._threadpool.joined)
示例3: run
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def run(self, handler):
from twisted.web import server, wsgi
from twisted.python.threadpool import ThreadPool
from twisted.internet import reactor
thread_pool = ThreadPool()
thread_pool.start()
reactor.addSystemEventTrigger('after', 'shutdown', thread_pool.stop)
factory = server.Site(wsgi.WSGIResource(reactor, thread_pool, handler))
reactor.listenTCP(self.port, factory, interface=self.host)
reactor.run()
示例4: run
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def run(self, handler):
from twisted.web import server, wsgi
from twisted.python.threadpool import ThreadPool
from twisted.internet import reactor
thread_pool = ThreadPool()
thread_pool.start()
reactor.addSystemEventTrigger('after', 'shutdown', thread_pool.stop)
factory = server.Site(wsgi.WSGIResource(reactor, thread_pool, handler))
reactor.listenTCP(self.port, factory, interface=self.host)
if not reactor.running:
reactor.run()
示例5: opt_wsgi
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def opt_wsgi(self, name):
"""
The FQPN of a WSGI application object to serve as the root resource of
the webserver.
"""
try:
application = reflect.namedAny(name)
except (AttributeError, ValueError):
raise usage.UsageError("No such WSGI application: %r" % (name,))
pool = threadpool.ThreadPool()
reactor.callWhenRunning(pool.start)
reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
self['root'] = wsgi.WSGIResource(reactor, pool, application)
示例6: setUp
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def setUp(self):
"""
Create a L{WSGIResource} with synchronous threading objects and a no-op
application object. This is useful for testing certain things about
the resource implementation which are unrelated to WSGI.
"""
self.resource = WSGIResource(
SynchronousReactorThreads(), SynchronousThreadPool(),
lambda environ, startResponse: None)
示例7: test_interfaces
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def test_interfaces(self):
"""
L{WSGIResource} implements L{IResource} and stops resource traversal.
"""
verifyObject(IResource, self.resource)
self.assertTrue(self.resource.isLeaf)
示例8: test_unsupported
# 需要导入模块: from twisted.web import wsgi [as 别名]
# 或者: from twisted.web.wsgi import WSGIResource [as 别名]
def test_unsupported(self):
"""
A L{WSGIResource} cannot have L{IResource} children. Its
C{getChildWithDefault} and C{putChild} methods raise L{RuntimeError}.
"""
self.assertRaises(
RuntimeError,
self.resource.getChildWithDefault,
b"foo", Request(DummyChannel(), False))
self.assertRaises(
RuntimeError,
self.resource.putChild,
b"foo", Resource())