diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-04-23 16:26:27 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-04-23 16:26:27 (GMT) |
commit | e34ba9c2fe759c547202a64b2dc40112d8e1d8c4 (patch) | |
tree | fa50968624544a8dbea052f102de23d6a069d802 /TurtleArt/tautils.py | |
parent | 39d5dcda2db9291208d4b4c1537f7321657c5e86 (diff) |
add missing ']'s to json strings (#2796)
Diffstat (limited to 'TurtleArt/tautils.py')
-rw-r--r-- | TurtleArt/tautils.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/TurtleArt/tautils.py b/TurtleArt/tautils.py index c027537..39ac2c2 100644 --- a/TurtleArt/tautils.py +++ b/TurtleArt/tautils.py @@ -121,15 +121,22 @@ def json_load(text): if OLD_SUGAR_SYSTEM is True: _listdata = json.read(text) else: - # strip out leading and trailing whitespace, nulls, and newlines + # Strip out leading and trailing whitespace, nulls, and newlines clean_text = text.lstrip() clean_text = clean_text.replace('\12', '') clean_text = clean_text.replace('\00', '') - _io = StringIO(clean_text.rstrip()) + clean_text = clean_text.rstrip() + # Look for missing ']'s + left_count = clean_text.count('[') + right_count = clean_text.count(']') + while left_count > right_count: + clean_text += ']' + right_count = clean_text.count(']') + _io = StringIO(clean_text) try: _listdata = jload(_io) except ValueError: - # assume that text is ascii list + # Assume that text is ascii list _listdata = text.split() for i, value in enumerate(_listdata): _listdata[i] = convert(value, float) |