Debian Codegraph @

docutils/readers/pep.py

raw symbols SCIP
1 # $Id: pep.py 10136 2025-05-20 15:48:27Z milde $
2 # Author: David Goodger <[email protected]>
3 # Copyright: This module has been placed in the public domain.
4
5 """
6 Python Enhancement Proposal (PEP) Reader.
7 """
8
9 from __future__ import annotations
10
11 __docformat__ = 'reStructuredText'
12
13 from docutils.readers import standalone
14 from docutils.transforms import peps, frontmatter
15 from docutils.parsers import rst
16
17
18 class Reader(standalone.Reader):
19
20 supported = ('pep',)
21 """Contexts this reader supports."""
22
23 settings_spec = (
24 'PEP Reader Option Defaults',
25 'The --pep-references and --rfc-references options (for the '
26 'reStructuredText parser) are on by default.',
27 ())
28
29 config_section = 'pep reader'
30 config_section_dependencies = ('readers', 'standalone reader')
31
32 def get_transforms(self):
33 transforms = super().get_transforms()
34 # We have PEP-specific frontmatter handling.
35 transforms.remove(frontmatter.DocTitle)
36 transforms.remove(frontmatter.SectionSubTitle)
37 transforms.remove(frontmatter.DocInfo)
38 transforms.extend([peps.Headers, peps.Contents, peps.TargetNotes])
39 return transforms
40
41 settings_default_overrides = {'pep_references': True,
42 'rfc_references': True}
43
44 inliner_class = rst.states.Inliner
45
46 def __init__(self, parser=None, parser_name=None) -> None:
47 """`parser` should be ``None``, `parser_name` is ignored.
48
49 The default parser is "rst" with PEP-specific settings
50 (since Docutils 0.3). Since Docutils 0.22, `parser` is ignored,
51 if it is a `str` instance.
52 """
53 if parser is None or isinstance(parser, str):
54 parser = rst.Parser(rfc2822=True, inliner=self.inliner_class())
55 super().__init__(parser)