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.
This commit is contained in:
Laurent Bachelier 2010-11-12 11:54:54 +01:00
commit 7d0105c167

View file

@ -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']: