Use compose to generate the lists where expected

This commit is contained in:
Jason R. Coombs 2016-09-03 14:38:10 -04:00
parent 658183b56c
commit d4e3afe6b0
2 changed files with 6 additions and 4 deletions

View File

@ -34,6 +34,7 @@ setup_params = dict(
install_requires=[ install_requires=[
'six', 'six',
'xmltodict', 'xmltodict',
'jaraco.functools',
], ],
extras_require={ extras_require={
}, },

View File

@ -3,6 +3,7 @@ import itertools
from six.moves import urllib, map from six.moves import urllib, map
import xmltodict import xmltodict
from jaraco.functools import compose
from . import compat from . import compat
@ -75,11 +76,11 @@ class Document(dict):
def from_doc(cls, doc): def from_doc(cls, doc):
""" """
Load instances from the xmltodict result. Always return Load instances from the xmltodict result. Always return
a list, even if the result is a singleton. an iterable, even if the result is a singleton.
""" """
if type(doc) != list: if type(doc) != list:
doc = [doc] doc = [doc]
return list(map(cls, doc)) return map(cls, doc)
def __getattr__(self, name): def __getattr__(self, name):
@ -172,7 +173,7 @@ class Subpod(Document):
Holds a specific answer or additional information relevant to said answer. Holds a specific answer or additional information relevant to said answer.
""" """
_attr_types = dict( _attr_types = dict(
img=Image.from_doc, img=compose(list, Image.from_doc),
) )
@ -191,7 +192,7 @@ class Pod(ErrorHandler, Document):
_attr_types = dict( _attr_types = dict(
position=float, position=float,
numsubpods=int, numsubpods=int,
subpod=Subpod.from_doc, subpod=compose(list, Subpod.from_doc),
) )
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Pod, self).__init__(*args, **kwargs) super(Pod, self).__init__(*args, **kwargs)