aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tools
diff options
context:
space:
mode:
authorxray7224 <xray7224@googlemail.com>2013-07-08 20:35:03 +0100
committerxray7224 <jessica@megworld.co.uk>2013-07-11 18:21:43 +0100
commitd41c6a5349db0ac573e8f0d29d239febc705f7c9 (patch)
treed012264c2fbc093ea4da131206e40ca38d8c0584 /mediagoblin/tools
parentbe7f90b3f537190d199989625f75d334dbca7080 (diff)
downloadmediagoblin-d41c6a5349db0ac573e8f0d29d239febc705f7c9.tar.lz
mediagoblin-d41c6a5349db0ac573e8f0d29d239febc705f7c9.tar.xz
mediagoblin-d41c6a5349db0ac573e8f0d29d239febc705f7c9.zip
Adds oauth support up until authorization
Diffstat (limited to 'mediagoblin/tools')
-rw-r--r--mediagoblin/tools/request.py17
-rw-r--r--mediagoblin/tools/response.py9
2 files changed, 26 insertions, 0 deletions
diff --git a/mediagoblin/tools/request.py b/mediagoblin/tools/request.py
index ee342eae..ed903ce0 100644
--- a/mediagoblin/tools/request.py
+++ b/mediagoblin/tools/request.py
@@ -14,12 +14,17 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import json
import logging
from mediagoblin.db.models import User
_log = logging.getLogger(__name__)
+# MIME-Types
+form_encoded = "application/x-www-form-urlencoded"
+json_encoded = "application/json"
+
def setup_user_in_request(request):
"""
Examine a request and tack on a request.user parameter if that's
@@ -36,3 +41,15 @@ def setup_user_in_request(request):
# this session.
_log.warn("Killing session for user id %r", request.session['user_id'])
request.session.delete()
+
+def decode_request(request):
+ """ Decodes a request based on MIME-Type """
+ data = request.get_data()
+
+ if request.content_type == json_encoded:
+ data = json.loads(data)
+ elif request.content_type == form_encoded:
+ data = request.form
+ else:
+ data = ""
+ return data
diff --git a/mediagoblin/tools/response.py b/mediagoblin/tools/response.py
index 1fd242fb..db8fc388 100644
--- a/mediagoblin/tools/response.py
+++ b/mediagoblin/tools/response.py
@@ -45,6 +45,15 @@ def render_error(request, status=500, title=_('Oops!'),
{'err_code': status, 'title': title, 'err_msg': err_msg}),
status=status)
+def render_400(request, err_msg=None):
+ """ Render a standard 400 page"""
+ _ = pass_to_ugettext
+ title = _("Bad Request")
+ if err_msg is None:
+ err_msg = _("The request sent to the server is invalid, please double check it")
+
+ return render_error(request, 400, title, err_msg)
+
def render_403(request):
"""Render a standard 403 page"""
_ = pass_to_ugettext