Transition webob.HttpForbidden to webob's exceptions Forbidden

Also the BadRequest exception.
This commit is contained in:
Sebastian Spaeth
2012-11-15 16:55:15 +01:00
parent 059eaee4df
commit 62d14bf50b
4 changed files with 19 additions and 14 deletions

View File

@@ -18,8 +18,9 @@ import logging
import json
from functools import wraps
from webob import exc, Response
from webob import Response
from urlparse import urljoin
from werkzeug.exceptions import Forbidden
from mediagoblin import mg_globals
from mediagoblin.tools.pluginapi import PluginManager
@@ -143,7 +144,7 @@ def api_auth(controller):
# If we can't find any authentication methods, we should not let them
# pass.
if not auth_candidates:
return exc.HTTPForbidden()
return Forbidden()
# For now, just select the first one in the list
auth = auth_candidates[0]
@@ -157,7 +158,7 @@ def api_auth(controller):
'status': 403,
'errors': auth.errors})
return exc.HTTPForbidden()
return Forbidden()
return controller(request, *args, **kw)

View File

@@ -19,7 +19,8 @@ import logging
import uuid
from os.path import splitext
from webob import exc, Response
from webob import Response
from werkzeug.exceptions import BadRequest, Forbidden
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from celery import registry
@@ -47,13 +48,13 @@ def post_entry(request):
if request.method != 'POST':
_log.debug('Must POST against post_entry')
return exc.HTTPBadRequest()
return BadRequest()
if not 'file' in request.files \
or not isinstance(request.files['file'], FileStorage) \
or not request.files['file'].stream:
_log.debug('File field not found')
return exc.HTTPBadRequest()
return BadRequest()
media_file = request.files['file']
@@ -129,7 +130,7 @@ def post_entry(request):
@api_auth
def api_test(request):
if not request.user:
return exc.HTTPForbidden()
return Forbidden()
user_data = {
'username': request.user.username,