[Python-checkins] cpython (merge 3.5 -> default): Merge: #16484: Fix pydoc doc links to modules whose names are mixed case.

r.david.murray python-checkins at python.org
Fri Jun 3 19:29:58 EDT 2016


https://hg.python.org/cpython/rev/912b9aad0b45
changeset:   101670:912b9aad0b45
parent:      101668:dfb61cd916e3
parent:      101669:64e7c8531131
user:        R David Murray <rdmurray at bitdance.com>
date:        Fri Jun 03 19:29:18 2016 -0400
summary:
  Merge: #16484: Fix pydoc doc links to modules whose names are mixed case.

files:
  Lib/pydoc.py           |  12 ++++++------
  Lib/test/test_pydoc.py |  14 ++++++++++++++
  Misc/ACKS              |   1 +
  3 files changed, 21 insertions(+), 6 deletions(-)


diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -366,7 +366,7 @@
 class Doc:
 
     PYTHONDOCS = os.environ.get("PYTHONDOCS",
-                                "http://docs.python.org/%d.%d/library"
+                                "https://docs.python.org/%d.%d/library"
                                 % sys.version_info[:2])
 
     def document(self, object, name=None, *args):
@@ -395,7 +395,9 @@
 
     docmodule = docclass = docroutine = docother = docproperty = docdata = fail
 
-    def getdocloc(self, object):
+    def getdocloc(self, object,
+                  basedir=os.path.join(sys.base_exec_prefix, "lib",
+                                       "python%d.%d" %  sys.version_info[:2])):
         """Return the location of module docs or None"""
 
         try:
@@ -405,8 +407,6 @@
 
         docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)
 
-        basedir = os.path.join(sys.base_exec_prefix, "lib",
-                               "python%d.%d" %  sys.version_info[:2])
         if (isinstance(object, type(os)) and
             (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
                                  'marshal', 'posix', 'signal', 'sys',
@@ -415,9 +415,9 @@
               not file.startswith(os.path.join(basedir, 'site-packages')))) and
             object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
             if docloc.startswith("http://"):
-                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
+                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__.lower())
             else:
-                docloc = os.path.join(docloc, object.__name__ + ".html")
+                docloc = os.path.join(docloc, object.__name__.lower() + ".html")
         else:
             docloc = None
         return docloc
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
@@ -18,6 +18,7 @@
 import unittest
 import urllib.parse
 import xml.etree
+import xml.etree.ElementTree
 import textwrap
 from io import StringIO
 from collections import namedtuple
@@ -352,6 +353,14 @@
         loc = "<br><a href=\"" + loc + "\">Module Docs</a>"
     return output.strip(), loc
 
+def get_pydoc_link(module):
+    "Returns a documentation web link of a module"
+    dirname = os.path.dirname
+    basedir = os.path.join(dirname(dirname(__file__)))
+    doc = pydoc.TextDoc()
+    loc = doc.getdocloc(module, basedir=basedir)
+    return loc
+
 def get_pydoc_text(module):
     "Returns pydoc generated output as text"
     doc = pydoc.TextDoc()
@@ -443,6 +452,11 @@
         doc = pydoc.render_doc(BinaryInteger)
         self.assertIn('<BinaryInteger.zero: 0>', doc)
 
+    def test_mixed_case_module_names_are_lower_cased(self):
+        # issue16484
+        doc_link = get_pydoc_link(xml.etree.ElementTree)
+        self.assertIn('xml.etree.elementtree', doc_link)
+
     def test_issue8225(self):
         # Test issue8225 to ensure no doc link appears for xml.etree
         result, doc_loc = get_pydoc_text(xml.etree)
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1026,6 +1026,7 @@
 R. David Murray
 Matti Mäki
 Jörg Müller
+Kaushik N
 Dale Nagata
 John Nagle
 Takahiro Nakayama

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


More information about the Python-checkins mailing list