[Twisted-Python] Any examples of an authenticating XMLRPC server?
Mike C. Fletcher
mcfletch at rogers.com
Mon Feb 28 17:42:58 EST 2005
Matt Goodall wrote:
>On Mon, 2005-02-28 at 14:15 -0500, Mike C. Fletcher wrote:
>
>
>>Stephen Waterbury wrote:
>>...
>>
>>
>>
>>>Critiques or razberries welcomed, as long as they're
>>>constructive razberries! :)
>>>
>>>
>>This is extremely illuminating. The key approach/idea that I was
>>missing is this:
>>
>> You can create a root web.resource.Resource() and add a child ""
>> that handles all URLs not otherwise matched by a known child.
>>
>>
>
>This is incorrect. A child of "" matches the empty path segment. Most of
>the time this is used to handle a URL that ends in a "/" but an empty
>segment is also legitimate in the middle of a URL.
>
>
I stand corrected, though somewhat confused as to how Stephen's code is
working, then. My own experience does back up your statement, though.
>In Nevow, you handle unmatched children by overriding locateChild(self,
>ctx, segments) or, in the case of a rend.Page subclass, providing a
>childFactory(self, ctx, name) method.
>
>
Indeed, as I discovered in implementing this. Still, Stephen's approach
works fine, I was just wrong about thinking it was implemented
automatically for the "" case. To make it work with a Nevow site, I
created a root resource like this:
class SiteRoot( object ):
__implements__ = (inevow.IResource, )
isLeaf = False
def __init__( self, root ):
"""Initialise the overall root"""
self.root = root
self.RPC = webservices.XMLRPCServer()
def locateChild(self, ctx, segments):
"""Locate child, return as inevow.IResource"""
if segments:
if segments[0] == 'RPC':
return self.RPC, segments[1:]
return self.root, segments
def renderHTTP( self, ctx, **named ):
"""Render this resource on an HTTP request"""
raise ValueError( """You shouldn't be able to view this
node!""" )
then wrap the SiteRoot instance in a nevow.appserver.NevowSite instance
(it won't work if you try to use a twisted.web site, because that site
class doesn't know how to traverse Nevow resources). You also AFAICS
should not wrap the "root" in an appserver.NevowSite instance (it seems
there should only be one site instance for any given web-server).
So, to recap:
nevow.appserver.NevowSite
SiteRoot( root )
root = guard.SessionWrapper( portal.Portal( realm.YourRealm(
rootResourceForNormalSite ) ) ) -- with the appropriate
credential checkers registered.
Enjoy, and thanks all,
Mike
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
PyCon is coming...
More information about the Twisted-Python
mailing list