Formatter fixes
split off the bugfix branch
Yes it looks weird. But it is the best way I've found after trying various hacks.
I hesitated making a commit for this:
diff --git a/weboob/tools/json.py b/weboob/tools/json.py
index f6cd13d0a..3313924db 100644
--- a/weboob/tools/json.py
+++ b/weboob/tools/json.py
@@ -20,6 +20,7 @@
# because we don't want to import this file by "import json"
from __future__ import absolute_import
+import os
from decimal import Decimal
from datetime import datetime, date, time, timedelta
@@ -30,6 +31,8 @@ try:
# However, note that simplejson has very different behaviors from the
# stdlib json module. In particular, it is handling Decimal in a very
# peculiar way and is not returning a string for them.
+ if os.getenv('WEBOOB_JSON', 'simplejson') != 'simplejson':
+ raise ImportError('Another json is asked for')
import simplejson as json
except ImportError:
# Python 2.6+ has a module similar to simplejson
But if people really have this use case maybe they should be using the API directly. It was useful for me to test:
import os
from decimal import Decimal
from weboob.tools.json import json, WeboobEncoder
print(json.__file__)
# This test should be ran with and without simplejson available
print(json.dumps(Decimal('1.1'), cls=WeboobEncoder))
PYTHONPATH="$PWD" python3 test.py ; PYTHONPATH="$PWD" WEBOOB_JSON=json python3 test.py
PYTHONPATH="$PWD" python2 test.py ; PYTHONPATH="$PWD" WEBOOB_JSON=json python2 test.py