Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is not yet included in main rpclib distribution because
- # it does a lot of unnecessary copying. However, it's reportedly
- # working fine, so if you're not caring that much about performance
- # you can use this.
- from rpclib.server.wsgi import WsgiApplication
- from cStringIO import StringIO
- from django.http import HttpResponse
- class DjangoApplication(WsgiApplication):
- def __call__(self, request):
- django_response = HttpResponse()
- def start_response(status, headers):
- status, reason = status.split(' ', 1)
- django_response.status_code = int(status)
- for header, value in headers:
- django_response[header] = value
- environ = request.META.copy()
- body = ''.join(['%s=%s' % v for v in request.POST.items()])
- environ['CONTENT_LENGTH'] = len(body)
- environ['wsgi.input'] = StringIO(body)
- environ['wsgi.multithread'] = False
- response = WsgiApplication.__call__(self, environ, start_response)
- django_response.content = "\n".join(response)
- return django_response
Add Comment
Please, Sign In to add comment