diff options
author | Zachary Ware <zachary.ware@gmail.com> | 2014-07-10 16:21:01 (GMT) |
---|---|---|
committer | Zachary Ware <zachary.ware@gmail.com> | 2014-07-10 16:21:01 (GMT) |
commit | fff80d984caa6d7f63ff1bb13d9c3d5261c0209f (patch) | |
tree | cfb43049705c9837ed40be2b8f4c26960c1a3bb9 /Lib | |
parent | f6e9f36e544ea7443bc3bdd959968e65817994e9 (diff) | |
parent | eb43214427b1ae6d7095bdd2333e9bc2220f9449 (diff) | |
download | cpython-fff80d984caa6d7f63ff1bb13d9c3d5261c0209f.zip cpython-fff80d984caa6d7f63ff1bb13d9c3d5261c0209f.tar.gz cpython-fff80d984caa6d7f63ff1bb13d9c3d5261c0209f.tar.bz2 |
Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/pydoc.py | 8 | ||||
-rw-r--r-- | Lib/test/test_pydoc.py | 7 |
2 files changed, 5 insertions, 10 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index adb15c4..4c67835 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -64,6 +64,7 @@ import re import sys import time import tokenize +import urllib.parse import warnings from collections import deque from reprlib import Repr @@ -646,10 +647,7 @@ class HTMLDoc(Doc): head = '<big><big><strong>%s</strong></big></big>' % linkedname try: path = inspect.getabsfile(object) - url = path - if sys.platform == 'win32': - import nturl2path - url = nturl2path.pathname2url(path) + url = urllib.parse.quote(path) filelink = self.filelink(url, path) except TypeError: filelink = '(built-in)' @@ -2350,7 +2348,7 @@ def _url_handler(url, content_type="text/html"): def html_getfile(path): """Get and display a source file listing safely.""" - path = path.replace('%20', ' ') + path = urllib.parse.unquote(path) with tokenize.open(path) as fp: lines = html.escape(fp.read()) body = '<pre>%s</pre>' % lines diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index e5794c8..bf808d3 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -13,6 +13,7 @@ import test.support import time import types import unittest +import urllib.parse import xml.etree import textwrap from io import StringIO @@ -396,11 +397,7 @@ class PydocDocTest(unittest.TestCase): def test_html_doc(self): result, doc_loc = get_pydoc_html(pydoc_mod) mod_file = inspect.getabsfile(pydoc_mod) - if sys.platform == 'win32': - import nturl2path - mod_url = nturl2path.pathname2url(mod_file) - else: - mod_url = mod_file + mod_url = urllib.parse.quote(mod_file) expected_html = expected_html_pattern % ( (mod_url, mod_file, doc_loc) + expected_html_data_docstrings) |