8
8
import warnings
9
9
from pydoc import locate
10
10
11
- import django
12
11
from decorator import decorator
13
12
from django import get_version as django_version
14
13
from django .http import HttpResponse
@@ -27,20 +26,20 @@ class rc_factory:
27
26
"""
28
27
29
28
CODES = dict (
30
- ALL_OK = ("OK" , 200 ),
31
- CREATED = ("Created" , 201 ),
32
- ACCEPTED = ("Accepted" , 202 ),
33
- DELETED = ("" , 204 ), # 204 says "Don't send a body!"
34
- BAD_REQUEST = ("Bad Request" , 400 ),
35
- UNAUTHORIZED = ("Unauthorized" , 401 ),
36
- FORBIDDEN = ("Forbidden" , 403 ),
37
- NOT_FOUND = ("Not Found" , 404 ),
38
- NOT_ACCEPTABLE = ("Not Acceptable" , 406 ),
39
- DUPLICATE_ENTRY = ("Conflict/Duplicate" , 409 ),
40
- NOT_HERE = ("Gone" , 410 ),
41
- INTERNAL_ERROR = ("Internal Error" , 500 ),
42
- NOT_IMPLEMENTED = ("Not Implemented" , 501 ),
43
- THROTTLED = ("Throttled" , 503 ),
29
+ ALL_OK = (b "OK" , 200 ),
30
+ CREATED = (b "Created" , 201 ),
31
+ ACCEPTED = (b "Accepted" , 202 ),
32
+ DELETED = (b "" , 204 ), # 204 says "Don't send a body!"
33
+ BAD_REQUEST = (b "Bad Request" , 400 ),
34
+ UNAUTHORIZED = (b "Unauthorized" , 401 ),
35
+ FORBIDDEN = (b "Forbidden" , 403 ),
36
+ NOT_FOUND = (b "Not Found" , 404 ),
37
+ NOT_ACCEPTABLE = (b "Not Acceptable" , 406 ),
38
+ DUPLICATE_ENTRY = (b "Conflict/Duplicate" , 409 ),
39
+ NOT_HERE = (b "Gone" , 410 ),
40
+ INTERNAL_ERROR = (b "Internal Error" , 500 ),
41
+ NOT_IMPLEMENTED = (b "Not Implemented" , 501 ),
42
+ THROTTLED = (b "Throttled" , 503 ),
44
43
)
45
44
46
45
def __getattr__ (self , attr ):
@@ -64,43 +63,7 @@ def __getattr__(self, attr):
64
63
DeprecationWarning ,
65
64
)
66
65
67
- class HttpResponseWrapper (HttpResponse ):
68
- """
69
- Wrap HttpResponse and make sure that the internal _is_string
70
- flag is updated when the _set_content method (via the content
71
- property) is called
72
- """
73
-
74
- def _set_content (self , content ):
75
- """
76
- Set the _container and _is_string /
77
- _base_content_is_iter properties based on the type of
78
- the value parameter. This logic is in the construtor
79
- for HttpResponse, but doesn't get repeated when
80
- setting HttpResponse.content although this bug report
81
- (feature request) suggests that it should:
82
- http://code.djangoproject.com/ticket/9403
83
- """
84
- is_string = False
85
- if not isinstance (content , str ) and hasattr (content , "__iter__" ):
86
- self ._container = content
87
- else :
88
- self ._container = [content ]
89
- is_string = True
90
- if django .VERSION >= (1 , 4 ):
91
- self ._base_content_is_iter = not is_string
92
- else : # pragma: nocover
93
- self ._is_string = is_string
94
-
95
- try :
96
- content = property (HttpResponse ._get_content , _set_content )
97
- except Exception :
98
-
99
- @HttpResponse .content .setter
100
- def content (self , content ):
101
- self ._set_content (content )
102
-
103
- return HttpResponseWrapper (r , content_type = "text/plain" , status = c )
66
+ return HttpResponse (r , content_type = "text/plain" , status = c )
104
67
105
68
106
69
rc = rc_factory ()
0 commit comments