From 7d0105c167c82066825325cd16854da4c9d25c6a Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Fri, 12 Nov 2010 11:54:54 +0100 Subject: [PATCH] Fallback to Python json if there is no simplejson The json module is in Python 2.6 and up. json does not raise JSONDecodeError, but ValueError. Since JSONDecodeError is a subclass of ValueError, the except ValueError will work for both. --- weboob/backends/aum/browser.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/weboob/backends/aum/browser.py b/weboob/backends/aum/browser.py index da23e3b5..580b7863 100644 --- a/weboob/backends/aum/browser.py +++ b/weboob/backends/aum/browser.py @@ -19,8 +19,12 @@ import datetime import time import random -import simplejson import urllib +try: + import simplejson +except ImportError: + # Python 2.6+ has a module similar to simplejson + import json as simplejson from weboob.tools.browser import BaseBrowser, BrowserUnavailable from weboob.tools.parsers.html5libparser import Html5libParser @@ -303,7 +307,7 @@ class AuMBrowser(BaseBrowser): def _get_chat_infos(self): try: json = simplejson.load(self.openurl('http://www.adopteunmec.com/1.1_cht_get.php?anticache=%f' % random.random())) - except simplejson.JSONDecodeError: + except ValueError: raise BrowserUnavailable() if json['error']: