File: middleware.py

package info (click to toggle)
python-django 1.8.18-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 41,628 kB
  • sloc: python: 189,488; xml: 695; makefile: 194; sh: 169; sql: 11
file content (38 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from django.core.urlresolvers import reverse
from django.http import HttpResponse, StreamingHttpResponse

from . import urlconf_inner


class ChangeURLconfMiddleware(object):
    def process_request(self, request):
        request.urlconf = urlconf_inner.__name__


class NullChangeURLconfMiddleware(object):
    def process_request(self, request):
        request.urlconf = None


class ReverseInnerInResponseMiddleware(object):
    def process_response(self, *args, **kwargs):
        return HttpResponse(reverse('inner'))


class ReverseOuterInResponseMiddleware(object):
    def process_response(self, *args, **kwargs):
        return HttpResponse(reverse('outer'))


class ReverseInnerInStreaming(object):
    def process_view(self, *args, **kwargs):
        def stream():
            yield reverse('inner')
        return StreamingHttpResponse(stream())


class ReverseOuterInStreaming(object):
    def process_view(self, *args, **kwargs):
        def stream():
            yield reverse('outer')
        return StreamingHttpResponse(stream())