Rename node and tree to hidden _doc attributes
This commit is contained in:
parent
d4e09bb905
commit
288b13db0f
|
@ -9,6 +9,7 @@
|
||||||
as URL parameters.
|
as URL parameters.
|
||||||
* ``Result.pods`` now returns an iterator and not
|
* ``Result.pods`` now returns an iterator and not
|
||||||
a list.
|
a list.
|
||||||
|
* ``Result.tree`` and ``Pod.node`` have been removed.
|
||||||
|
|
||||||
2.4
|
2.4
|
||||||
===
|
===
|
||||||
|
|
|
@ -72,8 +72,8 @@ class Result(ErrorHandler, object):
|
||||||
Handles processing the response for the programmer.
|
Handles processing the response for the programmer.
|
||||||
"""
|
"""
|
||||||
def __init__(self, stream):
|
def __init__(self, stream):
|
||||||
self.tree = xmltodict.parse(stream, dict_constructor=dict)['queryresult']
|
self._doc = xmltodict.parse(stream, dict_constructor=dict)['queryresult']
|
||||||
self._handle_error(self.tree)
|
self._handle_error(self._doc)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def info(self):
|
def info(self):
|
||||||
|
@ -84,15 +84,15 @@ class Result(ErrorHandler, object):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pods(self):
|
def pods(self):
|
||||||
return map(Pod, self.tree.get('pod', []))
|
return map(Pod, self._doc.get('pod', []))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def assumptions(self):
|
def assumptions(self):
|
||||||
return map(Assumption, self.tree.get('assumptions', []))
|
return map(Assumption, self._doc.get('assumptions', []))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def warnings(self):
|
def warnings(self):
|
||||||
return map(Warning, self.tree.get('warnings', []))
|
return map(Warning, self._doc.get('warnings', []))
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self.info
|
return self.info
|
||||||
|
@ -119,22 +119,22 @@ class Pod(ErrorHandler, object):
|
||||||
"""
|
"""
|
||||||
Groups answers and information contextualizing those answers.
|
Groups answers and information contextualizing those answers.
|
||||||
"""
|
"""
|
||||||
def __init__(self, node):
|
def __init__(self, doc):
|
||||||
self.node = node
|
self._doc = doc
|
||||||
self.error = node['@error']
|
self.error = doc['@error']
|
||||||
self._handle_error(self.node)
|
self._handle_error(doc)
|
||||||
self.title = node['@title']
|
self.title = doc['@title']
|
||||||
self.scanner = node['@scanner']
|
self.scanner = doc['@scanner']
|
||||||
self.id = node['@id']
|
self.id = doc['@id']
|
||||||
self.position = float(node['@position'])
|
self.position = float(doc['@position'])
|
||||||
self.number_of_subpods = int(node['@numsubpods'])
|
self.number_of_subpods = int(doc['@numsubpods'])
|
||||||
self.subpods = node['subpod']
|
self.subpods = doc['subpod']
|
||||||
# Allow subpods to be accessed in a consistent way,
|
# Allow subpods to be accessed in a consistent way,
|
||||||
# as a list, regardless of how many there are.
|
# as a list, regardless of how many there are.
|
||||||
if type(self.subpods) != list:
|
if type(self.subpods) != list:
|
||||||
self.subpods = [self.subpods]
|
self.subpods = [self.subpods]
|
||||||
self.subpods = list(map(Subpod, self.subpods))
|
self.subpods = list(map(Subpod, self.subpods))
|
||||||
self.primary = '@primary' in node and node['@primary'] != 'false'
|
self.primary = '@primary' in doc and doc['@primary'] != 'false'
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.subpods)
|
return iter(self.subpods)
|
||||||
|
@ -158,11 +158,11 @@ class Subpod(object):
|
||||||
"""
|
"""
|
||||||
Holds a specific answer or additional information relevant to said answer.
|
Holds a specific answer or additional information relevant to said answer.
|
||||||
"""
|
"""
|
||||||
def __init__(self, node):
|
def __init__(self, doc):
|
||||||
self.node = node
|
self._doc = doc
|
||||||
self.title = node['@title']
|
self.title = doc['@title']
|
||||||
self.text = node['plaintext']
|
self.text = doc['plaintext']
|
||||||
self.img = node['img']
|
self.img = doc['img']
|
||||||
# Allow images to be accessed in a consistent way,
|
# Allow images to be accessed in a consistent way,
|
||||||
# as a list, regardless of how many there are.
|
# as a list, regardless of how many there are.
|
||||||
if type(self.img) != list:
|
if type(self.img) != list:
|
||||||
|
@ -172,15 +172,15 @@ class Subpod(object):
|
||||||
|
|
||||||
# Needs work. At the moment this should be considered a placeholder.
|
# Needs work. At the moment this should be considered a placeholder.
|
||||||
class Assumption(object):
|
class Assumption(object):
|
||||||
def __init__(self, node):
|
def __init__(self, doc):
|
||||||
self.assumption = node
|
self._doc = doc
|
||||||
#self.description = self.assumption[0]['desc'] # We only care about our given assumption.
|
#self.description = self._doc[0]['desc'] # We only care about our given assumption.
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self.assumption)
|
return iter(self._doc)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.assumption)
|
return len(self._doc)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def text(self):
|
def text(self):
|
||||||
|
@ -194,14 +194,14 @@ class Assumption(object):
|
||||||
|
|
||||||
# Needs work. At the moment this should be considered a placeholder.
|
# Needs work. At the moment this should be considered a placeholder.
|
||||||
class Warning(object):
|
class Warning(object):
|
||||||
def __init__(self, node):
|
def __init__(self, doc):
|
||||||
self.node = node
|
self._doc = doc
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(node)
|
return iter(self._doc)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(node)
|
return len(self._doc)
|
||||||
|
|
||||||
|
|
||||||
class Image(object):
|
class Image(object):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user