Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def from_xml(self, xml_string):
"""Grab errors from an XML response.
Args:
xml_string: An xml errors object (e.g. '')
Returns:
None
"""
attribute_keys = self.base.attributes.keys()
try:
messages = util.xml_to_dict(
xml_string)['errors']['error']
if not isinstance(messages, list):
messages = [messages]
except util.Error:
messages = []
for message in messages:
attr_name = message.split()[0]
key = util.underscore(attr_name)
if key in attribute_keys:
self.add(key, message[len(attr_name)+1:])
else:
self.add_to_base(message)