1 2 3 4 5 6 7 8 9 10 11 | import new
def accepts( self, mime ):
return mime in self.accepted_types
class AcceptMiddleware(object):
def process_request(self, request):
acc = [a.split(';')[0] for a in request.META['HTTP_ACCEPT'].split(',')]
setattr(request, 'accepted_types', acc )
request.accepts = new.instancemethod(accepts, request, request.__class__)
return None
|
More like this
- Other approach of making middleware (by decorators) by diverman 11 months ago
- Improved Accept header middleware by ludvig.ericson 3 years, 4 months ago
- XhtmlDegraderMiddleware by dmh 4 years, 6 months ago
- Improved Accept middleware with webkit workaround by raven_nevermore 1 year, 2 months ago
- AjaxCheckMiddleware by kylefox 4 years ago
Comments
I'd say the new.instancemethod trickery is indeed uncalled for:
Not to mention the list comprehension. :-)
#