http.NOT_IMPLEMENTED)
super = appserver.DefaultExceptionHandler
return super.renderHTTP_exception(self, ctx, f)
+
+class RenderMixin:
+
+ def renderHTTP(self, ctx):
+ request = IRequest(ctx)
+
+ # if we were using regular twisted.web Resources (and the regular
+ # twisted.web.server.Request object) then we could implement
+ # render_PUT and render_GET. But Nevow's request handler
+ # (NevowRequest.gotPageContext) goes directly to renderHTTP. Copy
+ # some code from the Resource.render method that Nevow bypasses, to
+ # do the same thing.
+ m = getattr(self, 'render_' + request.method, None)
+ if not m:
+ from twisted.web.server import UnsupportedMethod
+ raise UnsupportedMethod(getattr(self, 'allowedMethods', ()))
+ return m(ctx)
ExistingChildError
from allmydata.web.common import text_plain, WebError, IClient, \
boolean_of_arg, get_arg, should_create_intermediate_directories, \
- getxmlfile
+ getxmlfile, RenderMixin
from allmydata.web.filenode import ReplaceMeMixin, \
FileNodeHandler, PlaceHolderNodeHandler
return DirectoryNodeHandler(node, parentnode, name)
raise WebError("Cannot provide handler for '%s'" % node)
-class DirectoryNodeHandler(rend.Page, ReplaceMeMixin):
+class DirectoryNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
addSlash = True
def __init__(self, node, parentnode=None, name=None):
if DEBUG: print "good child"
return make_handler_for(node, self.node, name)
- def renderHTTP(self, ctx):
- # This is where all of the ?t=* actions are implemented.
- request = IRequest(ctx)
-
- # if we were using regular twisted.web Resources (and the regular
- # twisted.web.server.Request object) then we could implement
- # render_PUT and render_GET. But Nevow's request handler
- # (NevowRequest.gotPageContext) goes directly to renderHTTP. Copy
- # some code from the Resource.render method that Nevow bypasses, to
- # do the same thing.
- m = getattr(self, 'render_' + request.method, None)
- if not m:
- from twisted.web.server import UnsupportedMethod
- raise UnsupportedMethod(getattr(self, 'allowedMethods', ()))
- return m(ctx)
-
def render_DELETE(self, ctx):
assert self.parentnode and self.name
d = self.parentnode.delete(self.name)
from allmydata.mutable.common import MODE_READ
from allmydata.util import log
-from allmydata.web.common import text_plain, WebError, IClient, \
+from allmydata.web.common import text_plain, WebError, IClient, RenderMixin, \
boolean_of_arg, get_arg, should_create_intermediate_directories
class ReplaceMeMixin:
d.addCallback(lambda newnode: newnode.get_uri())
return d
-class PlaceHolderNodeHandler(rend.Page, ReplaceMeMixin):
+class PlaceHolderNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
def __init__(self, parentnode, name):
rend.Page.__init__(self)
assert parentnode
% name, http.CONFLICT)
- def renderHTTP(self, ctx):
- # This is where all of the ?t=* actions are implemented.
- request = IRequest(ctx)
-
- # if we were using regular twisted.web Resources (and the regular
- # twisted.web.server.Request object) then we could implement
- # render_PUT and render_GET. But Nevow's request handler
- # (NevowRequest.gotPageContext) goes directly to renderHTTP. Copy
- # some code from the Resource.render method that Nevow bypasses, to
- # do the same thing.
- m = getattr(self, 'render_' + request.method, None)
- if not m:
- from twisted.web.server import UnsupportedMethod
- raise UnsupportedMethod(getattr(self, 'allowedMethods', ()))
- return m(ctx)
-
def render_PUT(self, ctx):
req = IRequest(ctx)
t = get_arg(req, "t", "").strip()
return d
-class FileNodeHandler(rend.Page, ReplaceMeMixin):
+class FileNodeHandler(RenderMixin, rend.Page, ReplaceMeMixin):
def __init__(self, node, parentnode=None, name=None):
rend.Page.__init__(self)
assert node
raise WebError("Files have no children, certainly not named '%s'"
% name)
-
- def renderHTTP(self, ctx):
- # This is where all of the ?t=* actions are implemented.
- request = IRequest(ctx)
-
- # if we were using regular twisted.web Resources (and the regular
- # twisted.web.server.Request object) then we could implement
- # render_PUT and render_GET. But Nevow's request handler
- # (NevowRequest.gotPageContext) goes directly to renderHTTP. Copy
- # some code from the Resource.render method that Nevow bypasses, to
- # do the same thing.
- m = getattr(self, 'render_' + request.method, None)
- if not m:
- from twisted.web.server import UnsupportedMethod
- raise UnsupportedMethod(getattr(self, 'allowedMethods', ()))
- return m(ctx)
-
def render_GET(self, ctx):
req = IRequest(ctx)
t = get_arg(req, "t", "").strip()
from allmydata.interfaces import IFileNode
from allmydata.web import filenode, directory, unlinked, status
from allmydata.web.common import abbreviate_size, IClient, getxmlfile, \
- WebError, get_arg
+ WebError, get_arg, RenderMixin
-class URIHandler(rend.Page):
+class URIHandler(RenderMixin, rend.Page):
# I live at /uri . There are several operations defined on /uri itself,
# mostly involed with creation of unlinked files and directories.
- def renderHTTP(self, ctx):
- request = IRequest(ctx)
-
- # if we were using regular twisted.web Resources (and the regular
- # twisted.web.server.Request object) then we could implement
- # render_PUT and render_GET. But Nevow's request handler
- # (NevowRequest.gotPageContext) goes directly to renderHTTP. Copy
- # some code from the Resource.render method that Nevow bypasses, to
- # do the same thing.
- m = getattr(self, 'render_' + request.method, None)
- if not m:
- from twisted.web.server import UnsupportedMethod
- raise UnsupportedMethod(getattr(self, 'allowedMethods', ()))
- return m(ctx)
-
def render_GET(self, ctx):
req = IRequest(ctx)
uri = get_arg(req, "uri", None)