[Twisted-web] Use Nevow in conjunction with XMLRPC

Remi Cool mailinglists at smartology.nl
Tue Nov 15 00:53:39 MST 2005


G'day,

My goal is to create a Twisted server that implements XMLRPC, Nevow and
PHP (for transition of the old webapp).

XMLRPC works again (thanks to Daniel and Matt) ... but I can't get Nevow
working as a child of the httpResource. Or is there a better (Twisted)
way of doing this (without using tap)?

The code:

from formless.annotate import TypedInterface, Integer, String
from nevow import rend, tags, loaders
from formless import webform

class ISimpleMethod(TypedInterface):
    def simple(self,
        name=String(description="Your name."),
        age=Integer(description="Your age.")):
        """Simple

        Please enter your name and age.
        """

class Implementation(object):

    implements(ISimpleMethod)

    def simple(self, name, age):
        print "Hello, %s, who is %s" % (name, age)


class WebForm(rend.Page):
    document = loaders.stan(tags.html[
    tags.body[ tags.h1["Here is the form:"],
                        webform.renderForms('original')]])



class httpResource(resource.Resource):

    implements(resource.IResource)

    def __init__(self, service):
        resource.Resource.__init__(self)
        self.service = service
        self.putChild('RPC2', Example(self.service))
        self.putChild('formtest',
resource.Resource(WebForm(Implementation())))

    def render(self, request):
        self._clientIP = request.getClientIP()
        return resource.Resource.render(self, request)

    def render_GET(self, request):
        """Process HTTP GET Requests."""
        print 'GET: request ->', request
        return '<html><body><h3>Not Implemented</h3></body></html>'

    def getChild(self, path, request):
        """This method handles http calls"""
        print 'getChild path:', path
        print 'getChild request:', request
        if path=="":
            return httpResource(self.service)
        else:
            return httpResource(self.service)

components.registerAdapter(httpResource, IowwService, resource.IResource)





More information about the Twisted-web mailing list