class documentation

class Resource: (source)

Known subclasses: twisted.web.distrib.ResourceSubscription, twisted.web.distrib.UserDirectory, twisted.web.proxy.ReverseProxyResource, twisted.web.resource.ErrorPage, twisted.web.rewrite.RewriterResource, twisted.web.script.PythonScript, twisted.web.script.ResourceScriptDirectory, twisted.web.script.ResourceScriptWrapper, twisted.web.soap.SOAPPublisher, twisted.web.static.ASISProcessor, twisted.web.static.Data, twisted.web.static.DirectoryLister, twisted.web.static.File, twisted.web.static.Redirect, twisted.web.twcgi.CGIDirectory, twisted.web.twcgi.CGIScript, twisted.web.util.DeferredResource, twisted.web.util.ParentRedirect, twisted.web.util.Redirect, twisted.web.vhost.NameVirtualHost, twisted.web.vhost.VHostMonsterResource, twisted.web.xmlrpc.XMLRPC, twisted.web.tap._AddHeadersResource, twisted.web.vhost._HostResource

Implements interfaces: twisted.web.resource.IResource

View In Hierarchy

Define a web-accessible resource.

This serves 2 main purposes; one is to provide a standard representation for what HTTP specification calls an 'entity', and the other is to provide an abstract directory structure for URL retrieval.

Method __init__ Initialize.
Method delEntity Undocumented
Method getChild Retrieve a 'child' resource from me.
Method getChildForRequest Undocumented
Method getChildWithDefault Retrieve a static or dynamically generated child resource from me.
Method getDynamicEntity Undocumented
Method getStaticEntity Undocumented
Method listDynamicEntities Undocumented
Method listDynamicNames Undocumented
Method listEntities Undocumented
Method listNames Undocumented
Method listStaticEntities Undocumented
Method listStaticNames Undocumented
Method putChild Register a static child.
Method reallyPutEntity Undocumented
Method render Render a given resource. See IResource's render method.
Method render_HEAD Default handling of HEAD method.
Class Variable isLeaf Signal if this IResource implementor is a "leaf node" or not. If True, getChildWithDefault will not be called on this Resource.
Class Variable server Undocumented
Instance Variable children Undocumented
def delEntity(self, name): (source)


def getChild(self, path, request): (source)

Retrieve a 'child' resource from me.

Implement this to create dynamic resource generation -- resources which are always available may be registered with self.putChild().

This will not be called if the class-level variable 'isLeaf' is set in your subclass; instead, the 'postpath' attribute of the request will be left as a list of the remaining path elements.

For example, the URL /foo/bar/baz will normally be:

  | site.resource.getChild('foo').getChild('bar').getChild('baz').

However, if the resource returned by 'bar' has isLeaf set to true, then the getChild call will never be made on it.

Parameters and return value have the same meaning and requirements as those defined by IResource.getChildWithDefault.

def getChildForRequest(self, request): (source)


def getChildWithDefault(self, path, request): (source)

Retrieve a static or dynamically generated child resource from me.

First checks if a resource was added manually by putChild, and then call getChild to check for dynamic resources. Only override if you want to affect behaviour of all child lookups, rather than just dynamic ones.

This will check to see if I have a pre-registered child resource of the given name, and call getChild if I do not.

See Also
def getDynamicEntity(self, name, request): (source)


def getStaticEntity(self, name): (source)


def listDynamicEntities(self, request=None): (source)


def listDynamicNames(self): (source)


def listEntities(self): (source)


def listNames(self): (source)


def listStaticEntities(self): (source)


def listStaticNames(self): (source)


def putChild(self, path, child): (source)

Register a static child.

You almost certainly don't want '/' in your path. If you intended to have the root of a folder, e.g. /foo/, you want path to be ''.

path:bytesA single path component.
child:IResourceThe child resource to register.
See Also
def reallyPutEntity(self, name, entity): (source)


def render(self, request): (source)

Render a given resource. See IResource's render method.

I delegate to methods of self with the form 'render_METHOD' where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is server.NOT_DONE_YET, in which case it is this class's responsibility to write the results using request.write(data) and then call request.finish().

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

See Also
def render_HEAD(self, request): (source)

Default handling of HEAD method.

I just return self.render_GET(request). When method is HEAD, the framework will handle this correctly.

server = (source)


children: dict = (source)