util: fallback to raw string reading if pickle fails

This is the next step for getting rid of all the random read and write
functions throughout hgsubversion.
This commit is contained in:
Sean Farley 2014-02-18 17:19:29 -06:00
parent d86829e2cd
commit dbf5c6edc1

View File

@ -169,8 +169,14 @@ def load(file_path, default=None, resave=True):
data = _convert(json.load(f), _descrub) data = _convert(json.load(f), _descrub)
f.close() f.close()
except ValueError: except ValueError:
# Ok, JSON couldn't be loaded, so we'll try the old way of using pickle try:
data = compathacks.pickle_load(f) # Ok, JSON couldn't be loaded, so we'll try the old way of using pickle
data = compathacks.pickle_load(f)
except:
# well, pickle didn't work either, so we reset the file pointer and
# read the string
f.seek(0)
data = f.read()
# convert the file to json immediately # convert the file to json immediately
f.close() f.close()