summaryrefslogtreecommitdiffstats
path: root/middleware.py
diff options
context:
space:
mode:
authorWookey <wookey@wookware.org>2011-07-11 02:10:22 +0100
committerWookey <wookey@wookware.org>2011-07-11 02:10:22 +0100
commitdc1327674c2676db02ccf525725019cd9115b699 (patch)
tree8b3a151a8512576ccfb6bb6578fe124c033c46c0 /middleware.py
parentc8ff8e3ef60c6eba0071e20664268c790c6a6aa6 (diff)
downloadtroggle-dc1327674c2676db02ccf525725019cd9115b699.tar.gz
troggle-dc1327674c2676db02ccf525725019cd9115b699.tar.bz2
troggle-dc1327674c2676db02ccf525725019cd9115b699.zip
remove all the DOS linefeeds
Diffstat (limited to 'middleware.py')
-rw-r--r--middleware.py98
1 files changed, 49 insertions, 49 deletions
diff --git a/middleware.py b/middleware.py
index 40e14ed..15dd039 100644
--- a/middleware.py
+++ b/middleware.py
@@ -1,49 +1,49 @@
-from django.conf import settings
-from django import http
-from django.core.urlresolvers import resolve
-
-class SmartAppendSlashMiddleware(object):
- """
- "SmartAppendSlash" middleware for taking care of URL rewriting.
-
- This middleware appends a missing slash, if:
- * the SMART_APPEND_SLASH setting is True
- * the URL without the slash does not exist
- * the URL with an appended slash does exist.
- Otherwise it won't touch the URL.
- """
-
- def process_request(self, request):
- """
- Rewrite the URL based on settings.SMART_APPEND_SLASH
- """
-
- # Check for a redirect based on settings.SMART_APPEND_SLASH
- host = http.get_host(request)
- old_url = [host, request.path]
- new_url = old_url[:]
- # Append a slash if SMART_APPEND_SLASH is set and the resulting URL
- # resolves.
- if settings.SMART_APPEND_SLASH and (not old_url[1].endswith('/')) and not _resolves(old_url[1]) and _resolves(old_url[1] + '/'):
- new_url[1] = new_url[1] + '/'
- if settings.DEBUG and request.method == 'POST':
- raise RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have SMART_APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set SMART_APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1])
- if new_url != old_url:
- # Redirect
- if new_url[0]:
- newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], new_url[1])
- else:
- newurl = new_url[1]
- if request.GET:
- newurl += '?' + request.GET.urlencode()
- return http.HttpResponsePermanentRedirect(newurl)
-
- return None
-
-def _resolves(url):
- try:
- resolve(url)
- return True
- except http.Http404:
- return False
-
+from django.conf import settings
+from django import http
+from django.core.urlresolvers import resolve
+
+class SmartAppendSlashMiddleware(object):
+ """
+ "SmartAppendSlash" middleware for taking care of URL rewriting.
+
+ This middleware appends a missing slash, if:
+ * the SMART_APPEND_SLASH setting is True
+ * the URL without the slash does not exist
+ * the URL with an appended slash does exist.
+ Otherwise it won't touch the URL.
+ """
+
+ def process_request(self, request):
+ """
+ Rewrite the URL based on settings.SMART_APPEND_SLASH
+ """
+
+ # Check for a redirect based on settings.SMART_APPEND_SLASH
+ host = http.get_host(request)
+ old_url = [host, request.path]
+ new_url = old_url[:]
+ # Append a slash if SMART_APPEND_SLASH is set and the resulting URL
+ # resolves.
+ if settings.SMART_APPEND_SLASH and (not old_url[1].endswith('/')) and not _resolves(old_url[1]) and _resolves(old_url[1] + '/'):
+ new_url[1] = new_url[1] + '/'
+ if settings.DEBUG and request.method == 'POST':
+ raise RuntimeError, "You called this URL via POST, but the URL doesn't end in a slash and you have SMART_APPEND_SLASH set. Django can't redirect to the slash URL while maintaining POST data. Change your form to point to %s%s (note the trailing slash), or set SMART_APPEND_SLASH=False in your Django settings." % (new_url[0], new_url[1])
+ if new_url != old_url:
+ # Redirect
+ if new_url[0]:
+ newurl = "%s://%s%s" % (request.is_secure() and 'https' or 'http', new_url[0], new_url[1])
+ else:
+ newurl = new_url[1]
+ if request.GET:
+ newurl += '?' + request.GET.urlencode()
+ return http.HttpResponsePermanentRedirect(newurl)
+
+ return None
+
+def _resolves(url):
+ try:
+ resolve(url)
+ return True
+ except http.Http404:
+ return False
+