From 5f41fef816c6283c8ed377b71a1ab0b912ee23bd Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Fri, 10 Mar 2017 12:04:01 +0100 Subject: [PATCH] config: Fix config checker for python 3.3/3.4 Python 3.3 and 3.4 do not have a JSONDecodeError, therefore, we must do by parsing the error message of the ValueError it throws instead. --- cum/config.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cum/config.py b/cum/config.py index c007983..a2111b7 100644 --- a/cum/config.py +++ b/cum/config.py @@ -38,12 +38,24 @@ def load(self): else: try: j = json.load(f) - except json.decoder.JSONDecodeError as e: + except ValueError as e: f.seek(0, 0) - raise exceptions.ConfigError(config=f.read(), - cursor=(e.lineno, e.colno), - message='Error reading config: {}' - .format(e.msg)) + cfargs = {} + if hasattr(json.decoder, 'JSONDecodeError'): + cfargs = {'config': f.read(), + 'cursor': (e.lineno, e.colno), + 'message': 'Error reading config: {}' + .format(e.msg)} + else: + # Remove this hack when we drop Python 3.4 support + msg, pos = str(e).split(':') + m = re.match(r'\s*line (\d+) column (\d+).*', pos) + cur = (int(m.group(1)), int(m.group(2))) + cfargs = {'config': f.read(), + 'cursor': cur, + 'message': 'Error reading config: {}' + .format(msg)} + raise exceptions.ConfigError(**cfargs) finally: f.close()