[Python-checkins] cpython (3.4): Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.

zach.ware python-checkins at python.org
Thu Jul 10 18:21:56 CEST 2014


http://hg.python.org/cpython/rev/74c7a186ffdd
changeset:   91625:74c7a186ffdd
branch:      3.4
parent:      91623:220d5fdbe22e
user:        Zachary Ware <zachary.ware at gmail.com>
date:        Thu Jul 10 11:18:00 2014 -0500
summary:
  Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.

files:
  Lib/pydoc.py           |  8 +++-----
  Lib/test/test_pydoc.py |  7 ++-----
  Misc/NEWS              |  2 ++
  3 files changed, 7 insertions(+), 10 deletions(-)


diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -64,6 +64,7 @@
 import sys
 import time
 import tokenize
+import urllib.parse
 import warnings
 from collections import deque
 from reprlib import Repr
@@ -648,10 +649,7 @@
         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)'
@@ -2353,7 +2351,7 @@
 
     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
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -14,6 +14,7 @@
 import time
 import types
 import unittest
+import urllib.parse
 import xml.etree
 import textwrap
 from io import StringIO
@@ -406,11 +407,7 @@
     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)
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,8 @@
 Library
 -------
 
+- Issue #21942: Fixed source file viewing in pydoc's server mode on Windows.
+
 - Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
   if the number of received bytes is negative.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list