You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
554 B

  1. import abc
  2. from typing import Dict
  3. from pydantic import BaseModel, validator
  4. class BaseData(BaseModel, abc.ABC):
  5. filename: str
  6. meta: Dict = {}
  7. @classmethod
  8. def parse(cls, **kwargs):
  9. return cls.parse_obj(kwargs)
  10. def __hash__(self):
  11. return hash(tuple(self.dict()))
  12. class TextData(BaseData):
  13. text: str
  14. @validator('text')
  15. def text_is_not_empty(cls, value: str):
  16. if value:
  17. return value
  18. else:
  19. raise ValueError('is not empty.')
  20. class FileData(BaseData):
  21. pass