allura
修訂 | 1c5e1064d1e582647f5dab23a5e5a7f3b3eef1c7 (tree) |
---|---|
時間 | 2011-04-30 02:08:36 |
作者 | Rick Copeland <rcopeland@geek...> |
Commiter | Rick Copeland |
[#1831] update with[out]_trailing_slash to give HTTPMovedPermanently rather than HTTPFound
Signed-off-by: Rick Copeland <rcopeland@geek.net>
@@ -3,6 +3,7 @@ from formencode import schema | ||
3 | 3 | import ew.render |
4 | 4 | |
5 | 5 | from .tg_globals import c, request, response |
6 | +from .util import moved | |
6 | 7 | |
7 | 8 | class _tg_deco(object): |
8 | 9 | def __init__(self, *args, **kwargs): |
@@ -21,20 +22,18 @@ def override_template(func, template): | ||
21 | 22 | c.override_template = template |
22 | 23 | |
23 | 24 | def without_trailing_slash(func): |
24 | - from tg import redirect | |
25 | 25 | def _check_path(params): |
26 | 26 | if request.method != 'GET': return |
27 | 27 | if request.path.endswith('/'): |
28 | - redirect(request.url.replace(request.path, request.path[:-1], 1)) | |
28 | + moved(request.url.replace(request.path, request.path[:-1], 1)) | |
29 | 29 | before_validate(_check_path)(func) |
30 | 30 | return func |
31 | 31 | |
32 | 32 | def with_trailing_slash(func): |
33 | - from tg import redirect | |
34 | 33 | def _check_path(params): |
35 | 34 | if request.method != 'GET': return |
36 | 35 | if not request.path.endswith('/'): |
37 | - redirect(request.url.replace(request.path, request.path + '/', 1)) | |
36 | + moved(request.url.replace(request.path, request.path + '/', 1)) | |
38 | 37 | before_validate(_check_path)(func) |
39 | 38 | return func |
40 | 39 |
@@ -43,6 +43,10 @@ def redirect(*args, **kwargs): | ||
43 | 43 | found = exc.HTTPFound(location=url(*args, **kwargs)) |
44 | 44 | raise found.exception |
45 | 45 | |
46 | +def moved(*args, **kwargs): | |
47 | + moved = exc.HTTPMovedPermanently(location=url(*args, **kwargs)) | |
48 | + raise moved.exception | |
49 | + | |
46 | 50 | def smart_str(s, encoding='utf-8', strings_only=False, errors='strict'): |
47 | 51 | """ |
48 | 52 | Returns a bytestring version of 's', encoded as specified in 'encoding'. |