Skip to content

Commit e4d9bb6

Browse files
committed
Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.
1 parent 46b3d9b commit e4d9bb6

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
@@ -648,10 +649,7 @@ def docmodule(self, object, name=None, mod=None, *ignored):
648649
head = '<big><big><strong>%s</strong></big></big>' % linkedname
649650
try:
650651
path = inspect.getabsfile(object)
651-
url = path
652-
if sys.platform == 'win32':
653-
import nturl2path
654-
url = nturl2path.pathname2url(path)
652+
url = urllib.parse.quote(path)
655653
filelink = self.filelink(url, path)
656654
except TypeError:
657655
filelink = '(built-in)'
@@ -2353,7 +2351,7 @@ def bltinlink(name):
23532351

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

Lib/test/test_pydoc.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import time
1515
import types
1616
import unittest
17+
import urllib.parse
1718
import xml.etree
1819
import textwrap
1920
from io import StringIO
@@ -406,11 +407,7 @@ class PydocDocTest(unittest.TestCase):
406407
def test_html_doc(self):
407408
result, doc_loc = get_pydoc_html(pydoc_mod)
408409
mod_file = inspect.getabsfile(pydoc_mod)
409-
if sys.platform == 'win32':
410-
import nturl2path
411-
mod_url = nturl2path.pathname2url(mod_file)
412-
else:
413-
mod_url = mod_file
410+
mod_url = urllib.parse.quote(mod_file)
414411
expected_html = expected_html_pattern % (
415412
(mod_url, mod_file, doc_loc) +
416413
expected_html_data_docstrings)

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.
31+
3032
- Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
3133
if the number of received bytes is negative.
3234

0 commit comments

Comments
 (0)