summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSantiago Gala <sgala@apache.org>2010-03-04 13:47:15 +0100
committerMarcel Hellkamp <marc@gsites.de>2010-03-11 22:24:46 +0100
commit2d0f2d8034a4e12263233fdb9ac83be41b6f2b47 (patch)
treecf52fc666b83756f9b636b3872415d872b6fcd2d
parent7904ea9ac76fe4dbc0aac44eedc6505700372320 (diff)
downloadbottle-2d0f2d8034a4e12263233fdb9ac83be41b6f2b47.tar.gz
Bug: when using @view, returning an error response results in exception
The @view wrapper expects a dictionary of vars. It tries to update the defaults with the returned values, and this fails for errors. The bottle.py patch checks and only updates and calls the template if the result is a dict. The app.py patch raises errors instead of using return, and so escapes the view processing. Missing: test cases
-rwxr-xr-xbottle.py9
-rwxr-xr-xhomepage/app.py2
2 files changed, 7 insertions, 4 deletions
diff --git a/bottle.py b/bottle.py
index 173509c..4110a44 100755
--- a/bottle.py
+++ b/bottle.py
@@ -1581,9 +1581,12 @@ def view(tpl_name, **defaults):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
- tplvars = dict(defaults)
- tplvars.update(func(*args, **kwargs))
- return template(tpl_name, **tplvars)
+ result = func(*args, **kwargs)
+ if isinstance(result, dict):
+ tplvars = defaults.copy()
+ tplvars.update(result)
+ return template(tpl_name, **tplvars)
+ return result
return wrapper
return decorator
diff --git a/homepage/app.py b/homepage/app.py
index 434b303..e5fd23c 100755
--- a/homepage/app.py
+++ b/homepage/app.py
@@ -112,7 +112,7 @@ def page(name='start'):
if p.exists:
return dict(page=p)
else:
- return bottle.HTTPError(404, 'Page not found')
+ raise bottle.HTTPError(404, 'Page not found') # raise to escape the view...
@route('/rss.xml')