Fixed wrong function, now wrapping content_type

master
seba 13 years ago
parent 2d11431e63
commit 16a0686b03

@ -88,11 +88,12 @@ def requirePlugin(apiFunc):
def fix_mime(mime_func):
""" Fix mimetype by truncating everything behind a ';'.
This is used to fix pistons ``piston.utils.Mimer.loader_for_type``."""
This is used to fix pistons ``piston.utils.Mimer.content_type``."""
@wraps(mime_func)
def wrapper(self, ctype):
def wrapper(self):
ctype = self.request.META.get('CONTENT_TYPE', None)
if ctype and ctype.find(";") >= 0:
ctype = ctype.split(";")[0]
return mime_func(self, ctype)
ctype = self.request.META['CONTENT_TYPE'] = ctype.split(";")[0]
return mime_func(self)
return wrapper

@ -6,17 +6,17 @@ from api2.handlers import *
from api2.decorators import fix_mime
import piston.utils
# piston does not understand mimetypes with charsets, HACK: fix loader_for_type
piston.utils.Mimer.loader_for_type = fix_mime(piston.utils.Mimer.loader_for_type)
# piston does not understand mimetypes with charsets, HACK: fix content_type
piston.utils.Mimer.content_type = fix_mime(piston.utils.Mimer.content_type)
class CsrfExemptResource( Resource ):
class CsrfExemptResource(Resource):
""" Except a :class:`Resource` from djangos CSRF-Framework.
This idea is taken from
http://www.robertshady.com/content/creating-very-basic-api-using-python-django-and-piston
"""
def __init__( self, handler, authentication = None ):
def __init__(self, handler, authentication = None):
super( CsrfExemptResource, self ).__init__( handler, authentication )
self.csrf_exempt = getattr( self.handler, 'csrf_exempt', True )

Loading…
Cancel
Save