From 658183b56c0fc01c7a8d1bc3fb0dff75da5ac692 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 3 Sep 2016 14:33:17 -0400 Subject: [PATCH] Move from_doc to the Document class --- wolframalpha/__init__.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/wolframalpha/__init__.py b/wolframalpha/__init__.py index 6f9017f..1f5a150 100644 --- a/wolframalpha/__init__.py +++ b/wolframalpha/__init__.py @@ -71,6 +71,17 @@ class Document(dict): _attr_types = {} "Override the types from the document" + @classmethod + def from_doc(cls, doc): + """ + Load instances from the xmltodict result. Always return + a list, even if the result is a singleton. + """ + if type(doc) != list: + doc = [doc] + return list(map(cls, doc)) + + def __getattr__(self, name): type = self._attr_types.get(name, lambda x: x) attr_name = '@' + name @@ -155,16 +166,6 @@ class Image(Document): width=int, ) - @classmethod - def from_doc(cls, doc): - """ - Load images from the xmltodictresult. Always return - a list, even if the result is a singleton. - """ - if type(doc) != list: - doc = [doc] - return list(map(Image, doc)) - class Subpod(Document): """ @@ -174,16 +175,6 @@ class Subpod(Document): img=Image.from_doc, ) - @classmethod - def from_doc(cls, doc): - """ - Load subpods from the xmltodict result. Always return - a list, even if the result is a singleton. - """ - if type(doc) != list: - doc = [doc] - return list(map(cls, doc)) - def xml_bool(str_val): return (