Guest User

Untitled

a guest
Jan 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # This is not yet included in main rpclib distribution because
  2. # it does a lot of unnecessary copying. However, it's reportedly
  3. # working fine, so if you're not caring that much about performance
  4. # you can use this.
  5.  
  6.  
  7. from rpclib.server.wsgi import WsgiApplication
  8. from cStringIO import StringIO
  9. from django.http import HttpResponse
  10.  
  11. class DjangoApplication(WsgiApplication):
  12. def __call__(self, request):
  13. django_response = HttpResponse()
  14.  
  15. def start_response(status, headers):
  16. status, reason = status.split(' ', 1)
  17.  
  18. django_response.status_code = int(status)
  19. for header, value in headers:
  20. django_response[header] = value
  21.  
  22. environ = request.META.copy()
  23. body = ''.join(['%s=%s' % v for v in request.POST.items()])
  24. environ['CONTENT_LENGTH'] = len(body)
  25. environ['wsgi.input'] = StringIO(body)
  26. environ['wsgi.multithread'] = False
  27.  
  28. response = WsgiApplication.__call__(self, environ, start_response)
  29.  
  30. django_response.content = "\n".join(response)
  31.  
  32. return django_response
Add Comment
Please, Sign In to add comment