classEmlParser(InformalParserInterface): """Extract text from an email""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides InformalParserInterface.load_data_source()""" pass
defextract_text_from_email(self, full_file_path: str) -> dict: """A method defined only in EmlParser. Does not override InformalParserInterface.extract_text() """ pass
classParserMeta(type): """A Parser metaclass that will be used for parser class creation. """ def__instancecheck__(cls, instance): return cls.__subclasscheck__(type(instance))
def__subclasscheck__(cls, subclass): return (hasattr(subclass, 'load_data_source') and callable(subclass.load_data_source) and hasattr(subclass, 'extract_text') and callable(subclass.extract_text))
classUpdatedInformalParserInterface(metaclass=ParserMeta): """This interface is used for concrete classes to inherit from. There is no need to define the ParserMeta methods as any class as they are implicitly made available via .__subclasscheck__(). """ pass
classEmlParserNew: """Extract text from an email.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides UpdatedInformalParserInterface.load_data_source()""" pass
defextract_text_from_email(self, full_file_path: str) -> dict: """A method defined only in EmlParser. Does not override UpdatedInformalParserInterface.extract_text() """ pass
classPersonMeta(type): """A person metaclass""" def__instancecheck__(cls, instance): return cls.__subclasscheck__(type(instance))
def__subclasscheck__(cls, subclass): return (hasattr(subclass, 'name') and callable(subclass.name) and hasattr(subclass, 'age') and callable(subclass.age))
classPersonSuper: """A person superclass""" defname(self) -> str: pass
defage(self) -> int: pass
classPerson(metaclass=PersonMeta): """Person interface built from PersonMeta metaclass.""" pass
# Inheriting subclasses classEmployee(PersonSuper): """Inherits from PersonSuper PersonSuper will appear in Employee.__mro__ """ pass
classFriend: """Built implicitly from Person Friend is a virtual subclass of Person since both required methods exist. Person not in Friend.__mro__ """ defname(self): pass
classFormalParserInterface(metaclass=abc.ABCMeta): @classmethod def__subclasshook__(cls, subclass): return (hasattr(subclass, 'load_data_source') and callable(subclass.load_data_source) and hasattr(subclass, 'extract_text') and callable(subclass.extract_text))
classPdfParserNew: """Extract text from a PDF.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides FormalParserInterface.load_data_source()""" pass
classEmlParserNew: """Extract text from an email.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides FormalParserInterface.load_data_source()""" pass
defextract_text_from_email(self, full_file_path: str) -> dict: """A method defined only in EmlParser. Does not override FormalParserInterface.extract_text() """ pass
classFormalParserInterface(metaclass=abc.ABCMeta): @classmethod def__subclasshook__(cls, subclass): return (hasattr(subclass, 'load_data_source') and callable(subclass.load_data_source) and hasattr(subclass, 'extract_text') and callable(subclass.extract_text) or NotImplemented)
classPdfParserNew: """Extract text from a PDF.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides FormalParserInterface.load_data_source()""" pass
@FormalParserInterface.register classEmlParserNew: """Extract text from an email.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides FormalParserInterface.load_data_source()""" pass
defextract_text_from_email(self, full_file_path: str) -> dict: """A method defined only in EmlParser. Does not override FormalParserInterface.extract_text() """ pass
classFormalParserInterface(metaclass=abc.ABCMeta): @classmethod def__subclasshook__(cls, subclass): return (hasattr(subclass, 'load_data_source') and callable(subclass.load_data_source) and hasattr(subclass, 'extract_text') and callable(subclass.extract_text) or NotImplemented)
@abc.abstractmethod defload_data_source(self, path: str, file_name: str): """Load in the data set""" raise NotImplementedError
@abc.abstractmethod defextract_text(self, full_file_path: str): """Extract text from the data set""" raise NotImplementedError
classPdfParserNew(FormalParserInterface): """Extract text from a PDF.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides FormalParserInterface.load_data_source()""" pass
classEmlParserNew(FormalParserInterface): """Extract text from an email.""" defload_data_source(self, path: str, file_name: str) -> str: """Overrides FormalParserInterface.load_data_source()""" pass
defextract_text_from_email(self, full_file_path: str) -> dict: """A method defined only in EmlParser. Does not override FormalParserInterface.extract_text() """ pass
A big difference between Python and Go is that Go doesn’t have classes. Rather, Go is similar to C in that it uses the struct keyword to create structures. A structure is similar to a class in that a structure contains data and methods. However, unlike a class, all of the data and methods are publicly accessed. The concrete structs in Go will be used to implement the fileParserInterface.