comparison env/lib/python3.9/site-packages/docutils/writers/pep_html/__init__.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 # $Id: __init__.py 8412 2019-11-06 18:15:21Z milde $
2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
4
5 """
6 PEP HTML Writer.
7 """
8
9 __docformat__ = 'reStructuredText'
10
11
12 import sys
13 import os
14 import os.path
15 import codecs
16 import docutils
17 from docutils import frontend, nodes, utils, writers
18 from docutils.writers import html4css1
19
20
21 class Writer(html4css1.Writer):
22
23 default_stylesheet = 'pep.css'
24
25 default_stylesheet_path = utils.relative_path(
26 os.path.join(os.getcwd(), 'dummy'),
27 os.path.join(os.path.dirname(__file__), default_stylesheet))
28
29 default_template = 'template.txt'
30
31 default_template_path = utils.relative_path(
32 os.path.join(os.getcwd(), 'dummy'),
33 os.path.join(os.path.dirname(__file__), default_template))
34
35 settings_spec = html4css1.Writer.settings_spec + (
36 'PEP/HTML-Specific Options',
37 'For the PEP/HTML writer, the default value for the --stylesheet-path '
38 'option is "%s", and the default value for --template is "%s". '
39 'See HTML-Specific Options above.'
40 % (default_stylesheet_path, default_template_path),
41 (('Python\'s home URL. Default is "http://www.python.org".',
42 ['--python-home'],
43 {'default': 'http://www.python.org', 'metavar': '<URL>'}),
44 ('Home URL prefix for PEPs. Default is "." (current directory).',
45 ['--pep-home'],
46 {'default': '.', 'metavar': '<URL>'}),
47 # For testing.
48 (frontend.SUPPRESS_HELP,
49 ['--no-random'],
50 {'action': 'store_true', 'validator': frontend.validate_boolean}),))
51
52 settings_default_overrides = {'stylesheet_path': default_stylesheet_path,
53 'template': default_template_path,}
54
55 relative_path_settings = ('template',)
56
57 config_section = 'pep_html writer'
58 config_section_dependencies = ('writers', 'html writers',
59 'html4css1 writer')
60
61 def __init__(self):
62 html4css1.Writer.__init__(self)
63 self.translator_class = HTMLTranslator
64
65 def interpolation_dict(self):
66 subs = html4css1.Writer.interpolation_dict(self)
67 settings = self.document.settings
68 pyhome = settings.python_home
69 subs['pyhome'] = pyhome
70 subs['pephome'] = settings.pep_home
71 if pyhome == '..':
72 subs['pepindex'] = '.'
73 else:
74 subs['pepindex'] = pyhome + '/dev/peps'
75 index = self.document.first_child_matching_class(nodes.field_list)
76 header = self.document[index]
77 self.pepnum = header[0][1].astext()
78 subs['pep'] = self.pepnum
79 if settings.no_random:
80 subs['banner'] = 0
81 else:
82 import random
83 subs['banner'] = random.randrange(64)
84 try:
85 subs['pepnum'] = '%04i' % int(self.pepnum)
86 except ValueError:
87 subs['pepnum'] = self.pepnum
88 self.title = header[1][1].astext()
89 subs['title'] = self.title
90 subs['body'] = ''.join(
91 self.body_pre_docinfo + self.docinfo + self.body)
92 return subs
93
94 def assemble_parts(self):
95 html4css1.Writer.assemble_parts(self)
96 self.parts['title'] = [self.title]
97 self.parts['pepnum'] = self.pepnum
98
99
100 class HTMLTranslator(html4css1.HTMLTranslator):
101
102 def depart_field_list(self, node):
103 html4css1.HTMLTranslator.depart_field_list(self, node)
104 if 'rfc2822' in node['classes']:
105 self.body.append('<hr />\n')