SVN: r25580 - in trunk: dulcinea/bin quixote
David Binger <dbinger-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Thu, 11 Nov 2004 16:17:05 -0500
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: dbinger
Date: 2004-11-11 16:12:22 -0500 (Thu, 11 Nov 2004)
New Revision: 25580
Modified:
trunk/quixote/config.py
trunk/quixote/directory.py
trunk/quixote/errors.py
trunk/quixote/publish.py
Log:
Move missing trailing slash detection and action to Directory.__call__().
Remove fix_trailing_slash configuration option.
Raise PublishError if PATH_INFO doesn't start with '/'.
Modified: trunk/quixote/config.py
===================================================================
--- trunk/quixote/config.py 2004-11-11 20:56:32 UTC (rev 25579)
+++ trunk/quixote/config.py 2004-11-11 21:12:22 UTC (rev 25580)
@@ -55,14 +55,6 @@
# as a FastCGI script.
RUN_ONCE = False
-# Automatically redirect paths referencing non-callable objects to a
-# path with a trailing slash. This should be disabled for development
-# sites. Internal links on the site should not require redirects. They
-# are costly, especially on high latency links like dialup lines. For
-# the convenience of users, you probably want to set this to True on
-# public sites.
-FIX_TRAILING_SLASH = False
-
# Compress large pages using gzip if the client accepts that encoding.
COMPRESS_PAGES = False
@@ -142,7 +134,6 @@
'secure_errors',
'error_log',
'run_once',
- 'fix_trailing_slash',
'compress_pages',
'form_tokens',
'session_cookie_domain',
Modified: trunk/quixote/directory.py
===================================================================
--- trunk/quixote/directory.py 2004-11-11 20:56:32 UTC (rev 25579)
+++ trunk/quixote/directory.py 2004-11-11 21:12:22 UTC (rev 25580)
@@ -3,7 +3,8 @@
Logic for traversing directory objects and generating output.
"""
-from quixote.errors import TraversalError, TrailingSlashError
+import quixote
+from quixote.errors import TraversalError
class Directory(object):
"""
@@ -64,15 +65,19 @@
if not isinstance(obj, Directory):
raise TraversalError('%r is not a Directory instance' % obj)
return obj._q_traverse(path)
+ elif callable(obj):
+ return obj()
else:
- if callable(obj):
- return obj()
- elif isinstance(obj, Directory) and obj._q_translate(''):
- raise TrailingSlashError(
- '%r is not callable (missing trailing slash?)' % obj)
- else:
- return obj
+ return obj
+ def __call__(self):
+ if "" in self._q_exports and not quixote.get_request().form:
+ # Fix missing trailing slash.
+ path = quixote.get_path()
+ print "Adding slash to: %r " % path
+ return quixote.redirect(path + "/", permanent=True)
+ else:
+ raise TraversalError
class AccessControlled(object):
"""
Modified: trunk/quixote/errors.py
===================================================================
--- trunk/quixote/errors.py 2004-11-11 20:56:32 UTC (rev 25579)
+++ trunk/quixote/errors.py 2004-11-11 21:12:22 UTC (rev 25580)
@@ -84,11 +84,6 @@
msg = msg + ": " + self.private_msg
return msg
-class TrailingSlashError (TraversalError):
- """A TraversalError that most likely could be avoided by appending a
- slash to the path.
- """
-
class RequestError(PublishError):
"""
Raised when Quixote is unable to parse an HTTP request (or its CGI
Modified: trunk/quixote/publish.py
===================================================================
--- trunk/quixote/publish.py 2004-11-11 20:56:32 UTC (rev 25579)
+++ trunk/quixote/publish.py 2004-11-11 21:12:22 UTC (rev 25580)
@@ -10,8 +10,7 @@
import cgitb
from quixote.directory import Directory
-from quixote.errors import PublishError, TrailingSlashError, \
- format_publish_error
+from quixote.errors import PublishError, format_publish_error
from quixote import util
from quixote.config import Config
from quixote.http_response import HTTPResponse
@@ -247,7 +246,7 @@
self.start_request()
path = request.get_environ('PATH_INFO', '')
if path[:1] != '/':
- raise TrailingSlashError("PATH_INFO does not start with /")
+ raise PublisherError("PATH_INFO should start with '/'")
# split path into components
if '//' in path:
path = self._SLASH_PAT.sub("/", path)
@@ -276,17 +275,8 @@
self.parse_request(request)
output = self.try_publish(request)
except PublishError, exc:
- if (self.config.fix_trailing_slash and
- isinstance(exc, TrailingSlashError) and
- not request.form):
- # This is for the convenience of users who type in paths.
- # Repair the path and redirect. This should not happen for
- # URLs within the site.
- redirect(request.get_path() + "/", permanent=True)
- output = None
- else:
- # Exit the publishing loop and return a result right away.
- output = self.finish_interrupted_request(exc)
+ # Exit the publishing loop and return a result right away.
+ output = self.finish_interrupted_request(exc)
except:
# Some other exception, generate error messages to the logs, etc.
output = self.finish_failed_request()