Wrapper allowing to enhance a standard `HttpRequest` instance. Kwargs: - request(HttpRequest). The original request instance. - parsers(list/tuple). The parsers to use for parsing the request content. - authenticators(list/tuple). The authenticators used t
| 138 | |
| 139 | |
| 140 | class Request: |
| 141 | """ |
| 142 | Wrapper allowing to enhance a standard `HttpRequest` instance. |
| 143 | |
| 144 | Kwargs: |
| 145 | - request(HttpRequest). The original request instance. |
| 146 | - parsers(list/tuple). The parsers to use for parsing the |
| 147 | request content. |
| 148 | - authenticators(list/tuple). The authenticators used to try |
| 149 | authenticating the request's user. |
| 150 | """ |
| 151 | |
| 152 | def __init__(self, request, parsers=None, authenticators=None, |
| 153 | negotiator=None, parser_context=None): |
| 154 | assert isinstance(request, HttpRequest), ( |
| 155 | 'The `request` argument must be an instance of ' |
| 156 | '`django.http.HttpRequest`, not `{}.{}`.' |
| 157 | .format(request.__class__.__module__, request.__class__.__name__) |
| 158 | ) |
| 159 | |
| 160 | self._request = request |
| 161 | self.parsers = parsers or () |
| 162 | self.authenticators = authenticators or () |
| 163 | self.negotiator = negotiator or self._default_negotiator() |
| 164 | self.parser_context = parser_context |
| 165 | self._data = Empty |
| 166 | self._files = Empty |
| 167 | self._full_data = Empty |
| 168 | self._content_type = Empty |
| 169 | self._stream = Empty |
| 170 | |
| 171 | if self.parser_context is None: |
| 172 | self.parser_context = {} |
| 173 | self.parser_context['request'] = self |
| 174 | self.parser_context['encoding'] = request.encoding or settings.DEFAULT_CHARSET |
| 175 | |
| 176 | force_user = getattr(request, '_force_auth_user', None) |
| 177 | force_token = getattr(request, '_force_auth_token', None) |
| 178 | if force_user is not None or force_token is not None: |
| 179 | forced_auth = ForcedAuthentication(force_user, force_token) |
| 180 | self.authenticators = (forced_auth,) |
| 181 | |
| 182 | def __repr__(self): |
| 183 | return '<%s.%s: %s %r>' % ( |
| 184 | self.__class__.__module__, |
| 185 | self.__class__.__name__, |
| 186 | self.method, |
| 187 | self.get_full_path()) |
| 188 | |
| 189 | # Allow generic typing checking for requests. |
| 190 | def __class_getitem__(cls, *args, **kwargs): |
| 191 | return cls |
| 192 | |
| 193 | def _default_negotiator(self): |
| 194 | return api_settings.DEFAULT_CONTENT_NEGOTIATION_CLASS() |
| 195 | |
| 196 | @property |
| 197 | def content_type(self): |
no outgoing calls