diff --git a/gramps/gen/lib/baseobj.py b/gramps/gen/lib/baseobj.py index db5dbd692..acfe81e86 100644 --- a/gramps/gen/lib/baseobj.py +++ b/gramps/gen/lib/baseobj.py @@ -24,9 +24,10 @@ Base Object class for Gramps #------------------------------------------------------------------------- # -# standard python modules +# Standard Python modules # #------------------------------------------------------------------------- +from abc import ABCMeta, abstractmethod import re #------------------------------------------------------------------------- @@ -34,7 +35,7 @@ import re # Base Object # #------------------------------------------------------------------------- -class BaseObject: +class BaseObject(metaclass=ABCMeta): """ The BaseObject is the base class for all data objects in Gramps, whether primary or not. @@ -43,18 +44,19 @@ class BaseObject: searching through all available information. """ + @abstractmethod def serialize(self): """ Convert the object to a serialized tuple of data. """ - raise NotImplementedError + @abstractmethod def unserialize(self, data): """ Convert a serialized tuple of data to an object. """ - raise NotImplementedError + @abstractmethod def to_struct(self): """ Convert the data held in this object to a structure (eg, @@ -74,8 +76,8 @@ class BaseObject: :returns: Returns a struct containing the data of the object. """ - raise NotImplementedError + @abstractmethod def from_struct(self, struct): """ Given a struct data representation, return an object of this type. @@ -90,7 +92,6 @@ class BaseObject: :returns: Returns an object of this type. """ - raise NotImplementedError def matches_string(self, pattern, case_sensitive=False): """ diff --git a/gramps/gen/lib/primaryobj.py b/gramps/gen/lib/primaryobj.py index 162fcc5fa..3992aff31 100644 --- a/gramps/gen/lib/primaryobj.py +++ b/gramps/gen/lib/primaryobj.py @@ -23,6 +23,13 @@ Basic Primary Object class for Gramps. """ +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from abc import abstractmethod + #------------------------------------------------------------------------- # # Gramps modules @@ -71,18 +78,19 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase): else: self.gramps_id = None + @abstractmethod def serialize(self): """ Convert the object to a serialized tuple of data. """ - raise NotImplementedError + @abstractmethod def unserialize(self, data): """ Convert a serialized tuple of data to an object. """ - raise NotImplementedError + @abstractmethod def to_struct(self): """ Convert the data held in this object to a structure (eg, @@ -102,8 +110,8 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase): :returns: Returns a struct containing the data of the object. """ - raise NotImplementedError + @abstractmethod def from_struct(self, struct): """ Given a struct data representation, return an object of this type. @@ -118,7 +126,6 @@ class BasicPrimaryObject(TableObject, PrivacyBase, TagBase): :returns: Returns an object of this type. """ - raise NotImplementedError def set_gramps_id(self, gramps_id): """ @@ -259,18 +266,19 @@ class PrimaryObject(BasicPrimaryObject): """ BasicPrimaryObject.__init__(self, source) + @abstractmethod def serialize(self): """ Convert the object to a serialized tuple of data. """ - raise NotImplementedError + @abstractmethod def unserialize(self, data): """ Convert a serialized tuple of data to an object. """ - raise NotImplementedError + @abstractmethod def to_struct(self): """ Convert the data held in this object to a structure (eg, @@ -290,8 +298,8 @@ class PrimaryObject(BasicPrimaryObject): :returns: Returns a struct containing the data of the object. """ - raise NotImplementedError + @abstractmethod def from_struct(self, struct): """ Given a struct data representation, return an object of this type. @@ -306,7 +314,6 @@ class PrimaryObject(BasicPrimaryObject): :returns: Returns an object of this type. """ - raise NotImplementedError def has_handle_reference(self, classname, handle): """ diff --git a/gramps/gen/lib/refbase.py b/gramps/gen/lib/refbase.py index 3c8723397..0a0013705 100644 --- a/gramps/gen/lib/refbase.py +++ b/gramps/gen/lib/refbase.py @@ -22,12 +22,19 @@ Base Reference class for Gramps. """ +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from abc import ABCMeta, abstractmethod + #------------------------------------------------------------------------- # # RefBase class # #------------------------------------------------------------------------- -class RefBase: +class RefBase(metaclass=ABCMeta): """ Base reference class to manage references to other objects. @@ -62,6 +69,7 @@ class RefBase: self.ref = data return self + @abstractmethod def get_referenced_handles(self): """ Returns the list of (classname, handle) tuples for all directly @@ -71,7 +79,6 @@ class RefBase: objects. :rtype: list """ - raise NotImplementedError def set_reference_handle(self, handle): """ diff --git a/gramps/gen/lib/secondaryobj.py b/gramps/gen/lib/secondaryobj.py index 03162de01..36165e312 100644 --- a/gramps/gen/lib/secondaryobj.py +++ b/gramps/gen/lib/secondaryobj.py @@ -22,6 +22,13 @@ Secondary Object class for Gramps. """ +#------------------------------------------------------------------------- +# +# Standard Python modules +# +#------------------------------------------------------------------------- +from abc import abstractmethod + #------------------------------------------------------------------------- # # Gramps modules @@ -40,18 +47,19 @@ class SecondaryObject(BaseObject): database. """ + @abstractmethod def serialize(self): """ Convert the object to a serialized tuple of data. """ - raise NotImplementedError + @abstractmethod def unserialize(self, data): """ Convert a serialized tuple of data to an object. """ - raise NotImplementedError + @abstractmethod def to_struct(self): """ Convert the data held in this object to a structure (eg, @@ -71,8 +79,8 @@ class SecondaryObject(BaseObject): :returns: Returns a struct containing the data of the object. """ - raise NotImplementedError + @abstractmethod def from_struct(self, struct): """ Given a struct data representation, return an object of this type. @@ -87,7 +95,6 @@ class SecondaryObject(BaseObject): :returns: Returns an object of this type. """ - raise NotImplementedError def is_equal(self, source): return self.serialize() == source.serialize() diff --git a/gramps/gen/lib/tableobj.py b/gramps/gen/lib/tableobj.py index 8cad8972f..44abf3392 100644 --- a/gramps/gen/lib/tableobj.py +++ b/gramps/gen/lib/tableobj.py @@ -25,9 +25,10 @@ Table Object class for Gramps. #------------------------------------------------------------------------- # -# standard python modules +# Standard Python modules # #------------------------------------------------------------------------- +from abc import abstractmethod import time #------------------------------------------------------------------------- @@ -78,18 +79,19 @@ class TableObject(BaseObject): self.handle = None self.change = 0 + @abstractmethod def serialize(self): """ Convert the object to a serialized tuple of data. """ - raise NotImplementedError + @abstractmethod def unserialize(self, data): """ Convert a serialized tuple of data to an object. """ - raise NotImplementedError + @abstractmethod def to_struct(self): """ Convert the data held in this object to a structure (eg, @@ -109,8 +111,8 @@ class TableObject(BaseObject): :returns: Returns a struct containing the data of the object. """ - raise NotImplementedError + @abstractmethod def from_struct(self, struct): """ Given a struct data representation, return an object of this type. @@ -125,7 +127,6 @@ class TableObject(BaseObject): :returns: Returns an object of this type. """ - raise NotImplementedError def get_change_time(self): """