diff --git a/modules/aum/browser.py b/modules/aum/browser.py index bf47d255..6a5d9f64 100644 --- a/modules/aum/browser.py +++ b/modules/aum/browser.py @@ -24,12 +24,9 @@ import datetime import random import urllib from htmlentitydefs import codepoint2name -try: - import json -except ImportError: - import simplejson as json from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword, BrowserUnavailable +from weboob.tools.json import json from weboob.capabilities.chat import ChatException, ChatMessage from weboob.capabilities.messages import CantSendMessage diff --git a/modules/izneo/backend.py b/modules/izneo/backend.py index 79a5a703..34fad3b7 100644 --- a/modules/izneo/backend.py +++ b/modules/izneo/backend.py @@ -19,14 +19,10 @@ from __future__ import with_statement -try: - import simplejson as json -except ImportError: - import json - import re from weboob.capabilities.gallery import ICapGallery, BaseGallery, BaseImage +from weboob.tools.json import json from weboob.tools.backend import BaseBackend from weboob.tools.browser import BaseBrowser, BasePage diff --git a/modules/mediawiki/browser.py b/modules/mediawiki/browser.py index 90d52e78..fd734c12 100644 --- a/modules/mediawiki/browser.py +++ b/modules/mediawiki/browser.py @@ -22,14 +22,9 @@ import urllib import datetime from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword +from weboob.tools.json import json as simplejson from weboob.capabilities.content import Revision -try: - import simplejson -except ImportError: - # Python 2.6+ has a module similar to simplejson - import json as simplejson - __all__ = ['MediawikiBrowser'] diff --git a/modules/radiofrance/browser.py b/modules/radiofrance/browser.py index 98b3d09d..8c774aa7 100644 --- a/modules/radiofrance/browser.py +++ b/modules/radiofrance/browser.py @@ -18,6 +18,7 @@ # along with weboob. If not, see . from weboob.tools.browser import BaseBrowser, BasePage +from weboob.tools.json import json from weboob.capabilities.video import BaseVideo from weboob.tools.browser.decorators import id2url @@ -25,11 +26,6 @@ from StringIO import StringIO from time import time import re -try: - import json -except ImportError: - import simplejson as json - try: from urlparse import parse_qs except ImportError: diff --git a/modules/youtube/pages.py b/modules/youtube/pages.py index e261373f..d0112184 100644 --- a/modules/youtube/pages.py +++ b/modules/youtube/pages.py @@ -18,14 +18,10 @@ # along with weboob. If not, see . -try: - import json -except ImportError: - import simplejson as json - import urllib from weboob.tools.browser import BasePage, BrokenPageError, BrowserIncorrectPassword +from weboob.tools.json import json __all__ = ['LoginPage', 'LoginRedirectPage', 'ForbiddenVideo', 'ForbiddenVideoPage', \ diff --git a/weboob/tools/json.py b/weboob/tools/json.py new file mode 100644 index 00000000..91868b15 --- /dev/null +++ b/weboob/tools/json.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +# Copyright(C) 2012 Laurent Bachelier +# +# This file is part of weboob. +# +# weboob is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# weboob is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with weboob. If not, see . + +# because we don't want to import this file by "import json" +from __future__ import absolute_import + +__all__ = ['json'] + +try: + # try simplejson first because it is faster + import simplejson as json +except ImportError: + # Python 2.6+ has a module similar to simplejson + import json diff --git a/weboob/tools/parsers/jsonparser.py b/weboob/tools/parsers/jsonparser.py index 29d6fcc8..9682962f 100644 --- a/weboob/tools/parsers/jsonparser.py +++ b/weboob/tools/parsers/jsonparser.py @@ -18,11 +18,7 @@ # along with weboob. If not, see . -try: - import json -except ImportError: - import simplejson as json - +from weboob.tools.json import json from .iparser import IParser