Skip to content

Commit a029556

Browse files
committed
Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.
2 parents d7b13ae + e4d9bb6 commit a029556

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Lib/pydoc.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class or function within a module or module in a package. If the
6464
import sys
6565
import time
6666
import tokenize
67+
import urllib.parse
6768
import warnings
6869
from collections import deque
6970
from reprlib import Repr
@@ -646,10 +647,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
646647
head = '<big><big><strong>%s</strong></big></big>' % linkedname
647648
try:
648649
path = inspect.getabsfile(object)
649-
url = path
650-
if sys.platform == 'win32':
651-
import nturl2path
652-
url = nturl2path.pathname2url(path)
650+
url = urllib.parse.quote(path)
653651
filelink = self.filelink(url, path)
654652
except TypeError:
655653
filelink = '(built-in)'
@@ -2350,7 +2348,7 @@ def bltinlink(name):
23502348

23512349
def html_getfile(path):
23522350
"""Get and display a source file listing safely."""
2353-
path = path.replace('%20', ' ')
2351+
path = urllib.parse.unquote(path)
23542352
with tokenize.open(path) as fp:
23552353
lines = html.escape(fp.read())
23562354
body = '<pre>%s</pre>' % lines

Lib/test/test_pydoc.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import time
1414
import types
1515
import unittest
16+
import urllib.parse
1617
import xml.etree
1718
import textwrap
1819
from io import StringIO
@@ -396,11 +397,7 @@ class PydocDocTest(unittest.TestCase):
396397
def test_html_doc(self):
397398
result, doc_loc = get_pydoc_html(pydoc_mod)
398399
mod_file = inspect.getabsfile(pydoc_mod)
399-
if sys.platform == 'win32':
400-
import nturl2path
401-
mod_url = nturl2path.pathname2url(mod_file)
402-
else:
403-
mod_url = mod_file
400+
mod_url = urllib.parse.quote(mod_file)
404401
expected_html = expected_html_pattern % (
405402
(mod_url, mod_file, doc_loc) +
406403
expected_html_data_docstrings)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Core and Builtins
108108
Library
109109
-------
110110

111+
- Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.
112+
111113
- Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
112114
if the number of received bytes is negative.
113115

0 commit comments

Comments
 (0)