@@ -78,19 +78,6 @@ def wrap_attributeerrors():
78
78
raise exc .with_traceback (info [2 ])
79
79
80
80
81
- def safe_property (func ):
82
- """
83
- Property decorator to ensure AttributeErrors raised in properties aren't lost
84
- """
85
-
86
- @property
87
- def new_func (self ):
88
- with wrap_attributeerrors ():
89
- return func (self )
90
-
91
- return new_func
92
-
93
-
94
81
class Empty :
95
82
"""
96
83
Placeholder for unset attributes.
@@ -206,12 +193,12 @@ def __class_getitem__(cls, *args, **kwargs):
206
193
def _default_negotiator (self ):
207
194
return api_settings .DEFAULT_CONTENT_NEGOTIATION_CLASS ()
208
195
209
- @safe_property
196
+ @property
210
197
def content_type (self ):
211
198
meta = self ._request .META
212
199
return meta .get ('CONTENT_TYPE' , meta .get ('HTTP_CONTENT_TYPE' , '' ))
213
200
214
- @safe_property
201
+ @property
215
202
def stream (self ):
216
203
"""
217
204
Returns an object that may be used to stream the request content.
@@ -220,27 +207,29 @@ def stream(self):
220
207
self ._load_stream ()
221
208
return self ._stream
222
209
223
- @safe_property
210
+ @property
224
211
def query_params (self ):
225
212
"""
226
213
More semantically correct name for request.GET.
227
214
"""
228
215
return self ._request .GET
229
216
230
- @safe_property
217
+ @property
231
218
def data (self ):
232
219
if not _hasattr (self , '_full_data' ):
233
- self ._load_data_and_files ()
220
+ with wrap_attributeerrors ():
221
+ self ._load_data_and_files ()
234
222
return self ._full_data
235
223
236
- @safe_property
224
+ @property
237
225
def user (self ):
238
226
"""
239
227
Returns the user associated with the current request, as authenticated
240
228
by the authentication classes provided to the request.
241
229
"""
242
230
if not hasattr (self , '_user' ):
243
- self ._authenticate ()
231
+ with wrap_attributeerrors ():
232
+ self ._authenticate ()
244
233
return self ._user
245
234
246
235
@user .setter
@@ -256,14 +245,15 @@ def user(self, value):
256
245
self ._user = value
257
246
self ._request .user = value
258
247
259
- @safe_property
248
+ @property
260
249
def auth (self ):
261
250
"""
262
251
Returns any non-user authentication information associated with the
263
252
request, such as an authentication token.
264
253
"""
265
254
if not hasattr (self , '_auth' ):
266
- self ._authenticate ()
255
+ with wrap_attributeerrors ():
256
+ self ._authenticate ()
267
257
return self ._auth
268
258
269
259
@auth .setter
@@ -275,14 +265,15 @@ def auth(self, value):
275
265
self ._auth = value
276
266
self ._request .auth = value
277
267
278
- @safe_property
268
+ @property
279
269
def successful_authenticator (self ):
280
270
"""
281
271
Return the instance of the authentication instance class that was used
282
272
to authenticate the request, or `None`.
283
273
"""
284
274
if not hasattr (self , '_authenticator' ):
285
- self ._authenticate ()
275
+ with wrap_attributeerrors ():
276
+ self ._authenticate ()
286
277
return self ._authenticator
287
278
288
279
def _load_data_and_files (self ):
@@ -432,22 +423,24 @@ def __getattr__(self, attr):
432
423
except AttributeError :
433
424
raise AttributeError (f"'{ self .__class__ .__name__ } ' object has no attribute '{ attr } '" )
434
425
435
- @safe_property
426
+ @property
436
427
def POST (self ):
437
428
# Ensure that request.POST uses our request parsing.
438
429
if not _hasattr (self , '_data' ):
439
- self ._load_data_and_files ()
430
+ with wrap_attributeerrors ():
431
+ self ._load_data_and_files ()
440
432
if is_form_media_type (self .content_type ):
441
433
return self ._data
442
434
return QueryDict ('' , encoding = self ._request ._encoding )
443
435
444
- @safe_property
436
+ @property
445
437
def FILES (self ):
446
438
# Leave this one alone for backwards compat with Django's request.FILES
447
439
# Different from the other two cases, which are not valid property
448
440
# names on the WSGIRequest class.
449
441
if not _hasattr (self , '_files' ):
450
- self ._load_data_and_files ()
442
+ with wrap_attributeerrors ():
443
+ self ._load_data_and_files ()
451
444
return self ._files
452
445
453
446
def force_plaintext_errors (self , value ):
0 commit comments