File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -3707,13 +3707,25 @@ def _strip_parent_keys(self):
3707
3707
def toJSON (self , indent = 4 , separators = None ):
3708
3708
"""Converts a parsed structure to JSON"""
3709
3709
import json
3710
-
3711
3710
self ._strip_parent_keys ()
3711
+ def clean_dict (markers , keys = []):
3712
+ if (id (markers ) in keys ):
3713
+ return None
3714
+ elif isinstance (markers , dict ):
3715
+ keys_ = keys + [id (markers )]
3716
+ return {key : clean_dict (markers [key ], keys_ ) for
3717
+ key , value in markers .items ()}
3718
+ elif type (markers ) in [list , set , tuple ]:
3719
+ return type (markers )(clean_dict (m , keys ) for m in markers )
3720
+ return markers
3712
3721
try :
3713
3722
del self .__dict__ ["classes_order" ]
3714
3723
except :
3715
3724
pass
3716
- return json .dumps (self .__dict__ , indent = indent , separators = separators )
3725
+
3726
+ d = self .__dict__
3727
+ d ["classes" ] = clean_dict (d ["classes" ])
3728
+ return json .dumps (d , indent = indent , separators = separators , default = "" )
3717
3729
3718
3730
def __repr__ (self ):
3719
3731
rtn = {
You can’t perform that action at this time.
0 commit comments