@@ -349,39 +349,43 @@ def safe_repr(value):
349
349
350
350
351
351
def object_to_json (obj , remaining_depth = 4 , memo = None ):
352
- if memo is None :
353
- memo = Memo ()
354
- if memo .memoize (obj ):
355
- return CYCLE_MARKER
352
+ with capture_internal_exceptions ():
353
+ if memo is None :
354
+ memo = Memo ()
355
+ if memo .memoize (obj ):
356
+ return CYCLE_MARKER
356
357
357
- try :
358
- if remaining_depth > 0 :
359
- hints = {"memo" : memo , "remaining_depth" : remaining_depth }
360
- for processor in global_repr_processors :
361
- with capture_internal_exceptions ():
362
- result = processor (obj , hints )
363
- if result is not NotImplemented :
364
- return result
365
-
366
- if isinstance (obj , (list , tuple )):
367
- # It is not safe to iterate over another sequence types as this may raise errors or
368
- # bring undesired side-effects (e.g. Django querysets are executed during iteration)
369
- return [
370
- object_to_json (x , remaining_depth = remaining_depth - 1 , memo = memo )
371
- for x in obj
372
- ]
373
-
374
- if isinstance (obj , Mapping ):
375
- return {
376
- safe_str (k ): object_to_json (
377
- v , remaining_depth = remaining_depth - 1 , memo = memo
378
- )
379
- for k , v in list (obj .items ())
380
- }
381
-
382
- return safe_repr (obj )
383
- finally :
384
- memo .unmemoize (obj )
358
+ try :
359
+ if remaining_depth > 0 :
360
+ hints = {"memo" : memo , "remaining_depth" : remaining_depth }
361
+ for processor in global_repr_processors :
362
+ with capture_internal_exceptions ():
363
+ result = processor (obj , hints )
364
+ if result is not NotImplemented :
365
+ return result
366
+
367
+ if isinstance (obj , (list , tuple )):
368
+ # It is not safe to iterate over another sequence types as this may raise errors or
369
+ # bring undesired side-effects (e.g. Django querysets are executed during iteration)
370
+ return [
371
+ object_to_json (
372
+ x , remaining_depth = remaining_depth - 1 , memo = memo
373
+ )
374
+ for x in obj
375
+ ]
376
+
377
+ if isinstance (obj , Mapping ):
378
+ return {
379
+ safe_str (k ): object_to_json (
380
+ v , remaining_depth = remaining_depth - 1 , memo = memo
381
+ )
382
+ for k , v in list (obj .items ())
383
+ }
384
+
385
+ return safe_repr (obj )
386
+ finally :
387
+ memo .unmemoize (obj )
388
+ return u"<broken repr>"
385
389
386
390
387
391
def extract_locals (frame ):
0 commit comments