|
From: <bla...@us...> - 2007-05-22 10:37:31
|
Author: blackbird
Date: 2007-05-22 12:36:49 +0200 (Tue, 22 May 2007)
New Revision: 5080
Modified:
trunk/sandbox/py-rest-doc/sphinx/templates/layout.html
trunk/sandbox/py-rest-doc/sphinx/web/application.py
trunk/sandbox/py-rest-doc/sphinx/web/util.py
Log:
removed the outermost arrow in the navigation
Modified: trunk/sandbox/py-rest-doc/sphinx/templates/layout.html
===================================================================
--- trunk/sandbox/py-rest-doc/sphinx/templates/layout.html 2007-05-22 10:20:26 UTC (rev 5079)
+++ trunk/sandbox/py-rest-doc/sphinx/templates/layout.html 2007-05-22 10:36:49 UTC (rev 5080)
@@ -23,7 +23,8 @@
<li class="right"><a href="{{ prev.link|e }}" title="{{ prev.title|striptags }}">previous</a> |</li>
{%- endif %}
{%- for parent in parents %}
- <li><a href="{{ parent.link|e }}">{{ parent.title }}</a></li> »
+ <li><a href="{{ parent.link|e }}">{{ parent.title }}</a>{%
+ if not loop.last %} »{% endif %}</li>
{%- endfor %}
</ul>
</div>
Modified: trunk/sandbox/py-rest-doc/sphinx/web/application.py
===================================================================
--- trunk/sandbox/py-rest-doc/sphinx/web/application.py 2007-05-22 10:20:26 UTC (rev 5079)
+++ trunk/sandbox/py-rest-doc/sphinx/web/application.py 2007-05-22 10:36:49 UTC (rev 5080)
@@ -13,8 +13,8 @@
import cPickle as pickle
from os import path
from ..util import relative_uri
-from .util import Request, Response, SharedDataMiddleware, NotFound, \
- render_template
+from .util import Request, Response, RedirectResponse, SharedDataMiddleware, \
+ NotFound, render_template
special_urls = set(['index', 'genindex', 'modindex', 'search'])
@@ -76,11 +76,14 @@
def __call__(self, environ, start_response):
req = Request(environ)
- url = req.path.strip('/') or 'index'
- try:
- resp = self.get_page(req, url)
- except NotFound:
- resp = self.get_close_matches(req, url)
+ if not req.path.endswith('/'):
+ resp = RedirectResponse(req.path + '/')
+ else:
+ url = req.path.strip('/') or 'index'
+ try:
+ resp = self.get_page(req, url)
+ except NotFound:
+ resp = self.get_close_matches(req, url)
return resp(environ, start_response)
Modified: trunk/sandbox/py-rest-doc/sphinx/web/util.py
===================================================================
--- trunk/sandbox/py-rest-doc/sphinx/web/util.py 2007-05-22 10:20:26 UTC (rev 5079)
+++ trunk/sandbox/py-rest-doc/sphinx/web/util.py 2007-05-22 10:36:49 UTC (rev 5080)
@@ -12,6 +12,7 @@
from __future__ import with_statement
import cgi
import tempfile
+import urllib
from os import path
from time import gmtime
from Cookie import SimpleCookie
@@ -577,6 +578,31 @@
yield str(item)
+class RedirectResponse(Response):
+
+ def __init__(self, target_url, code=302):
+ if not target_url.startswith('/'):
+ target_url = '/' + target_url
+ self.target_url = target_url
+ super(RedirectResponse, self).__init__('Moved...', status=code)
+
+ def __call__(self, environ, start_response):
+ url = environ['wsgi.url_scheme'] + '://'
+ if 'HTTP_HOST' in environ:
+ url += environ['HTTP_HOST']
+ else:
+ url += environ['SERVER_NAME']
+ if (environ['wsgi.url_scheme'], environ['SERVER_PORT']) not \
+ in (('https', '443'), ('http', '80')):
+ url += ':' + environ['SERVER_PORT']
+
+ url += urllib.quote(environ.get('SCRIPT_INFO', '').rstrip('/'))
+ url += self.target_url
+
+ self.headers['Location'] = url
+ return super(RedirectResponse, self).__call__(environ, start_response)
+
+
class SharedDataMiddleware(object):
"""
Redirects calls to an folder with static data.
|