class ServiceClass(XMLElement, ServiceExtension): _xml_tag = 'service-class' _xml_namespace = namespace _xml_document = PIDFDocument value = XMLStringChoiceChild('value', registry=ServiceClassRegistry, extension_type=ServiceClassElement) _note_map = NoteMap() def __init__(self, service_class=None, notes=[]): XMLElement.__init__(self) self.value = service_class self.notes.update(notes) @property def notes(self): return NoteList(self, RPIDNote) def __eq__(self, other): if isinstance(other, ServiceClass): return super(ServiceClass, self).__eq__(other) and self.notes == other.notes else: return NotImplemented def __repr__(self): return '%s(%r, %r)' % (self.__class__.__name__, self.value, list(self.notes)) def _parse_element(self, element): self.notes._parse_element(element) def _build_element(self): self.notes._build_element()
class Relationship(XMLElement, ServiceExtension): _xml_tag = 'relationship' _xml_namespace = namespace _xml_document = PIDFDocument _xml_children_order = {RPIDNote: 0} value = XMLStringChoiceChild('value', registry=RelationshipRegistry, other_type=RPIDOther, extension_type=RelationshipElement) _note_map = NoteMap() def __init__(self, relationship='self', notes=[]): XMLElement.__init__(self) self.value = relationship self.notes.update(notes) @property def notes(self): return NoteList(self, RPIDNote) def __eq__(self, other): if isinstance(other, Relationship): return super(Relationship, self).__eq__(other) and self.notes == other.notes else: return NotImplemented def __repr__(self): return '%s(%r, %r)' % (self.__class__.__name__, self.value, list(self.notes)) def _parse_element(self, element): self.notes._parse_element(element) def _build_element(self): self.notes._build_element()
class Mood(XMLStringListElement, PersonExtension): _xml_tag = 'mood' _xml_namespace = namespace _xml_document = PIDFDocument _xml_extension_type = MoodElement _xml_children_order = {RPIDNote.qname: 0} _xml_item_registry = MoodRegistry _xml_item_other_type = RPIDOther _xml_item_extension_type = MoodElement id = XMLAttribute('id', type=str, required=False, test_equal=True) since = XMLAttribute('since', xmlname='from', type=DateTime, required=False, test_equal=True) until = XMLAttribute('until', type=DateTime, required=False, test_equal=True) _note_map = NoteMap() def __init__(self, id=None, since=None, until=None, moods=[], notes=[]): XMLElement.__init__(self) self.id = id self.since = since self.until = until self.update(moods) self.notes.update(notes) @property def notes(self): return NoteList(self, RPIDNote) def __eq__(self, other): if isinstance(other, Mood): return super(Mood, self).__eq__(other) and self.notes == other.notes else: return NotImplemented def __repr__(self): return '%s(%r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id, self.since, self.until, list(self), list(self.notes)) def _parse_element(self, element): super(Mood, self)._parse_element(element) self.notes._parse_element(element) def _build_element(self): super(Mood, self)._build_element() self.notes._build_element() def add(self, mood): if isinstance(mood, basestring): if mood in self._xml_item_registry.names: mood = self._xml_item_registry.class_map[mood]() else: mood = self._xml_item_other_type.from_string(mood) unknown_mood = self._xml_item_registry.class_map['unknown']() if mood == unknown_mood or unknown_mood in self._element_map.itervalues(): self.clear() super(Mood, self).add(mood) def check_validity(self): if not self: raise ValidationError("Mood element must have at least one value") super(Mood, self).check_validity()
class Privacy(XMLElement, PersonExtension): __metaclass__ = PrivacyType _xml_tag = 'privacy' _xml_namespace = namespace _xml_document = PIDFDocument _xml_children_order = {RPIDNote.qname: 0, AudioPrivacy.qname: 1, TextPrivacy.qname: 2, VideoPrivacy.qname: 3} id = XMLAttribute('id', type=str, required=False, test_equal=True) since = XMLAttribute('since', xmlname='from', type=DateTime, required=False, test_equal=True) until = XMLAttribute('until', type=DateTime, required=False, test_equal=True) audio = XMLElementChild('audio', type=AudioPrivacy, required=False, test_equal=True) text = XMLElementChild('text', type=TextPrivacy, required=False, test_equal=True) video = XMLElementChild('video', type=VideoPrivacy, required=False, test_equal=True) unknown = property(lambda self: all(getattr(self, name) is None for name in self._privacy_attributes)) _note_map = NoteMap() def __init__(self, id=None, since=None, until=None, notes=[], audio=False, text=False, video=False): super(Privacy, self).__init__() self.id = id self.since = since self.until = until self.audio = audio self.text = text self.video = video self.notes.update(notes) @property def notes(self): return NoteList(self, RPIDNote) def __eq__(self, other): if isinstance(other, Privacy): return super(Privacy, self).__eq__(other) and self.notes == other.notes else: return NotImplemented def __repr__(self): return '%s(%r, %r, %r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id, self.since, self.until, list(self.notes), self.audio, self.text, self.video) def _parse_element(self, element): self.notes._parse_element(element) def _build_element(self): if self.unknown: if self.element.find('{%s}unknown' % self._xml_namespace) is None: etree.SubElement(self.element, '{%s}unknown' % self._xml_namespace, nsmap=self._xml_document.nsmap) else: unknown_element = self.element.find('{%s}unknown' % self._xml_namespace) if unknown_element is not None: self.element.remove(unknown_element) self.notes._build_element()
class PlaceType(XMLElement, PersonExtension): _xml_tag = 'place-type' _xml_namespace = namespace _xml_document = PIDFDocument _xml_children_order = {RPIDNote.qname: 0} id = XMLAttribute('id', type=str, required=False, test_equal=True) since = XMLAttribute('since', xmlname='from', type=DateTime, required=False, test_equal=True) until = XMLAttribute('until', type=DateTime, required=False, test_equal=True) value = XMLStringChoiceChild('value', other_type=RPIDOther, extension_type=PlaceTypeElement) _note_map = NoteMap() def __init__(self, id=None, since=None, until=None, placetype=None, notes=[]): super(PlaceType, self).__init__() self.id = id self.since = since self.until = until self.value = placetype self.notes.update(notes) @property def notes(self): return NoteList(self, RPIDNote) def __eq__(self, other): if isinstance(other, PlaceType): return super(PlaceType, self).__eq__(other) and self.notes == other.notes else: return NotImplemented def __repr__(self): return '%s(%r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id, self.since, self.until, self.value, list(self.notes)) def _parse_element(self, element): self.notes._parse_element(element) def _build_element(self): self.notes._build_element()
class PlaceIs(XMLElement, PersonExtension): _xml_tag = 'place-is' _xml_namespace = namespace _xml_document = PIDFDocument _xml_children_order = {RPIDNote.qname: 0, AudioPlaceInformation.qname: 1, VideoPlaceInformation.qname: 2, TextPlaceInformation.qname: 3} id = XMLAttribute('id', type=str, required=False, test_equal=True) since = XMLAttribute('since', xmlname='from', type=DateTime, required=False, test_equal=True) until = XMLAttribute('until', type=DateTime, required=False, test_equal=True) audio = XMLElementChild('audio', type=AudioPlaceInformation, required=False, test_equal=True) video = XMLElementChild('video', type=VideoPlaceInformation, required=False, test_equal=True) text = XMLElementChild('text', type=TextPlaceInformation, required=False, test_equal=True) _note_map = NoteMap() def __init__(self, id=None, since=None, until=None, audio=None, video=None, text=None, notes=[]): XMLElement.__init__(self) self.id = id self.since = since self.until = until self.audio = audio self.video = video self.text = text self.notes.update(notes) @property def notes(self): return NoteList(self, RPIDNote) def __eq__(self, other): if isinstance(other, PlaceIs): return super(PlaceIs, self).__eq__(other) and self.notes == other.notes else: return NotImplemented def __repr__(self): return '%s(%r, %r, %r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id, self.since, self.until, self.audio, self.video, self.text, list(self.notes)) def _parse_element(self, element): self.notes._parse_element(element) def _build_element(self): self.notes._build_element()