本文整理汇总了Python中twisted.web.resource.Resource.isLeaf方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.isLeaf方法的具体用法?Python Resource.isLeaf怎么用?Python Resource.isLeaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.resource.Resource
的用法示例。
在下文中一共展示了Resource.isLeaf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_leafResource
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import isLeaf [as 别名]
def test_leafResource(self):
"""
L{getChildForRequest} returns the first resource it encounters with a
C{isLeaf} attribute set to C{True}.
"""
request = DummyRequest([b"foo", b"bar"])
resource = Resource()
resource.isLeaf = True
result = getChildForRequest(resource, request)
self.assertIdentical(resource, result)
示例2: wrapper
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import isLeaf [as 别名]
def wrapper(fn):
"""
:type path: str
"""
r = Resource()
r.render_GET = fn
r.isLeaf = True
self.routes[path] = r
return fn
示例3: on_login
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import isLeaf [as 别名]
def on_login(_):
logger.info("Logged in as '%s'", spotify.session.user_name)
root = Resource()
root.isLeaf = False
player = Player(spotify)
root.putChild("player",player)
root.putChild("static",File(cfg.get("SERVER", "static")))
site = Site(root)
# setup and register service
reactor.listenTCP(port, site)
logger.info("Listening on %s:%d", host, port)
zeroconf.register_service(service_info)
示例4: test_postPathToPrePath
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import isLeaf [as 别名]
def test_postPathToPrePath(self):
"""
As path segments from the request are traversed, they are taken from
C{postpath} and put into C{prepath}.
"""
request = DummyRequest([b"foo", b"bar"])
root = Resource()
child = Resource()
child.isLeaf = True
root.putChild(b"foo", child)
self.assertIdentical(child, getChildForRequest(root, request))
self.assertEqual(request.prepath, [b"foo"])
self.assertEqual(request.postpath, [b"bar"])
示例5: make_real_webserver
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import isLeaf [as 别名]
def make_real_webserver(self):
"""
Construct a real webserver to test actual connectivity.
"""
root = Resource()
root.isLeaf = True
root.render = lambda r: self._render_request(r)
site_factory = Site(root)
webserver = yield reactor.listenTCP(
0, site_factory, interface='127.0.0.1')
self.add_cleanup(webserver.loseConnection)
addr = webserver.getHost()
url = "http://%s:%s/" % (addr.host, addr.port)
returnValue(url)
示例6: render_GET
# 需要导入模块: from twisted.web.resource import Resource [as 别名]
# 或者: from twisted.web.resource.Resource import isLeaf [as 别名]
def render_GET(self, request):
request.transport.socket.settimeout(5)
if not getattr(twisted_bluetooth, "SCOReader", None):
raise Exception("Not supported in your platform")
address = request.path.split("/",2)[-1].replace("_", ":")
if address == "" or len(address) != 17:
raise Exception("Invalid address")
scoclient = SCOStream(request)
scoclient.process()
scoclient.target = address
if len(address) == 17:
if not twisted_bluetooth.SCOConnected(address):
log.msg("Connecting SCO to %s" % address)
client = twisted_bluetooth.SCOReader(address,
self.gotFrame, self.lostConnection)
log.msg("SCO connected")
return server.NOT_DONE_YET
if __name__ == '__main__':
from twisted.web.server import Site
import sys
log.startLogging(sys.stdout)
root = Resource()
root.isLeaf = False
root.putChild("sco", SCOResource())
reactor.listenTCP(8800, Site(root), interface="0.0.0.0")
reactor.run()#!/usr/bin/env python