def find(self, **kwargs):
"""
A helper method for navigating lists of dicts on the page.
The kwargs parameter is used to pass requirements for matching the nested
dictionary keys. All key-values must match.
Args:
kwargs - matching requirements
Returns:
An APIElement matching the filter or None if nothing matched
"""
if not isinstance(self.data, collections.Iterable):
raise CRESTException('Can not iterate on an ' + str(type(self.data)))
for element in self.data:
if all(element[key] == value for key, value in kwargs.items()):
if type(element) in (dict, list):
return APIElement(self.url, element, self._preston)
return element
return None
评论列表
文章目录