refs #1060 : move to_dict to base.py
This commit is contained in:
parent
8d8fe9090f
commit
1b47455225
2 changed files with 16 additions and 21 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright(C) 2010-2011 Christophe Benz, Romain Bignon
|
# Copyright(C) 2010-2013 Christophe Benz, Romain Bignon, Julien Hebert
|
||||||
#
|
#
|
||||||
# This file is part of weboob.
|
# This file is part of weboob.
|
||||||
#
|
#
|
||||||
|
|
@ -389,3 +389,15 @@ class CapBaseObject(object):
|
||||||
self._fields.pop(name)
|
self._fields.pop(name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
object.__delattr__(self, name)
|
object.__delattr__(self, name)
|
||||||
|
|
||||||
|
def to_dict(self):
|
||||||
|
def iter_decorate(d):
|
||||||
|
for key, value in d:
|
||||||
|
if key == 'id' and self.backend is not None:
|
||||||
|
value = self.fullid
|
||||||
|
yield key, value
|
||||||
|
|
||||||
|
fields_iterator = self.iter_fields()
|
||||||
|
return OrderedDict(iter_decorate(fields_iterator))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright(C) 2010-2011 Christophe Benz
|
# Copyright(C) 2010-2013 Christophe Benz, Julien Hebert
|
||||||
#
|
#
|
||||||
# This file is part of weboob.
|
# This file is part of weboob.
|
||||||
#
|
#
|
||||||
|
|
@ -48,7 +48,6 @@ else:
|
||||||
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
|
||||||
|
|
||||||
from weboob.capabilities.base import CapBaseObject
|
from weboob.capabilities.base import CapBaseObject
|
||||||
from weboob.tools.ordereddict import OrderedDict
|
|
||||||
from weboob.tools.application.console import ConsoleApplication
|
from weboob.tools.application.console import ConsoleApplication
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -173,7 +172,7 @@ class IFormatter(object):
|
||||||
:type obj: CapBaseObject
|
:type obj: CapBaseObject
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
return self.format_dict(self.to_dict(obj))
|
return self.format_dict(obj.to_dict())
|
||||||
|
|
||||||
def format_dict(self, obj):
|
def format_dict(self, obj):
|
||||||
"""
|
"""
|
||||||
|
|
@ -185,22 +184,6 @@ class IFormatter(object):
|
||||||
"""
|
"""
|
||||||
return NotImplementedError()
|
return NotImplementedError()
|
||||||
|
|
||||||
def to_dict(self, obj):
|
|
||||||
if not isinstance(obj, CapBaseObject):
|
|
||||||
try:
|
|
||||||
return OrderedDict(obj)
|
|
||||||
except ValueError:
|
|
||||||
raise TypeError('Please give a CapBaseObject or a dict')
|
|
||||||
|
|
||||||
def iter_decorate(d):
|
|
||||||
for key, value in d:
|
|
||||||
if key == 'id' and obj.backend is not None:
|
|
||||||
value = obj.fullid
|
|
||||||
yield key, value
|
|
||||||
|
|
||||||
fields_iterator = obj.iter_fields()
|
|
||||||
return OrderedDict(iter_decorate(fields_iterator))
|
|
||||||
|
|
||||||
|
|
||||||
class PrettyFormatter(IFormatter):
|
class PrettyFormatter(IFormatter):
|
||||||
def format_obj(self, obj, alias):
|
def format_obj(self, obj, alias):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue