SVN: r25376 - trunk/quixote
Neil Schemenauer <nascheme-fVcApmY9cLvQ3/1i3zOLAti2O/[email protected]> Fri, 15 Oct 2004 16:20:35 -0400
| Newsgroups | gmane.comp.web.quixote.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: nascheme
Date: 2004-10-15 16:19:37 -0400 (Fri, 15 Oct 2004)
New Revision: 25376
Modified:
trunk/quixote/http_request.py
trunk/quixote/publish.py
trunk/quixote/util.py
Log:
Avoid accessing the 'response' attribute of the HTTPRequest
object. Remove the HTTPRequest.redirect() method.
Modified: trunk/quixote/http_request.py
===================================================================
--- trunk/quixote/http_request.py 2004-10-15 19:29:29 UTC (rev 25375)
+++ trunk/quixote/http_request.py 2004-10-15 20:19:37 UTC (rev 25376)
@@ -9,7 +9,6 @@
import re
import string
import tempfile
-import urlparse
import urllib
import rfc822
from cStringIO import StringIO
@@ -517,19 +516,7 @@
# guess_browser_version ()
- def redirect(self, location, permanent=False):
- """redirect(location : string, permanent : boolean = false)
- -> string
- Create a redirection response. If the location is relative, then it
- will automatically be made absolute. The return value is an HTML
- document indicating the new URL (useful if the client browser does
- not honor the redirect).
- """
- location = urlparse.urljoin(self.get_url(), location)
- return self.response.redirect(location, permanent)
-
-
# See RFC 2109 for details. Note that this parser is more liberal.
_COOKIE_RE = re.compile(r"""
\s*
Modified: trunk/quixote/publish.py
===================================================================
--- trunk/quixote/publish.py 2004-10-15 19:29:29 UTC (rev 25375)
+++ trunk/quixote/publish.py 2004-10-15 20:19:37 UTC (rev 25376)
@@ -10,6 +10,7 @@
import sys, os, traceback, cStringIO
import time, types, socket, re, warnings
import struct
+import urlparse
try:
import zlib # for COMPRESS_PAGES option
except ImportError:
@@ -658,8 +659,7 @@
# user to the right URL; when the client follows the redirect,
# we'll wind up here again with path == '/'.
if (not path and fix_trailing_slash):
- request.redirect(request.environ['SCRIPT_NAME'] + '/' ,
- permanent=True)
+ redirect(request.environ['SCRIPT_NAME'] + '/' , permanent=True)
return None
# replace repeated slashes with a single slash
@@ -691,7 +691,7 @@
# 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.
- request.redirect(request.get_path() + "/", permanent=True)
+ redirect(request.get_path() + "/", permanent=True)
return None
else:
@@ -861,8 +861,17 @@
return _publisher.get_request().get_path(n)
def redirect(location, permanent=False):
- return _publisher.get_request().redirect(location, permanent)
+ """(location : string, permanent : boolean = false) -> string
+ Create a redirection response. If the location is relative, then it
+ will automatically be made absolute. The return value is an HTML
+ document indicating the new URL (useful if the client browser does
+ not honor the redirect).
+ """
+ request = _publisher.get_request()
+ location = urlparse.urljoin(request.get_url(), location)
+ return request.response.redirect(location, permanent)
+
def get_session():
return _publisher.get_request().session
Modified: trunk/quixote/util.py
===================================================================
--- trunk/quixote/util.py 2004-10-15 19:29:29 UTC (rev 25375)
+++ trunk/quixote/util.py 2004-10-15 20:19:37 UTC (rev 25376)
@@ -164,26 +164,27 @@
stat = os.stat(self.path)
last_modified = formatdate(stat.st_mtime)
request = quixote.get_request()
+ response = quixote.get_response()
if last_modified == request.get_header('If-Modified-Since'):
# handle exact match of If-Modified-Since header
- request.response.set_status(304)
+ response.set_status(304)
return ''
# Set the Content-Type for the response and return the file's contents.
- request.response.set_content_type(self.mime_type)
+ response.set_content_type(self.mime_type)
if self.encoding:
- request.response.set_header("Content-Encoding", self.encoding)
+ response.set_header("Content-Encoding", self.encoding)
- request.response.set_header('Last-Modified', last_modified)
+ response.set_header('Last-Modified', last_modified)
if self.cache_time is None:
- request.response.set_expires(None) # don't set the Expires header
+ response.set_expires(None) # don't set the Expires header
else:
# explicitly allow client to cache page by setting the Expires
# header, this is even more efficient than the using
# Last-Modified/If-Modified-Since since the browser does not need
# to contact the server
- request.response.set_expires(seconds=self.cache_time)
+ response.set_expires(seconds=self.cache_time)
return FileStream(open(self.path, 'rb'), stat.st_size)