Mercurial > hgsubversion
changeset 1148:91d685418490
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.
author | Sean Farley <sean.michael.farley@gmail.com> |
---|---|
date | Tue, 18 Feb 2014 17:19:29 -0600 |
parents | 56f426d0261f |
children | 34173bbd3b8e |
files | hgsubversion/util.py |
diffstat | 1 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/hgsubversion/util.py +++ b/hgsubversion/util.py @@ -169,8 +169,14 @@ def load(file_path, default=None, resave data = _convert(json.load(f), _descrub) f.close() except ValueError: - # Ok, JSON couldn't be loaded, so we'll try the old way of using pickle - data = compathacks.pickle_load(f) + try: + # 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 f.close()