Reconcile the two previous commits (json/to_dict)

Also fix some to_dict move things that were incomplete.
And some PEP8 fixes.

closes #1060
closes #1061
This commit is contained in:
Laurent Bachelier 2013-03-09 12:25:22 +01:00
commit a6fbcbaec7
3 changed files with 40 additions and 16 deletions

View file

@ -18,22 +18,25 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from .iformatter import IFormatter
from weboob.tools.json import json
from .iformatter import IFormatter
__all__ = ['JsonFormatter']
class Encoder(json.JSONEncoder):
"generic weboob objects encoder"
"generic weboob object encoder"
def default(self, obj):
try :
try:
return json.JSONEncoder.default(self, obj)
except TypeError:
i = IFormatter()
try :
dico = i.to_dict(obj)
except TypeError:
try:
dct = obj.to_dict()
except AttributeError:
return str(obj)
for z in dico:
for z in dct:
return z