]> granicus.if.org Git - python/commitdiff
#16484: Change PYTHONDOCS to "https:", and fix links to use lowercase
authorMartin Panter <vadmium+py@gmail.com>
Sun, 12 Jun 2016 05:25:16 +0000 (05:25 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Sun, 12 Jun 2016 05:25:16 +0000 (05:25 +0000)
Implementation by Sean Rodman; test by Kaushik Nadikuditi.

Doc/library/pydoc.rst
Lib/pydoc.py
Lib/test/test_pydoc.py
Misc/ACKS
Misc/NEWS

index 743769fe3e5d30725fafa09b19f3f14f95803952..57521f790224954caae0df427583c251de4ec08e 100644 (file)
@@ -80,7 +80,7 @@ documents precisely the version of the module you would get if you started the
 Python interpreter and typed ``import spam``.
 
 Module docs for core modules are assumed to reside in
-http://docs.python.org/library/.  This can be overridden by setting the
+https://docs.python.org/library/.  This can be overridden by setting the
 :envvar:`PYTHONDOCS` environment variable to a different URL or to a local
 directory containing the Library Reference Manual pages.
 
index 9316fff1515017ebf30c39c34266f4c5c2808a75..b4b190f3f9a6597b08c5ed2984e34a123d661c7d 100755 (executable)
@@ -28,7 +28,7 @@ to a file named "<name>.html".
 
 Module docs for core modules are assumed to be in
 
-    http://docs.python.org/library/
+    https://docs.python.org/library/
 
 This can be overridden by setting the PYTHONDOCS environment variable
 to a different URL or to a local directory containing the Library
@@ -374,7 +374,9 @@ class Doc:
 
     docmodule = docclass = docroutine = docother = docproperty = docdata = fail
 
-    def getdocloc(self, object):
+    def getdocloc(self, object,
+                  basedir=os.path.join(sys.exec_prefix, "lib",
+                                       "python"+sys.version[0:3])):
         """Return the location of module docs or None"""
 
         try:
@@ -383,9 +385,8 @@ class Doc:
             file = '(built-in)'
 
         docloc = os.environ.get("PYTHONDOCS",
-                                "http://docs.python.org/library")
-        basedir = os.path.join(sys.exec_prefix, "lib",
-                               "python"+sys.version[0:3])
+                                "https://docs.python.org/library")
+        basedir = os.path.normcase(basedir)
         if (isinstance(object, type(os)) and
             (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
                                  'marshal', 'posix', 'signal', 'sys',
@@ -393,10 +394,10 @@ class Doc:
              (file.startswith(basedir) and
               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__)
+            if docloc.startswith(("http://", "https://")):
+                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
index 6cfe7e785363aa1c3b0ae862bc9b009206ddc0e9..7188d0af75a1342673df3d6a3a3eadda22a2b08c 100644 (file)
@@ -13,6 +13,7 @@ import unittest
 import xml.etree
 import types
 import test.test_support
+import xml.etree.ElementTree
 from collections import namedtuple
 from test.script_helper import assert_python_ok
 from test.test_support import (TESTFN, rmtree, reap_children, captured_stdout,
@@ -253,6 +254,14 @@ def get_pydoc_html(module):
         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 = 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()
@@ -331,6 +340,11 @@ class PydocDocTest(unittest.TestCase):
             print_diffs(expected_text, result)
             self.fail("outputs are not equal, see diff above")
 
+    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)
index ee3a465e34aa14f35ea67fd6414b4a61626b0e75..c6a4bc02f7ff12a34bd3578bee8cb40fba4b2224 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -965,6 +965,7 @@ Louis Munro
 R. David Murray
 Matti Mäki
 Jörg Müller
+Kaushik N
 Dale Nagata
 John Nagle
 Takahiro Nakayama
index 72e5396ca247f2a2d1dc341cca34caa7f24c67d3..55f44bf69fdc79eaa6933de4e0ded437f850e284 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,13 @@ Core and Builtins
 Library
 -------
 
+Documentation
+-------------
+
+- Issue #16484: Change the default PYTHONDOCS URL to "https:", and fix the
+  resulting links to use lowercase.  Patch by Sean Rodman, test by Kaushik
+  Nadikuditi.
+
 
 What's New in Python 2.7.12 release candidate 1?
 ================================================