def refine_model(cls): model = get_pyxml_model(cls) for child_name in children_names: type = get_parameter_type(child_name, cls) child = PyXmlChild(child_name, type) model.children.append(child) return cls
def refine_model(cls): model = get_pyxml_model(cls) for attribute_name in attribute_names: type = get_parameter_type(attribute_name, cls) attribute = PyXmlAttribute(attribute_name, type) model.attrib.append(attribute) return cls
def serialize(obj: object) -> etree.Element: model = get_pyxml_model(obj) element = etree.Element(model.name) if model.text is not None: value = getattr(obj, model.text.name) element.text = str(value) attrib = PyXmlSerializer.build_attrib(model, obj) PyXmlSerializer.serialize_children(element, model, obj) PyXmlSerializer.serialize_children_lists(element, model, obj) element.attrib.update(attrib) return element
def parse_lists(element, model, object_attr): for sublist in model.lists: new_list = list() if sublist.parent is None: parent = element else: parent = find(sublist.parent, element, model) for item_element in find_all(sublist.items_tag, parent, model): sublist_items_model = get_pyxml_model(sublist.items_type) if sublist_items_model is not None: sublist_item = PyXmlParser.parse_element(item_element, sublist_items_model) else: sublist_item = sublist.items_type(item_element.text) new_list.append(sublist_item) object_attr[sublist.name] = new_list
def parse(file: str, cls: object): model = get_pyxml_model(cls) tree = etree.parse(file).getroot() return PyXmlParser.parse_element(tree, model)
def refine_model(cls): model = get_pyxml_model(cls) model.namespace = namespace return cls
def refine_model(cls): model = get_pyxml_model(cls) child_list = PyXmlList(name, items_type, items_tag, parent) model.lists.append(child_list) return cls
def refine_model(cls): model = get_pyxml_model(cls) type = get_parameter_type(text_name, cls) model.text = PyXmlText(text_name, type) return cls
def refine_model(cls): model = get_pyxml_model(cls) model.name = node_name return cls