pep.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # $Id: pep.py 9037 2022-03-05 23:31:10Z milde $
  2. # Author: David Goodger <goodger@python.org>
  3. # Copyright: This module has been placed in the public domain.
  4. """
  5. Python Enhancement Proposal (PEP) Reader.
  6. """
  7. __docformat__ = 'reStructuredText'
  8. from docutils.readers import standalone
  9. from docutils.transforms import peps, frontmatter
  10. from docutils.parsers import rst
  11. class Reader(standalone.Reader):
  12. supported = ('pep',)
  13. """Contexts this reader supports."""
  14. settings_spec = (
  15. 'PEP Reader Option Defaults',
  16. 'The --pep-references and --rfc-references options (for the '
  17. 'reStructuredText parser) are on by default.',
  18. ())
  19. config_section = 'pep reader'
  20. config_section_dependencies = ('readers', 'standalone reader')
  21. def get_transforms(self):
  22. transforms = standalone.Reader.get_transforms(self)
  23. # We have PEP-specific frontmatter handling.
  24. transforms.remove(frontmatter.DocTitle)
  25. transforms.remove(frontmatter.SectionSubTitle)
  26. transforms.remove(frontmatter.DocInfo)
  27. transforms.extend([peps.Headers, peps.Contents, peps.TargetNotes])
  28. return transforms
  29. settings_default_overrides = {'pep_references': 1, 'rfc_references': 1}
  30. inliner_class = rst.states.Inliner
  31. def __init__(self, parser=None, parser_name=None):
  32. """`parser` should be ``None``."""
  33. if parser is None:
  34. parser = rst.Parser(rfc2822=True, inliner=self.inliner_class())
  35. standalone.Reader.__init__(self, parser, '')