def getChildWithDefault(self, name, request):
"""
Reject attempts to retrieve a child resource. All path segments beyond
the one which refers to this resource are handled by the WebSocket
connection.
@type name: C{bytes}
@param name: A single path component from a requested URL.
@type request: L{twisted.web.iweb.IRequest} provider
@param request: The request received.
"""
raise RuntimeError(
"Cannot get IResource children from WebSocketsResource")
python类IResource()的实例源码
def putChild(self, path, child):
"""
Reject attempts to add a child resource to this resource. The
WebSocket connection handles all path segments beneath this resource,
so L{IResource} children can never be found.
@type path: C{bytes}
@param path: A single path component.
@type child: L{IResource} provider
@param child: A resource to put underneat this one.
"""
raise RuntimeError(
"Cannot put IResource children under WebSocketsResource")
def getChild(self, path, request):
s = request.getSession()
if s is None:
return request.setupSession()
if path == INIT_PERSPECTIVE:
def loginSuccess(result):
interface, avatarAspect, logout = result
s.setResourceForPortal(avatarAspect, self.portal, logout)
def triggerLogin(username, password, submit=None):
return self.portal.login(
UsernamePassword(username, password),
None,
IResource
).addCallback(
loginSuccess
).addErrback(
self._ebFilter
)
return form.FormProcessor(
newLoginSignature.method(
triggerLogin
),
callback=self.callback,
errback=self.errback
)
elif path == DESTROY_PERSPECTIVE:
s.portalLogout(self.portal)
return Redirect(".")
else:
r = s.resourceForPortal(self.portal)
if r:
## Delegate our getChild to the resource our portal says is the right one.
return getResource(r[0], path, request)
else:
return DeferredResource(
self.portal.login(Anonymous(), None, IResource
).addCallback(
lambda (interface, avatarAspect, logout):
getResource(s.setResourceForPortal(avatarAspect,
self.portal, logout),
path, request)))