Skip to content

Commit

Permalink
Fix more json.load() calls for Python 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dagwieers committed Dec 9, 2019
1 parent 0ea8d0b commit 334cee4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
8 changes: 3 additions & 5 deletions resources/lib/kodiutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,13 +791,11 @@ def get_cache(path, ttl=None): # pylint: disable=redefined-outer-name
log(3, "Cache '{path}' is forced from cache.", path=path)
else:
log(3, "Cache '{path}' is fresh, expires in {time}.", path=path, time=human_delta(mtime + ttl - now))
from json import load
with open_file(fullpath, 'r') as fdesc:
try:
return load(fdesc)
except (TypeError, ValueError) as exc: # No JSON object could be decoded
fdesc.seek(0, 0)
log_error('{exc}\nDATA: {data}', exc=exc, data=fdesc.read())
return get_json_data(fdesc)
except ValueError as exc: # No JSON object could be decoded
log_error('JSON Error: {exc}', exc=exc)
return None


Expand Down
16 changes: 7 additions & 9 deletions resources/lib/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

from __future__ import absolute_import, division, unicode_literals
from favorites import Favorites
from kodiutils import (addon_profile, container_refresh, end_of_directory, get_search_string,
get_setting, localize, log_error, ok_dialog, open_file, show_listing, ttl,
url_for)
from kodiutils import (addon_profile, container_refresh, end_of_directory, get_json_data,
get_search_string, get_setting, localize, log_error, ok_dialog, open_file,
show_listing, ttl, url_for)
from resumepoints import ResumePoints


Expand All @@ -25,12 +25,10 @@ def read_history(self):
from json import load
with open_file(self._search_history, 'r') as fdesc:
try:
history = load(fdesc)
except (TypeError, ValueError) as exc: # No JSON object could be decoded
fdesc.seek(0, 0)
log_error('{exc}\nDATA: {data}', exc=exc, data=fdesc.read())
history = []
return history
return get_json_data(fdesc)
except ValueError as exc: # No JSON object could be decoded
log_error('JSON Error: {exc}', exc=exc)
return []

def write_history(self, history):
''' Write search history to disk '''
Expand Down
16 changes: 7 additions & 9 deletions resources/lib/tokenresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
''' This module contains all functionality for VRT NU API authentication. '''

from __future__ import absolute_import, division, unicode_literals
from kodiutils import (addon_profile, delete, exists, get_proxies, get_setting, get_tokens_path,
get_url_json, has_credentials, invalidate_caches, listdir, localize, log,
log_error, mkdir, notification, ok_dialog, open_file, open_settings,
set_setting)
from kodiutils import (addon_profile, delete, exists, get_json_data, get_proxies, get_setting,
get_tokens_path, get_url_json, has_credentials, invalidate_caches, listdir,
localize, log, log_error, mkdir, notification, ok_dialog, open_file,
open_settings, set_setting)
from vrtutils import from_unicode

try: # Python 3
Expand Down Expand Up @@ -97,13 +97,11 @@ def _get_cached_token(self, token_name, token_variant=None):
if not exists(path):
return None

from json import load
with open_file(path) as fdesc:
try:
token = load(fdesc)
except (TypeError, ValueError) as exc: # No JSON object could be decoded
fdesc.seek(0, 0)
log_error('{exc}\nDATA: {data}', exc=exc, data=fdesc.read())
token = get_json_data(fdesc)
except ValueError as exc: # No JSON object could be decoded
log_error('JSON Error: {exc}', exc=exc)
return None

from datetime import datetime
Expand Down

0 comments on commit 334cee4

Please sign in to comment.