def to_xml_tree(self): info = create_element('info') add_child(info, self._language, 'language') add_child(info, self._category, 'category') add_child(info, self._event, 'event') add_child(info, self._response_type, 'responseType') add_child(info, self._urgency, 'urgency') add_child(info, self._severity, 'severity') add_child(info, self._certainty, 'certainty') if self._event_code: event_code_text = self._event_code.split(':') event_code = create_element('eventCode') add_child(event_code, event_code_text[0], 'valueName') add_child(event_code, event_code_text[1], 'value') info.append(event_code) add_child(info, self._sender_name, 'senderName') add_child(info, self._headline, 'headline') add_child(info, self._description, 'description') add_child(info, self._instruction, 'instruction') add_child(info, self._web, 'web') add_child(info, self._contact, 'contact') if self._area is not None: info.append(self._area) return info
def to_xml_tree(self): """ Convert this alert to element tree format. Return the top element of the Alert tree """ # Check if required attributes are set assert (self._sender not in ['', None]), "Alert sender is empty string." assert (self._status is not None), "Alert status is None." assert (self._msg_type is not None), "Alert message type is None." assert (self._scope is not None), "Alert scope is None." # A restriction message is required for the restricted scope if self._scope == 'Restricted': assert (self._restriction not in ['', None]), "Restricted Alert doesn't have restriction." # At least one address is required for the private scope if self._scope == 'Private': assert (any(self._addresses)), "Private Alert doesn't have addresses." # Create the XML tree alert = create_element('alert') self._sent = datetime.now(pytz.utc).replace(microsecond=0) add_child(alert, self._identifier, 'identifier') add_child(alert, self._sender, 'sender') add_child(alert, str(self._sent.isoformat()), 'sent') add_child(alert, self._status, 'status') add_child(alert, self._msg_type, 'msgType') add_child(alert, self._scope, 'scope') if self._scope == 'Restricted': add_child(alert, self._restriction, 'restriction') if self._scope == 'Private': add_child(alert, self._addresses.pop(), 'addresses') if self._info is not None: alert.append(self._info) if self._signature is not None: alert.append(self._signature) return alert
def to_xml_tree(self): area = create_element('area') add_child(area, self._area_description, 'areaDesc') if self._polygons: for polygon in self._polygons: add_child(area, polygon, 'polygon') if self._circles: for circle in self._circles: add_child(area, circle, 'circle') return area
def to_xml_tree(self): """ Convert this alert to element tree format. Return the top element of the Alert tree """ # Check if required attributes are set assert (self._sender not in ['', None]), "Alert sender is empty string." assert (self._status is not None), "Alert status is None." assert (self._msg_type is not None), "Alert message type is None." assert (self._scope is not None), "Alert scope is None." # A restriction message is required for the restricted scope if self._scope == 'Restricted': assert (self._restriction not in ['', None ]), "Restricted Alert doesn't have restriction." # At least one address is required for the private scope if self._scope == 'Private': assert (any( self._addresses)), "Private Alert doesn't have addresses." # Create the XML tree alert = create_element('alert') self._sent = datetime.now(pytz.utc).replace(microsecond=0) add_child(alert, self._identifier, 'identifier') add_child(alert, self._sender, 'sender') add_child(alert, str(self._sent.isoformat()), 'sent') add_child(alert, self._status, 'status') add_child(alert, self._msg_type, 'msgType') add_child(alert, self._scope, 'scope') if self._scope == 'Restricted': add_child(alert, self._restriction, 'restriction') if self._scope == 'Private': add_child(alert, self._addresses.pop(), 'addresses') if self._info is not None: alert.append(self._info) if self._signature is not None: alert.append(self._signature) return alert