def parse(cls, sentence): response_match = response_re.match(sentence[0]) if response_match: response = cls(response_match.group(1)) response.parse_attributes(sentence[1:]) else: raise exceptions.RouterOsApiParsingError("Malformed sentence %s", sentence) return response
def parse_attributes(self, serialized_attributes): for serialized in serialized_attributes: attribute_match = attribute_re.match(serialized) tag_match = tag_re.match(serialized) if attribute_match: key, value = attribute_match.groups() self.attributes[key] = self.process_value(value) elif tag_match: self.tag = tag_match.group(1) else: raise exceptions.RouterOsApiParsingError( "Malformed attribute %s", serialized)