--- a/etwist/server.py Wed Apr 22 16:50:46 2009 +0200
+++ b/etwist/server.py Wed Apr 22 16:51:29 2009 +0200
@@ -18,7 +18,7 @@
from twisted.web2 import static, resource, responsecode
from cubicweb import ObjectNotFound
-from cubicweb.web import (AuthenticationError, NotFound, Redirect,
+from cubicweb.web import (AuthenticationError, NotFound, Redirect,
RemoteCallFailed, DirectResponse, StatusResponse,
ExplicitLogin)
from cubicweb.web.application import CubicWebPublisher
@@ -42,7 +42,7 @@
start_task(interval, catch_error_func)
# ensure no tasks will be further added
repo._looping_tasks = ()
-
+
class LongTimeExpiringFile(static.File):
"""overrides static.File and sets a far futre ``Expires`` date
@@ -71,7 +71,7 @@
class CubicWebRootResource(resource.PostableResource):
addSlash = False
-
+
def __init__(self, config, debug=None):
self.appli = CubicWebPublisher(config, debug=debug)
self.debugmode = debug
@@ -103,7 +103,7 @@
interval = min(config['cleanup-session-time'] or 120,
config['cleanup-anonymous-session-time'] or 720) / 2.
start_task(interval, self.appli.session_handler.clean_sessions)
-
+
def shutdown_event(self):
"""callback fired when the server is shutting down to properly
clean opened sessions
@@ -116,7 +116,7 @@
self.pyro_daemon.handleRequests(self.pyro_listen_timeout)
except select.error:
return
-
+
def locateChild(self, request, segments):
"""Indicate which resource to use to process down the URL's path"""
if segments:
@@ -143,7 +143,7 @@
return static.File(fckeditordir), segments[1:]
# Otherwise we use this single resource
return self, ()
-
+
def render(self, request):
"""Render a page from the root resource"""
# reload modified files (only in development or debug mode)
@@ -153,7 +153,7 @@
return self.render_request(request)
else:
return threads.deferToThread(self.render_request, request)
-
+
def render_request(self, request):
origpath = request.path
host = request.host
@@ -163,7 +163,7 @@
origpath = origpath[6:]
request.uri = request.uri[6:]
https = True
- baseurl = self.https_url or self.base_url
+ baseurl = self.https_url or self.base_url
else:
https = False
baseurl = self.base_url
@@ -180,7 +180,7 @@
return self.redirect(req, ex.location)
if https and req.cnx.anonymous_connection:
# don't allow anonymous on https connection
- return self.request_auth(req)
+ return self.request_auth(req)
if self.url_rewriter is not None:
# XXX should occur before authentication?
try:
@@ -226,11 +226,6 @@
return self.request_auth(req, loggedout=True)
except Redirect, ex:
return self.redirect(req, ex.location)
- if not result:
- # no result, something went wrong...
- self.error('no data (%s)', req)
- # 500 Internal server error
- return self.redirect(req, req.build_url('error'))
# request may be referenced by "onetime callback", so clear its entity
# cache to avoid memory usage
req.drop_entity_cache()
@@ -242,11 +237,11 @@
self.debug('redirecting to %s', location)
# 303 See other
return http.Response(code=303, headers=req.headers_out)
-
+
def request_auth(self, req, loggedout=False):
if self.https_url and req.base_url() != self.https_url:
req.headers_out.setHeader('location', self.https_url + 'login')
- return http.Response(code=303, headers=req.headers_out)
+ return http.Response(code=303, headers=req.headers_out)
if self.config['auth-mode'] == 'http':
code = responsecode.UNAUTHORIZED
else:
@@ -260,7 +255,7 @@
content = self.appli.need_login_content(req)
return http.Response(code, req.headers_out, content)
-
+
# This part gets run when you run this file via: "twistd -noy demo.py"
def main(appid, cfgname):
"""Starts an cubicweb twisted server for an application
@@ -295,12 +290,12 @@
# XXX set max file size to 100Mo: put max upload size in the configuration
# line below for twisted >= 8.0, default param value for earlier version
-resource.PostableResource.maxSize = 100*1024*1024
+resource.PostableResource.maxSize = 100*1024*1024
def parsePOSTData(request, maxMem=100*1024, maxFields=1024,
maxSize=100*1024*1024):
if request.stream.length == 0:
return defer.succeed(None)
-
+
ctype = request.headers.getHeader('content-type')
if ctype is None:
@@ -318,7 +313,7 @@
def error(f):
f.trap(fileupload.MimeFormatError)
raise http.HTTPError(responsecode.BAD_REQUEST)
-
+
if ctype.mediaType == 'application' and ctype.mediaSubtype == 'x-www-form-urlencoded':
d = fileupload.parse_urlencoded(request.stream, keep_blank_values=True)
d.addCallbacks(updateArgs, error)