base.py 558 B

12345678910111213141516171819202122232425
  1. # encoding=utf-8
  2. '''Base class for format writers'''
  3. import io
  4. __all__ = ['BaseWriter', 'registry']
  5. registry = {}
  6. class BaseWriter:
  7. def __init__(self, fp, *args, **kwargs):
  8. assert isinstance(fp, io.BufferedIOBase)
  9. self.fp = fp
  10. def write_header(self, site, *args, **kwargs):
  11. '''Write file headers and metadata'''
  12. pass
  13. def write_shortcode(self, shortcode, url, encoding):
  14. raise NotImplementedError
  15. def write_footer(self, *args, **kwargs):
  16. '''Write file footer and metadata'''
  17. pass