def flatten(stan, ctx=None): """Given the stan and the optional context, return a string containing the representation of the tree in the given context. """ if ctx is None: from nevow.context import RequestContext, PageContext ctx = PageContext(tag=None, parent=RequestContext(tag=testutil.FakeRequest())) ctx.remember(None, inevow.IData) result = [] list(iterflatten(stan, ctx, result.append)) return tags.raw(''.join(result))
def flatten(stan, ctx=None): """Given the stan and the optional context, return a string containing the representation of the tree in the given context. """ if ctx is None: from nevow.context import RequestContext, PageContext from nevow.testutil import FakeRequest ctx = PageContext(tag=None, parent=RequestContext(tag=FakeRequest())) ctx.remember(None, inevow.IData) result = [] list(iterflatten(stan, ctx, result.append)) return tags.raw(''.join(result))
class FourOhFour: """A simple 404 (not found) page. """ implements(inevow.IResource) notFound = "<html><head><title>Page Not Found</title></head><body>Sorry, but I couldn't find the object you requested.</body></html>" original = None def locateChild(self, ctx, segments): return NotFound def renderHTTP(self, ctx): inevow.IRequest(ctx).setResponseCode(404) # Look for an application-remembered handler try: notFoundHandler = ctx.locate(inevow.ICanHandleNotFound) except KeyError, e: return self.notFound # Call the application-remembered handler but if there are any errors # then log it and fallback to the standard message. try: return notFoundHandler.renderHTTP_notFound( PageContext(parent=ctx, tag=notFoundHandler)) except: log.err() return self.notFound
def renderHTTP(self, ctx): from twisted.protocols import http inevow.IRequest(ctx).setResponseCode(404) try: notFoundHandler = ctx.locate(inevow.ICanHandleNotFound) return notFoundHandler.renderHTTP_notFound( PageContext(parent=ctx, tag=notFoundHandler)) except KeyError, e: return self.notFound
def renderHTTP(self, ctx): inevow.IRequest(ctx).setResponseCode(404) # Look for an application-remembered handler try: notFoundHandler = ctx.locate(inevow.ICanHandleNotFound) except KeyError as e: return self.notFound # Call the application-remembered handler but if there are any errors # then log it and fallback to the standard message. try: return notFoundHandler.renderHTTP_notFound( PageContext(parent=ctx, tag=notFoundHandler)) except: log.err() return self.notFound
def renderSynchronously(self, ctx=None): """Render this page synchronously, returning a string result immediately. Raise an exception if a Deferred is required to complete the rendering process. """ io = StringIO() ctx = PageContext(parent=ctx, tag=self) self.rememberStuff(ctx) doc = self.docFactory.load(ctx) ctx = WovenContext(ctx, tags.invisible[doc]) def raiseAlways(item): raise NotImplementedError("renderSynchronously can not support" " rendering: %s" % (item, )) list(flat.iterflatten(doc, ctx, io.write, raiseAlways)) return io.getvalue()
def renderString(self, ctx=None): """Render this page outside of the context of a web request, returning a Deferred which will result in a string. If twisted is not installed, this method will return a string result immediately, and this method is equivalent to renderSynchronously. """ io = StringIO() writer = io.write def finisher(result): return io.getvalue() ctx = PageContext(parent=ctx, tag=self) self.rememberStuff(ctx) doc = self.docFactory.load(ctx) ctx = WovenContext(ctx, tags.invisible[doc]) return self.flattenFactory(doc, ctx, writer, finisher)