def createWSGIApplication(page, rootURL=None): """Given a Page instance, return a WSGI callable. `rootURL` - URL to be remembered as root """ page.flattenFactory = flat.iterflatten siteCtx = context.SiteContext(tag=None) def application(environ, start_response): request = WSGIRequest(environ, start_response) if rootURL: request.rememberRootURL(rootURL) site = NevowWSGISite(request, page) request.site = site result = request.process() if not request.headersSent: request.write('') # send headers now if isinstance(result, str): yield result elif isinstance(result, util.Deferred): ## So we can use the wsgi module if twisted is installed ## TODO use render synchronously instead maybe? I'm pretty ## sure after the application callable returns, the request ## is "closed". Investigate with the latest wsgi spec and ## some implementations. #raise 'PH' + str(dir(result)) + '{{%s}}' % str(result.result) yield result.result else: for x in result: yield x return application
def renderResource(uri, notFoundHandler=None): """Render a resource at some uri and return the response code and html. """ root = Root() if notFoundHandler is not None: root.remember(notFoundHandler, inevow.ICanHandleNotFound) site = appserver.NevowSite(root) ctx = context.SiteContext(tag=site) request = testutil.FakeRequest(uri=uri) ctx = context.RequestContext(parent=ctx, tag=request) def waitmore(newctx): return defer.maybeDeferred(newctx.tag.renderHTTP, newctx).addCallback(lambda html: (request.code, html)) return site.getPageContextForRequestContext(ctx).addCallback(waitmore)
def createWSGIApplication(page, rootURL=None): """Given a Page instance, return a WSGI callable. `rootURL` - URL to be remembered as root """ page.flattenFactory = flat.iterflatten siteCtx = context.SiteContext(tag=None) def application(environ, start_response): request = WSGIRequest(environ, start_response) prefixURL = rootURL if prefixURL is None: # Try to guess proto = request.isSecure() and 'https://' or 'http://' server = environ['SERVER_NAME'] prefixURL = proto + server + environ.get('SCRIPT_NAME', '/') request.rememberRootURL(prefixURL) site = NevowWSGISite(request, page) request.site = site result = request.process() if not request.headersSent: request.write('') # send headers now if isinstance(result, str): yield str(result) # work around wsgiref using StringType elif isinstance(result, util.Deferred): ## So we can use the wsgi module if twisted is installed ## TODO use render synchronously instead maybe? I'm pretty ## sure after the application callable returns, the request ## is "closed". Investigate with the latest wsgi spec and ## some implementations. #raise 'PH' + str(dir(result)) + '{{%s}}' % str(result.result) yield result.result else: for x in result: yield x return application
def __init__(self, resource, *args, **kwargs): resource.addSlash = True server.Site.__init__(self, resource, *args, **kwargs) self.context = context.SiteContext()
def __init__(self, *args, **kwargs): server.Site.__init__(self, *args, **kwargs) self.context = context.SiteContext()
def __init__(self, request, resource): self.request = request self.resource = resource self.context = context.SiteContext()