def _parse_element(self, element, *args, **kwargs): self.value = None for child in element: if child.tag == RPIDNote.qname: self.notes.append(RPIDNote.from_element(child, *args, **kwargs)) elif child.tag == '{%s}other' % self._xml_namespace: value = child.text if value not in self: self._value = value else: value = parse_qname(child.tag)[1] if value in self.values: self._value = value
def _parse_element(self, element, *args, **kwargs): self.__value = None for child in element: value = parse_qname(child.tag)[1] if value in ('home', 'work', 'unknown'): self.__value = value break else: child_cls = self._xml_application.get_element(child.tag) if child_cls is not None and issubclass(child_cls, SphereElement): self.__value = child_cls.from_element(child, xml_meta=self._xml_meta) break else: self.value = element.text
def _parse_element(self, element, *args, **kwargs): for child in element: if child.tag == RPIDNote.qname: self.notes.add(RPIDNote.from_element(child, *args, **kwargs), with_element=False) elif child.tag == '{%s}other' % self._xml_namespace: value = child.text if value not in self: list.append(self, value) else: value = parse_qname(child.tag)[1] if value in self.values and value not in self: list.append(self, value) if 'unknown' in self and len(self) > 1: self.remove('unknown')
def _parse_element(self, element, *args, **kwargs): self.value = None for child in element: if child.tag == RPIDNote.qname: self.notes.append(RPIDNote.from_element( child, *args, **kwargs)) elif child.tag == '{%s}other' % self._xml_namespace: value = child.text if value not in self: self._value = value else: value = parse_qname(child.tag)[1] if value in self.values: self._value = value
def _parse_element(self, element, *args, **kwargs): self.__value = None for child in element: value = parse_qname(child.tag)[1] if value in ('home', 'work', 'unknown'): self.__value = value break else: child_cls = self._xml_application.get_element(child.tag) if child_cls is not None and issubclass( child_cls, SphereElement): self.__value = child_cls.from_element( child, xml_meta=self._xml_meta) break else: self.value = element.text
def _set_value(self, value): if value is not None and not isinstance(value, str) and not isinstance(value, SphereElement): raise ParserError("Sphere elements can only have SphereElement children, got %s instead" % value.__class__.__name__) if self.__value is not None: for child in self.element: if (parse_qname(child.tag)[1] == self.__value and self.__value in ('home', 'work', 'unknown')) or \ (isinstance(self.__value, SphereElement) and self.__value.element == child): self.element.remove(child) break else: self.element.text = None if isinstance(value, SphereElement): self._insert_element(value.element) elif value in ('home', 'work', 'unknown') or value is None: if value is None: value = 'unknown' element = etree.Element('{%s}%s' % (self._xml_namespace, value)) self._insert_element(element) else: self.element.text = value self.__value = value
def _set_value(self, value): if value is not None and not isinstance(value, str) and not isinstance( value, SphereElement): raise ParserError( "Sphere elements can only have SphereElement children, got %s instead" % value.__class__.__name__) if self.__value is not None: for child in self.element: if (parse_qname(child.tag)[1] == self.__value and self.__value in ('home', 'work', 'unknown')) or \ (isinstance(self.__value, SphereElement) and self.__value.element == child): self.element.remove(child) break else: self.element.text = None if isinstance(value, SphereElement): self._insert_element(value.element) elif value in ('home', 'work', 'unknown') or value is None: if value is None: value = 'unknown' element = etree.Element('{%s}%s' % (self._xml_namespace, value)) self._insert_element(element) else: self.element.text = value self.__value = value