document_parser.py 664 B

123456789101112131415161718192021222324252627282930
  1. from abc import ABC, abstractmethod
  2. class DocumentParser(ABC):
  3. """文档解析器抽象基类"""
  4. @abstractmethod
  5. def parse(self, data: bytes) -> str:
  6. """
  7. 解析文档内容
  8. Args:
  9. data (bytes): 文档二进制数据
  10. Returns:
  11. str: 解析出的文本内容
  12. """
  13. pass
  14. @abstractmethod
  15. def supports(self, content_type: str) -> bool:
  16. """
  17. 检查是否支持指定的内容类型
  18. Args:
  19. content_type (str): 内容类型
  20. Returns:
  21. bool: 是否支持
  22. """
  23. pass