Skip to content

Commit 5a2112f

Browse files
Address reviews
1 parent e70e84c commit 5a2112f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Lib/pydoc.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ def __init__(self):
598598
self.maxdict = 10
599599
self.maxstring = self.maxother = 100
600600

601+
def escape(self, text):
602+
return replace(text, '&', '&amp;', '<', '&lt;', '>', '&gt;')
603+
601604
def repr(self, object):
602605
return Repr.repr(self, object)
603606

@@ -636,6 +639,7 @@ class HTMLDoc(Doc):
636639

637640
_repr_instance = HTMLRepr()
638641
repr = _repr_instance.repr
642+
escape = _repr_instance.escape
639643

640644
def page(self, title, contents):
641645
"""Format an HTML page."""
@@ -2636,21 +2640,21 @@ def html_topicpage(topic):
26362640
title = 'SYMBOL'
26372641
contents, xrefs = htmlhelp._getsymbol(topic)
26382642
else:
2639-
raise ValueError('could not find topic %s' % repr(topic))
2643+
raise ValueError(f'could not find topic {topic!r}')
26402644
heading = html.heading(
2641-
'<strong class="title">%s</strong>' % title,
2645+
f'<strong class="title">{title}</strong>',
26422646
)
2643-
contents = '<pre>%s</pre>' % html.markup(contents)
2647+
contents = f'<pre>{html.markup(contents)}</pre>'
26442648
contents = html.bigsection(topic , 'index', contents)
26452649
if xrefs:
26462650
xrefs = sorted(xrefs.split())
26472651

26482652
def bltinlink(name):
2649-
return '<a href="topic?key=%s">%s</a>' % (html_escape(name), html_escape(name))
2653+
return f'<a href="topic?key={html_escape(name)}>{html_escape(name)}</a>'
26502654

26512655
xrefs = html.multicolumn(xrefs, bltinlink)
26522656
xrefs = html.section('Related help topics: ', 'index', xrefs)
2653-
return ('%s %s' % (title, topic),
2657+
return (f'{title} {topic}',
26542658
''.join((heading, contents, xrefs)))
26552659

26562660
def html_getobj(url):

0 commit comments

Comments
 (0)