dhlab-basel / alephmarcreader

Python Library to read Marc obtained from Aleph
GNU Affero General Public License v3.0
1 stars 0 forks source link

Provide implementation for MarcXML #8

Closed tobiasschweizer closed 5 years ago

tobiasschweizer commented 5 years ago

We could provide an implementation for MarcXML, derived from an abstract base class:

import abc

# compatible with Python 2 *and* 3:
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})

class AbstractMarcReader(ABC):

    @abc.abstractmethod
    def __init__(self, file_path):
        pass

    @abc.abstractmethod
    def do_something(self):
        print("Some implementation!")

class Marc21Reader(AbstractMarcReader):
    def __init__(self, file_path):
        super(Marc21Reader, self).__init__(file_path)
        pass

    def do_something(self):
        super(Marc21Reader, self).do_something()
        print("The enrichment from Marc21Reader")

class MarcXMLReader(AbstractMarcReader):
    def __init__(self, file_path):
        super(MarcXMLReader, self).__init__(file_path)
        pass

    def do_something(self):
        super(MarcXMLReader, self).do_something()
        print("The enrichment from MarcXMLReader")

x = Marc21Reader('test')
x.do_something()

y = MarcXMLReader('test')
y.do_something()

see https://stackoverflow.com/questions/35673474/using-abc-abcmeta-in-a-way-it-is-compatible-both-with-python-2-7-and-python-3-5 and https://www.python-course.eu/python3_abstract_classes.php