equal
deleted
inserted
replaced
3 """ |
3 """ |
4 |
4 |
5 try: |
5 try: |
6 from functools import wraps |
6 from functools import wraps |
7 except ImportError: |
7 except ImportError: |
8 from django.utils.functional import wraps # Python 2.3, 2.4 fallback. |
8 from django.utils.functional import wraps # Python 2.4 fallback. |
9 |
9 |
10 from calendar import timegm |
10 from calendar import timegm |
11 from datetime import timedelta |
11 from datetime import timedelta |
12 from email.Utils import formatdate |
12 from email.Utils import formatdate |
13 |
13 |
14 from django.utils.decorators import decorator_from_middleware |
14 from django.utils.decorators import decorator_from_middleware, available_attrs |
15 from django.utils.http import parse_etags, quote_etag |
15 from django.utils.http import parse_etags, quote_etag |
16 from django.middleware.http import ConditionalGetMiddleware |
16 from django.middleware.http import ConditionalGetMiddleware |
17 from django.http import HttpResponseNotAllowed, HttpResponseNotModified, HttpResponse |
17 from django.http import HttpResponseNotAllowed, HttpResponseNotModified, HttpResponse |
18 |
18 |
19 |
19 |
33 def decorator(func): |
33 def decorator(func): |
34 def inner(request, *args, **kwargs): |
34 def inner(request, *args, **kwargs): |
35 if request.method not in request_method_list: |
35 if request.method not in request_method_list: |
36 return HttpResponseNotAllowed(request_method_list) |
36 return HttpResponseNotAllowed(request_method_list) |
37 return func(request, *args, **kwargs) |
37 return func(request, *args, **kwargs) |
38 return wraps(func)(inner) |
38 return wraps(func, assigned=available_attrs(func))(inner) |
39 return decorator |
39 return decorator |
40 |
40 |
41 require_GET = require_http_methods(["GET"]) |
41 require_GET = require_http_methods(["GET"]) |
42 require_GET.__doc__ = "Decorator to require that a view only accept the GET method." |
42 require_GET.__doc__ = "Decorator to require that a view only accept the GET method." |
43 |
43 |