#16484: Change PYTHONDOCS to "https:", and fix links to use lowercase
Implementation by Sean Rodman; test by Kaushik Nadikuditi.
diff --git a/Doc/library/pydoc.rst b/Doc/library/pydoc.rst
index 743769f..57521f7 100644
--- a/Doc/library/pydoc.rst
+++ b/Doc/library/pydoc.rst
@@ -80,7 +80,7 @@
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.
diff --git a/Lib/pydoc.py b/Lib/pydoc.py
index 9316fff..b4b190f 100755
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -28,7 +28,7 @@
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 @@
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 @@
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 @@
(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
diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py
index 6cfe7e7..7188d0a 100644
--- a/Lib/test/test_pydoc.py
+++ b/Lib/test/test_pydoc.py
@@ -13,6 +13,7 @@
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 @@
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 @@
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)
diff --git a/Misc/ACKS b/Misc/ACKS
index ee3a465..c6a4bc0 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -965,6 +965,7 @@
R. David Murray
Matti Mäki
Jörg Müller
+Kaushik N
Dale Nagata
John Nagle
Takahiro Nakayama
diff --git a/Misc/NEWS b/Misc/NEWS
index 72e5396..55f44bf 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,13 @@
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?
================================================