summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Saddi <allan@saddi.com>2005-12-16 17:29:00 +0000
committerAllan Saddi <allan@saddi.com>2005-12-16 17:29:00 +0000
commit577421501bc98c2f88a38afe96f2b3c375fd0a22 (patch)
tree3a7ea7019003e9d5c9b6c8046dabd4b67e702022
parentf407f73d334d7e4c4840496904d7b4ce3d737d6d (diff)
downloadflup-577421501bc98c2f88a38afe96f2b3c375fd0a22.tar.gz
Add higher-level 404 error page support.
-rw-r--r--ChangeLog5
-rw-r--r--flup/publisher.py7
-rw-r--r--flup/resolver/complex.py3
-rw-r--r--flup/resolver/function.py3
-rw-r--r--flup/resolver/importingmodule.py3
-rw-r--r--flup/resolver/module.py3
-rw-r--r--flup/resolver/nopathinfo.py3
-rw-r--r--flup/resolver/objectpath.py3
-rw-r--r--flup/resolver/resolver.py3
9 files changed, 26 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 03e3c29..b007033 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-12-16 Allan Saddi <asaddi@kalahari.flup.org>
+
+ * Add higher-level 404 error page support. Thanks to Scot Doyle
+ for suggesting and idea and providing code.
+
2005-11-28 Allan Saddi <asaddi@kalahari.flup.org>
* Fix issue with FCGI_GET_VALUES handling. Thanks to
diff --git a/flup/publisher.py b/flup/publisher.py
index 6328a50..b02724a 100644
--- a/flup/publisher.py
+++ b/flup/publisher.py
@@ -450,7 +450,12 @@ class Publisher(object):
func = self._resolver.resolve(transaction.request,
redirect=redirect)
if func is None:
- return self._error404(environ, start_response)
+ # See if there's a higher-level 404 page
+ if hasattr(self._resolver, 'error404') and \
+ self._resolver.error404 is not None:
+ func = self._resolver.error404
+ else:
+ return self._error404(environ, start_response)
try:
# Call the function.
diff --git a/flup/resolver/complex.py b/flup/resolver/complex.py
index c3016ea..cd25e9c 100644
--- a/flup/resolver/complex.py
+++ b/flup/resolver/complex.py
@@ -54,7 +54,8 @@ class ComplexResolver(Resolver):
"""
_slashRE = re.compile(r'''/{2,}''')
- def __init__(self):
+ def __init__(self, **kw):
+ super(ComplexResolver, self).__init__(**kw)
self.resolverMap = {}
def _canonicalUrl(self, url):
diff --git a/flup/resolver/function.py b/flup/resolver/function.py
index 537caa3..a759926 100644
--- a/flup/resolver/function.py
+++ b/flup/resolver/function.py
@@ -39,7 +39,8 @@ class FunctionResolver(Resolver):
Can be used as a decorator and might actually have uses when used with
the ComplexResolver.
"""
- def __init__(self, func):
+ def __init__(self, func, **kw):
+ super(FunctionResolver, self).__init__(**kw)
self._func = func
def resolve(self, request, redirect=False):
diff --git a/flup/resolver/importingmodule.py b/flup/resolver/importingmodule.py
index af0d712..19decad 100644
--- a/flup/resolver/importingmodule.py
+++ b/flup/resolver/importingmodule.py
@@ -62,7 +62,8 @@ class ImportingModuleResolver(Resolver):
default_module = None
index_page = 'index'
- def __init__(self, path, defaultModule=NoDefault, index=NoDefault):
+ def __init__(self, path, defaultModule=NoDefault, index=NoDefault, **kw):
+ super(ImportingModuleResolver, self).__init__(**kw)
self.path = path
if defaultModule is not NoDefault:
self.default_module = defaultModule
diff --git a/flup/resolver/module.py b/flup/resolver/module.py
index 1d635fb..e174b54 100644
--- a/flup/resolver/module.py
+++ b/flup/resolver/module.py
@@ -52,7 +52,8 @@ class ModuleResolver(Resolver):
"""
index_page = 'index'
- def __init__(self, module, index=NoDefault):
+ def __init__(self, module, index=NoDefault, **kw):
+ super(ModuleResolver, self).__init__(**kw)
self.module = module
if index is not NoDefault:
self.index_page = index
diff --git a/flup/resolver/nopathinfo.py b/flup/resolver/nopathinfo.py
index e0f3182..0e3c866 100644
--- a/flup/resolver/nopathinfo.py
+++ b/flup/resolver/nopathinfo.py
@@ -37,7 +37,8 @@ class NoPathInfoResolver(Resolver):
what's needed to resolve the function). Optionally allows a trailing
slash.
"""
- def __init__(self, resolver, allowTrailingSlash=False):
+ def __init__(self, resolver, allowTrailingSlash=False, **kw):
+ super(NoPathInfoResolver, self).__init__(**kw)
self._resolver = resolver
self._allowTrailingSlash = allowTrailingSlash
diff --git a/flup/resolver/objectpath.py b/flup/resolver/objectpath.py
index 9b74c3f..cd6f312 100644
--- a/flup/resolver/objectpath.py
+++ b/flup/resolver/objectpath.py
@@ -56,7 +56,7 @@ class ObjectPathResolver(Resolver):
default_page = 'default'
def __init__(self, root, index=NoDefault, default=NoDefault,
- favorIndex=True):
+ favorIndex=True, **kw):
"""
root is the root object of your URL hierarchy. In CherryPy, this
would be cpg.root.
@@ -66,6 +66,7 @@ class ObjectPathResolver(Resolver):
which method is called when the URL has a trailing slash. If
True, the index method will be called. Otherwise, the default method.
"""
+ super(ObjectPathResolver, self).__init__(**kw)
self.root = root
if index is not NoDefault:
self.index_page = index
diff --git a/flup/resolver/resolver.py b/flup/resolver/resolver.py
index 10de455..ff07f1f 100644
--- a/flup/resolver/resolver.py
+++ b/flup/resolver/resolver.py
@@ -43,6 +43,9 @@ class Resolver(object):
When resolving an InternalRedirect, redirect will be True.
"""
+ def __init__(self, error404=None):
+ self.error404 = error404
+
def resolve(self, request, redirect=False):
raise NotImplementedError, self.__class__.__name__ + '.resolve'