Remove to_struct and from_struct methods

This commit is contained in:
Nick Hall 2017-01-20 21:55:39 +00:00
parent 4c2464cb49
commit 41bcfefd67
47 changed files with 0 additions and 2080 deletions

View File

@ -67,49 +67,6 @@ class Address(SecondaryObject, PrivacyBase, CitationBase, NoteBase, DateBase,
DateBase.serialize(self), DateBase.serialize(self),
LocationBase.serialize(self)) LocationBase.serialize(self))
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Address",
"private": PrivacyBase.serialize(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"date": DateBase.to_struct(self),
"location": LocationBase.to_struct(self)
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Address()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
DateBase.from_struct(struct.get("date", {})),
LocationBase.from_struct(struct.get("location", {}))
)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -59,37 +59,6 @@ class AddressBase:
""" """
return [addr.serialize() for addr in self.address_list] return [addr.serialize() for addr in self.address_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [addr.to_struct() for addr in self.address_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Address.from_struct(addr) for addr in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -65,37 +65,6 @@ class AttributeRootBase:
""" """
return [attr.serialize() for attr in self.attribute_list] return [attr.serialize() for attr in self.attribute_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [attr.to_struct() for attr in self.attribute_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [cls._CLASS.from_struct(attr) for attr in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -77,43 +77,6 @@ class AttributeRoot(SecondaryObject, PrivacyBase):
return (PrivacyBase.serialize(self), return (PrivacyBase.serialize(self),
self.type.serialize(), self.value) self.type.serialize(), self.value)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": self.__class__.__name__,
"private": PrivacyBase.serialize(self),
"type": self.type.to_struct(),
"value": self.value}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Attribute()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
AttributeType.from_struct(struct.get("type", {})),
struct.get("value", default.value))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.
@ -246,46 +209,6 @@ class Attribute(AttributeRoot, CitationBase, NoteBase):
NoteBase.serialize(self), NoteBase.serialize(self),
self.type.serialize(), self.value) self.type.serialize(), self.value)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Attribute",
"private": PrivacyBase.serialize(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"type": self.type.to_struct(),
"value": self.value}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return (PrivacyBase.from_struct(struct["private"]),
CitationBase.from_struct(struct["citation_list"]),
NoteBase.from_struct(struct["note_list"]),
AttributeType.from_struct(struct["type"]),
struct["value"])
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -56,43 +56,6 @@ class BaseObject(metaclass=ABCMeta):
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.
""" """
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def matches_string(self, pattern, case_sensitive=False): def matches_string(self, pattern, case_sensitive=False):
""" """
Return True if any text data in the object or any of it's child Return True if any text data in the object or any of it's child

View File

@ -75,49 +75,6 @@ class ChildRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
self.frel.serialize(), self.frel.serialize(),
self.mrel.serialize()) self.mrel.serialize())
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "ChildRef",
"private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"ref": Handle("Person", self.ref),
"frel": self.frel.to_struct(),
"mrel": self.mrel.to_struct()}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = ChildRef()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
ChildRefType.from_struct(struct.get("frel", {})),
ChildRefType.from_struct(struct.get("mrel", {})))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -136,61 +136,6 @@ class Citation(MediaBase, NoteBase, SrcAttributeBase, IndirectCitationBase,
TagBase.serialize(self), # 10 TagBase.serialize(self), # 10
self.private) # 11 self.private) # 11
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Citation",
"handle": Handle("Citation", self.handle), # 0
"gramps_id": self.gramps_id, # 1
"date": DateBase.to_struct(self), # 2
"page": str(self.page), # 3
"confidence": self.confidence, # 4
"source_handle": Handle("Source", self.source_handle), # 5
"note_list": NoteBase.to_struct(self), # 6
"media_list": MediaBase.to_struct(self), # 7
"srcattr_list": SrcAttributeBase.to_struct(self),# 8
"change": self.change, # 9
"tag_list": TagBase.to_struct(self), # 10
"private": self.private} # 11
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Citation()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
DateBase.from_struct(struct.get("date", {})),
struct.get("page", default.page),
struct.get("confidence", default.confidence),
Handle.from_struct(struct.get("source_handle", default.source_handle)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
MediaBase.from_struct(struct.get("media_list", default.media_list)),
SrcAttributeBase.from_struct(struct.get("srcattr_list", [])),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -75,37 +75,6 @@ class CitationBase:
""" """
return self.citation_list return self.citation_list
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [Handle("Citation", c) for c in self.citation_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Handle.from_struct(handle) for handle in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -671,55 +671,6 @@ class Date:
return (self.calendar, self.modifier, self.quality, return (self.calendar, self.modifier, self.quality,
self.dateval, text, self.sortval, self.newyear) self.dateval, text, self.sortval, self.newyear)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Date",
"calendar": self.calendar,
"modifier": self.modifier,
"quality": self.quality,
"dateval": self.dateval,
"text": self.text,
"sortval": self.sortval,
"newyear": self.newyear}
@classmethod
def from_struct(cls, struct, full=False):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Date()
retval = (struct.get("calendar", default.calendar),
struct.get("modifier", default.modifier),
struct.get("quality", default.quality),
struct.get("dateval", default.dateval),
struct.get("text", default.text),
struct.get("sortval", default.sortval),
struct.get("newyear", default.newyear))
if not full and retval == (0, 0, 0, (0, 0, 0, False), '', 0, 0):
return None
else:
return retval
def unserialize(self, data): def unserialize(self, data):
""" """
Load from the format created by serialize. Load from the format created by serialize.

View File

@ -61,41 +61,6 @@ class DateBase:
date = self.date.serialize(no_text_date) date = self.date.serialize(no_text_date)
return date return date
def to_struct(self, no_text_date=False):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
if self.date is None:
date = Date().to_struct()
else:
date = self.date.to_struct()
return date
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return Date.from_struct(struct)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -118,41 +118,6 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase,
AttributeBase.serialize(self), AttributeBase.serialize(self),
self.change, TagBase.serialize(self), self.private) self.change, TagBase.serialize(self), self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Event",
"handle": Handle("Event", self.handle),
"gramps_id": self.gramps_id,
"type": self.__type.to_struct(),
"date": DateBase.to_struct(self),
"description": self.__description,
"place": Handle("Place", self.place),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"media_list": MediaBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """
@ -199,28 +164,6 @@ class Event(CitationBase, NoteBase, MediaBase, AttributeBase,
"private": _("Private"), "private": _("Private"),
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Event()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
EventType.from_struct(struct.get("type", {})),
DateBase.from_struct(struct.get("date", {})),
struct.get("description", default.description),
Handle.from_struct(struct.get("place", default.place)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
MediaBase.from_struct(struct.get("media_list", default.media_list)),
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -79,35 +79,6 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
self.__role.serialize() self.__role.serialize()
) )
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "EventRef",
"private": PrivacyBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"ref": Handle("Event", self.ref),
"role": self.__role.to_struct()
}
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """
@ -142,22 +113,6 @@ class EventRef(PrivacyBase, NoteBase, AttributeBase, RefBase,
"role": _("Role"), "role": _("Role"),
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = EventRef()
return (
PrivacyBase.from_struct(struct.get("private", default.private)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
EventRoleType.from_struct(struct.get("role", {}))
)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -127,78 +127,6 @@ class Family(CitationBase, NoteBase, MediaBase, AttributeBase, LdsOrdBase,
NoteBase.serialize(self), NoteBase.serialize(self),
self.change, TagBase.serialize(self), self.private) self.change, TagBase.serialize(self), self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Family",
"handle": Handle("Family", self.handle),
"gramps_id": self.gramps_id,
"father_handle": Handle("Person", self.father_handle),
"mother_handle": Handle("Person", self.mother_handle),
"child_ref_list": [cr.to_struct() for cr in self.child_ref_list],
"type": self.type.to_struct(),
"event_ref_list": [er.to_struct() for er in self.event_ref_list],
"media_list": MediaBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"lds_ord_list": LdsOrdBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Family()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
Handle.from_struct(struct.get("father_handle",
default.father_handle)),
Handle.from_struct(struct.get("mother_handle",
default.mother_handle)),
[ChildRef.from_struct(cr)
for cr in struct.get("child_ref_list",
default.child_ref_list)],
FamilyRelType.from_struct(struct.get("type", {})),
[EventRef.from_struct(er)
for er in struct.get("event_ref_list",
default.event_ref_list)],
MediaBase.from_struct(struct.get("media_list",
default.media_list)),
AttributeBase.from_struct(struct.get("attribute_list",
default.attribute_list)),
LdsOrdBase.from_struct(struct.get("lds_ord_list",
default.lds_ord_list)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
from .mediaref import MediaRef from .mediaref import MediaRef

View File

@ -215,44 +215,6 @@ class GrampsType(object, metaclass=GrampsTypeMeta):
"string": _("Family Relationship"), "string": _("Family Relationship"),
} }
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": self.__class__.__name__,
"value": self.__value,
"string": str(self)}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = cls()
if struct.get("value", cls._CUSTOM) == cls._CUSTOM:
return (struct.get("value", default.value),
struct.get("string", ""))
else:
return (struct.get("value", default.value), '')
def unserialize(self, data): def unserialize(self, data):
"""Convert a serialized tuple of data to an object.""" """Convert a serialized tuple of data to an object."""
self.__value, self.__string = data self.__value, self.__string = data

View File

@ -53,7 +53,3 @@ def Handle(_classname, handle):
classname = _classname classname = _classname
h = MyHandleClass(handle) h = MyHandleClass(handle)
return h return h
def __from_struct(struct):
return struct
Handle.from_struct = __from_struct

View File

@ -144,57 +144,6 @@ class LdsOrd(SecondaryObject, CitationBase, NoteBase,
self.type, self.place, self.type, self.place,
self.famc, self.temple, self.status, self.private) self.famc, self.temple, self.status, self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "LdsOrd",
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"date": DateBase.to_struct(self),
"type": self.type,
"place": self.place,
"famc": self.famc,
"temple": self.temple,
"status": self.status,
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = LdsOrd()
return (CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
DateBase.from_struct(struct.get("date", {})),
struct.get("type", {}),
struct.get("place", default.place),
struct.get("famc", default.famc),
struct.get("temple", default.temple),
struct.get("status", default.status),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -64,37 +64,6 @@ class LdsOrdBase:
""" """
return [lds_ord.serialize() for lds_ord in self.lds_ord_list] return [lds_ord.serialize() for lds_ord in self.lds_ord_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [lds_ord.to_struct() for lds_ord in self.lds_ord_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [LdsOrd.from_struct(lds_ord) for lds_ord in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object Convert a serialized tuple of data to an object

View File

@ -63,55 +63,6 @@ class Location(SecondaryObject, LocationBase):
""" """
return (LocationBase.serialize(self), self.parish) return (LocationBase.serialize(self), self.parish)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Location",
"street": self.street,
"locality": self.locality,
"city": self.city,
"county": self.county,
"state": self.state,
"country": self.country,
"postal": self.postal,
"phone": self.phone,
"parish": self.parish}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Location()
return ((struct.get("street", default.street),
struct.get("locality", default.locality),
struct.get("city", default.city),
struct.get("country", default.country),
struct.get("state", default.state),
struct.get("country", default.country),
struct.get("postal", default.postal),
struct.get("phone", default.phone)),
struct.get("parish", default.parish))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -64,55 +64,6 @@ class LocationBase:
return (self.street, self.locality, self.city, self.county, self.state, return (self.street, self.locality, self.city, self.county, self.state,
self.country, self.postal, self.phone) self.country, self.postal, self.phone)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "LocationBase",
"street": self.street,
"locality": self.locality,
"city": self.city,
"county": self.county,
"state": self.state,
"country": self.country,
"postal": self.postal,
"phone": self.phone
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = LocationBase()
return (struct.get("street", default.street),
struct.get("locality", default.locality),
struct.get("city", default.city),
struct.get("county", default.county),
struct.get("state", default.state),
struct.get("country", default.country),
struct.get("postal", default.postal),
struct.get("phone", default.phone))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -118,41 +118,6 @@ class Media(CitationBase, NoteBase, DateBase, AttributeBase,
TagBase.serialize(self), TagBase.serialize(self),
self.private) self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Media",
"handle": Handle("Media", self.handle),
"gramps_id": self.gramps_id,
"path": self.path,
"mime": self.mime,
"desc": self.desc,
"checksum": self.checksum,
"attribute_list": AttributeBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"change": self.change,
"date": DateBase.to_struct(self),
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """
@ -205,28 +170,6 @@ class Media(CitationBase, NoteBase, DateBase, AttributeBase,
"private": _("Private"), "private": _("Private"),
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Media()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("path", default.path),
struct.get("mime", default.mime),
struct.get("desc", default.desc),
struct.get("checksum", default.checksum),
AttributeBase.from_struct(struct.get("attribute_list", default.attribute_list)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
struct.get("change", default.change),
DateBase.from_struct(struct.get("date", {})),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -56,37 +56,6 @@ class MediaBase:
""" """
return [mref.serialize() for mref in self.media_list] return [mref.serialize() for mref in self.media_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [mref.to_struct() for mref in self.media_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [MediaRef.from_struct(mref) for mref in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -70,34 +70,6 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
RefBase.serialize(self), RefBase.serialize(self),
self.rect) self.rect)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "MediaRef",
"private": PrivacyBase.serialize(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"attribute_list": AttributeBase.to_struct(self),
"ref": Handle("Media", self.ref),
"rect": self.rect if self.rect != (0, 0, 0, 0) else None}
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """
@ -118,24 +90,6 @@ class MediaRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase,
"rect": tuple, # or None if (0,0,0,0) "rect": tuple, # or None if (0,0,0,0)
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = MediaRef()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
AttributeBase.from_struct(struct.get("attribute_list",
default.attribute_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
struct.get("rect", default.rect))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -129,70 +129,6 @@ class Name(SecondaryObject, PrivacyBase, SurnameBase, CitationBase, NoteBase,
self.group_as, self.sort_as, self.display_as, self.call, self.group_as, self.sort_as, self.display_as, self.call,
self.nick, self.famnick) self.nick, self.famnick)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Name",
"private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"date": DateBase.to_struct(self),
"first_name": self.first_name,
"surname_list": SurnameBase.to_struct(self),
"suffix": self.suffix,
"title": self.title,
"type": self.type.to_struct(),
"group_as": self.group_as,
"sort_as": self.sort_as,
"display_as": self.display_as,
"call": self.call,
"nick": self.nick,
"famnick": self.famnick}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Name()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
DateBase.from_struct(struct.get("date", {})),
struct.get("first_name", default.first_name),
SurnameBase.from_struct(struct.get("surname_list",
default.surname_list)),
struct.get("suffix", default.suffix),
struct.get("title", default.title),
NameType.from_struct(struct.get("type", {})),
struct.get("group_as", default.group_as),
struct.get("sort_as", default.sort_as),
struct.get("display_as", default.display_as),
struct.get("call", default.call),
struct.get("nick", default.nick),
struct.get("famnick", default.famnick))
@classmethod @classmethod
def get_labels(cls, _): def get_labels(cls, _):
return { return {

View File

@ -95,36 +95,6 @@ class Note(BasicPrimaryObject):
self.type.serialize(), self.change, TagBase.serialize(self), self.type.serialize(), self.change, TagBase.serialize(self),
self.private) self.private)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Note",
"handle": Handle("Note", self.handle),
"gramps_id": self.gramps_id,
"text": self.text.to_struct(),
"format": self.format,
"type": self.type.to_struct(),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """
@ -154,23 +124,6 @@ class Note(BasicPrimaryObject):
"private": _("Private"), "private": _("Private"),
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Note()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
StyledText.from_struct(struct.get("text", {})),
struct.get("format", default.format),
NoteType.from_struct(struct.get("type", {})),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
"""Convert a serialized tuple of data to an object. """Convert a serialized tuple of data to an object.

View File

@ -53,37 +53,6 @@ class NoteBase:
""" """
return self.note_list return self.note_list
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [Handle("Note", n) for n in self.note_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Handle.from_struct(n) for n in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -157,56 +157,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
[pr.serialize() for pr in self.person_ref_list] # 20 [pr.serialize() for pr in self.person_ref_list] # 20
) )
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "Person",
"handle": Handle("Person", self.handle), # 0
"gramps_id": self.gramps_id, # 1
"gender": self.__gender, # 2
"primary_name": self.primary_name.to_struct(), # 3
"alternate_names": [name.to_struct()
for name in self.alternate_names], # 4
"death_ref_index": self.death_ref_index, # 5
"birth_ref_index": self.birth_ref_index, # 6
"event_ref_list": [er.to_struct()
for er in self.event_ref_list], # 7
"family_list": [Handle("Family", f) for f in
self.family_list], # 8
"parent_family_list": [Handle("Family", f) for f in
self.parent_family_list], # 9
"media_list": MediaBase.to_struct(self), # 10
"address_list": AddressBase.to_struct(self), # 11
"attribute_list": AttributeBase.to_struct(self), # 12
"urls": UrlBase.to_struct(self), # 13
"lds_ord_list": LdsOrdBase.to_struct(self), # 14
"citation_list": CitationBase.to_struct(self), # 15
"note_list": NoteBase.to_struct(self), # 16
"change": self.change, # 17
"tag_list": TagBase.to_struct(self), # 18
"private": self.private, # 19
"person_ref_list": [pr.to_struct()
for pr in self.person_ref_list] # 20
}
@classmethod @classmethod
def get_labels(cls, _): def get_labels(cls, _):
return { return {
@ -234,49 +184,6 @@ class Person(CitationBase, NoteBase, AttributeBase, MediaBase,
"probably_alive": _("Probably alive"), "probably_alive": _("Probably alive"),
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Person()
return (
Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("gender", default.gender),
Name.from_struct(struct.get("primary_name", {})),
[Name.from_struct(name)
for name in struct.get("alternate_names",
default.alternate_names)],
struct.get("death_ref_index", default.death_ref_index),
struct.get("birth_ref_index", default.birth_ref_index),
[EventRef.from_struct(er)
for er in struct.get("event_ref_list", default.event_ref_list)],
[Handle.from_struct(handle)
for handle in struct.get("family_list", default.family_list)],
[Handle.from_struct(handle)
for handle in struct.get("parent_family_list",
default.parent_family_list)],
MediaBase.from_struct(struct.get("media_list", default.media_list)),
AddressBase.from_struct(struct.get("address_list",
default.address_list)),
AttributeBase.from_struct(struct.get("attribute_list",
default.attribute_list)),
UrlBase.from_struct(struct.get("urls", default.urls)),
LdsOrdBase.from_struct(struct.get("lds_ord_list",
default.lds_ord_list)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private),
[PersonRef.from_struct(p)
for p in struct.get("person_ref_list", default.person_ref_list)]
)
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """

View File

@ -72,47 +72,6 @@ class PersonRef(SecondaryObject, PrivacyBase, CitationBase, NoteBase, RefBase):
RefBase.serialize(self), RefBase.serialize(self),
self.rel) self.rel)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "PersonRef",
"private": PrivacyBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"ref": Handle("Person", self.ref),
"rel": self.rel}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = PersonRef()
return (PrivacyBase.from_struct(struct.get("private", default.private)),
CitationBase.from_struct(struct.get("citation_list", default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
struct.get("rel", default.rel))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -166,78 +166,6 @@ class Place(CitationBase, NoteBase, MediaBase, UrlBase, PrimaryObject):
"private": bool "private": bool
} }
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Place",
"handle": Handle("Place", self.handle),
"gramps_id": self.gramps_id,
"title": self.title,
"long": self.long,
"lat": self.lat,
"placeref_list": [pr.to_struct() for pr in self.placeref_list],
"name": self.name.to_struct(),
"alt_names": [an.to_struct() for an in self.alt_names],
"place_type": self.place_type.to_struct(),
"code": self.code,
"alt_loc": [al.to_struct() for al in self.alt_loc],
"urls": UrlBase.to_struct(self),
"media_list": MediaBase.to_struct(self),
"citation_list": CitationBase.to_struct(self),
"note_list": NoteBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Place()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("title", default.title),
struct.get("long", default.long),
struct.get("lat", default.lat),
[PlaceRef.from_struct(pr)
for pr in struct.get("placeref_list", default.placeref_list)],
PlaceName.from_struct(struct.get("name", {})),
[PlaceName.from_struct(an)
for an in struct.get("alt_names", default.alt_names)],
PlaceType.from_struct(struct.get("place_type", {})),
struct.get("code", default.code),
[Location.from_struct(al)
for al in struct.get("alt_loc", default.alt_loc)],
UrlBase.from_struct(struct.get("urls", default.urls)),
MediaBase.from_struct(struct.get("media_list",
default.media_list)),
CitationBase.from_struct(struct.get("citation_list",
default.citation_list)),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -71,47 +71,6 @@ class PlaceName(SecondaryObject, DateBase):
self.lang self.lang
) )
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "PlaceName",
"value": self.value,
"date": DateBase.to_struct(self),
"lang": self.lang
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = PlaceName()
return (
struct.get("value", default.value),
DateBase.from_struct(struct.get("date", {})),
struct.get("lang", default.lang)
)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -63,45 +63,6 @@ class PlaceRef(RefBase, DateBase, SecondaryObject):
DateBase.serialize(self) DateBase.serialize(self)
) )
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "PlaceRef",
"ref": Handle("Place", self.ref),
"date": DateBase.to_struct(self)
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = PlaceRef()
return (
RefBase.from_struct(struct.get("ref", default.ref)),
DateBase.from_struct(struct.get("date", {}))
)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -90,43 +90,6 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase):
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.
""" """
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def set_gramps_id(self, gramps_id): def set_gramps_id(self, gramps_id):
""" """
Set the Gramps ID for the primary object. Set the Gramps ID for the primary object.
@ -278,43 +241,6 @@ class PrimaryObject(BasicPrimaryObject):
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.
""" """
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def has_handle_reference(self, classname, handle): def has_handle_reference(self, classname, handle):
""" """
Return True if the object has reference to a given handle of given Return True if the object has reference to a given handle of given

View File

@ -55,37 +55,6 @@ class PrivacyBase:
""" """
return self.private return self.private
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: bool
"""
return self.private
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return struct
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -53,15 +53,6 @@ class RefBase(metaclass=ABCMeta):
""" """
return self.ref return self.ref
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return str(struct)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -104,57 +104,6 @@ class Repository(NoteBase, AddressBase, UrlBase, IndirectCitationBase,
"private": bool "private": bool
} }
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Repository",
"handle": Handle("Repository", self.handle),
"gramps_id": self.gramps_id,
"type": self.type.to_struct(),
"name": str(self.name),
"note_list": NoteBase.to_struct(self),
"address_list": AddressBase.to_struct(self),
"urls": UrlBase.to_struct(self),
"change": self.change,
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Repository()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
RepositoryType.from_struct(struct.get("type", {})),
struct.get("name", default.name),
NoteBase.from_struct(struct.get("note_list", default.note_list)),
AddressBase.from_struct(struct.get("address_list", default.address_list)),
UrlBase.from_struct(struct.get("urls", default.urls)),
struct.get("change", default.change),
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -69,51 +69,6 @@ class RepoRef(SecondaryObject, PrivacyBase, NoteBase, RefBase):
PrivacyBase.serialize(self), PrivacyBase.serialize(self),
) )
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {
"_class": "RepositoryRef",
"note_list": NoteBase.to_struct(self),
"ref": Handle("Repository", self.ref),
"call_number": self.call_number,
"media_type": self.media_type.to_struct(),
"private": PrivacyBase.serialize(self),
}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = RepoRef()
return (
NoteBase.from_struct(struct.get("note_list", default.note_list)),
RefBase.from_struct(struct.get("ref", default.ref)),
struct.get("call_number", default.call_number),
SourceMediaType.from_struct(struct.get("media_type", {})),
struct.get("private", default.private),
)
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -60,59 +60,6 @@ class Researcher(LocationBase):
return (LocationBase.serialize(self), return (LocationBase.serialize(self),
self.name, self.addr, self.email) self.name, self.addr, self.email)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Researcher",
"street": self.street,
"locality": self.locality,
"city": self.city,
"county": self.county,
"state": self.state,
"country": self.country,
"postal": self.postal,
"phone": self.phone,
"name": self.name,
"address": self.addr,
"email": self.email}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Researcher()
return (struct.get("street", default.street),
struct.get("locality", default.locality),
struct.get("city", default.city),
struct.get("country", default.country),
struct.get("state", default.state),
struct.get("country", default.country),
struct.get("postal", default.postal),
struct.get("phone", default.phone),
struct.get("name", default.name),
struct.get("address", default.addr),
struct.get("email", default.email))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -59,43 +59,6 @@ class SecondaryObject(BaseObject):
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.
""" """
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def is_equal(self, source): def is_equal(self, source):
return self.serialize() == source.serialize() return self.serialize() == source.serialize()

View File

@ -121,67 +121,6 @@ class Source(MediaBase, NoteBase, SrcAttributeBase, IndirectCitationBase,
"private": bool "private": bool
} }
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Source",
"handle": Handle("Source", self.handle),
"gramps_id": self.gramps_id,
"title": str(self.title),
"author": str(self.author),
"pubinfo": str(self.pubinfo),
"note_list": NoteBase.to_struct(self),
"media_list": MediaBase.to_struct(self),
"abbrev": str(self.abbrev),
"change": self.change,
"srcattr_list": SrcAttributeBase.to_struct(self),
"reporef_list": [rr.to_struct() for rr in self.reporef_list],
"tag_list": TagBase.to_struct(self),
"private": self.private}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
from .srcattribute import SrcAttribute
default = Source()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("gramps_id", default.gramps_id),
struct.get("title", default.title),
struct.get("author", default.author),
struct.get("pubinfo", default.pubinfo),
NoteBase.from_struct(struct.get("note_list",
default.note_list)),
MediaBase.from_struct(struct.get("media_list",
default.media_list)),
struct.get("abbrev", default.abbrev),
struct.get("change", default.change),
SrcAttributeBase.from_struct(struct.get("srcattr_list", {})),
[RepoRef.from_struct(rr)
for rr in struct.get("reporef_list", default.reporef_list)],
TagBase.from_struct(struct.get("tag_list", default.tag_list)),
struct.get("private", default.private))
def unserialize(self, data): def unserialize(self, data):
""" """
Convert the data held in a tuple created by the serialize method Convert the data held in a tuple created by the serialize method

View File

@ -288,47 +288,6 @@ class StyledText:
return (self._string, the_tags) return (self._string, the_tags)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:return: Returns a struct containing the data of the object.
:rtype: dict
"""
if self._tags:
the_tags = [tag.to_struct() for tag in self._tags]
else:
the_tags = []
return {"_class": "StyledText",
"string": self._string,
"tags": the_tags}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:return: Returns a serialized object
"""
default = StyledText()
return (struct.get("string", default.string),
[StyledTextTag.from_struct(t)
for t in struct.get("tags", default.tags)])
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
""" """

View File

@ -72,43 +72,6 @@ class StyledTextTag:
""" """
return (self.name.serialize(), self.value, self.ranges) return (self.name.serialize(), self.value, self.ranges)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:return: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "StyledTextTag",
"name": self.name.to_struct(),
"value": self.value,
"ranges": self.ranges}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:return: Returns a serialized object
"""
default = StyledTextTag()
return (StyledTextTagType.from_struct(struct.get("name", {})),
struct.get("value", default.value),
struct.get("ranges", default.ranges))
def unserialize(self, data): def unserialize(self, data):
"""Convert a serialized tuple of data to an object. """Convert a serialized tuple of data to an object.

View File

@ -71,33 +71,6 @@ class Surname(SecondaryObject):
return (self.surname, self.prefix, self.primary, return (self.surname, self.prefix, self.primary,
self.origintype.serialize(), self.connector) self.origintype.serialize(), self.connector)
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Surname",
"surname": self.surname,
"prefix": self.prefix,
"primary": self.primary,
"origintype": self.origintype.to_struct(),
"connector": self.connector}
@classmethod @classmethod
def get_schema(cls): def get_schema(cls):
return { return {
@ -119,20 +92,6 @@ class Surname(SecondaryObject):
"connector": _("Connector") "connector": _("Connector")
} }
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Surname()
return (struct.get("surname", default.surname),
struct.get("prefix", default.prefix),
struct.get("primary", default.primary),
NameOriginType.from_struct(struct.get("origintype", {})),
struct.get("connector", default.connector))
def is_empty(self): def is_empty(self):
""" """
Indicate if the surname is empty. Indicate if the surname is empty.

View File

@ -60,37 +60,6 @@ class SurnameBase:
""" """
return [surname.serialize() for surname in self.surname_list] return [surname.serialize() for surname in self.surname_list]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [surname.to_struct() for surname in self.surname_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Surname.from_struct(surname) for surname in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -92,43 +92,6 @@ class TableObject(BaseObject):
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.
""" """
@abstractmethod
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
"""
@abstractmethod
def from_struct(self, struct):
"""
Given a struct data representation, return an object of this type.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns an object of this type.
"""
def get_change_time(self): def get_change_time(self):
""" """
Return the time that the data was last changed. Return the time that the data was last changed.

View File

@ -225,46 +225,5 @@ class Tag(TableObject):
""" """
return self.__priority return self.__priority
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Tag",
"handle": Handle("Tag", self.handle),
"name": self.__name,
"color": self.__color,
"priority": self.__priority,
"change": self.change}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Tag()
return (Handle.from_struct(struct.get("handle", default.handle)),
struct.get("name", default.name),
struct.get("color", default.color),
struct.get("priority", default.priority),
struct.get("change", default.change))
priority = property(get_priority, set_priority, None, priority = property(get_priority, set_priority, None,
'Returns or sets priority of the tag') 'Returns or sets priority of the tag')

View File

@ -55,37 +55,6 @@ class TagBase:
""" """
return self.tag_list return self.tag_list
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [Handle('Tag', t) for t in self.tag_list]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Handle.from_struct(t) for t in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.

View File

@ -67,45 +67,6 @@ class Url(SecondaryObject, PrivacyBase):
def serialize(self): def serialize(self):
return (self.private, self.path, self.desc, self.type.serialize()) return (self.private, self.path, self.desc, self.type.serialize())
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: dict
"""
return {"_class": "Url",
"private": self.private,
"path": self.path,
"desc": self.desc,
"type": self.type.to_struct()}
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
default = Url()
return (struct.get("private", default.private),
struct.get("path", default.path),
struct.get("desc", default.desc),
UrlType.from_struct(struct.get("type", {})))
def unserialize(self, data): def unserialize(self, data):
(self.private, self.path, self.desc, type_value) = data (self.private, self.path, self.desc, type_value) = data
self.type.unserialize(type_value) self.type.unserialize(type_value)

View File

@ -58,37 +58,6 @@ class UrlBase:
""" """
return [url.serialize() for url in self.urls] return [url.serialize() for url in self.urls]
def to_struct(self):
"""
Convert the data held in this object to a structure (eg,
struct) that represents all the data elements.
This method is used to recursively convert the object into a
self-documenting form that can easily be used for various
purposes, including diffs and queries.
These structures may be primitive Python types (string,
integer, boolean, etc.) or complex Python types (lists,
tuples, or dicts). If the return type is a dict, then the keys
of the dict match the fieldname of the object. If the return
struct (or value of a dict key) is a list, then it is a list
of structs. Otherwise, the struct is just the value of the
attribute.
:returns: Returns a struct containing the data of the object.
:rtype: list
"""
return [url.to_struct() for url in self.urls]
@classmethod
def from_struct(cls, struct):
"""
Given a struct data representation, return a serialized object.
:returns: Returns a serialized object
"""
return [Url.from_struct(url) for url in struct]
def unserialize(self, data): def unserialize(self, data):
""" """
Convert a serialized tuple of data to an object. Convert a serialized tuple of data to an object.