From: Martin Panter Date: Sun, 12 Jun 2016 05:25:16 +0000 (+0000) Subject: #16484: Change PYTHONDOCS to "https:", and fix links to use lowercase X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e52140caf1dda7313e59e1a076192aa501492159;p=python #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 743769fe3e..57521f7902 100644 --- a/Doc/library/pydoc.rst +++ b/Doc/library/pydoc.rst @@ -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. diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 9316fff151..b4b190f3f9 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -28,7 +28,7 @@ to a file named ".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 diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 6cfe7e7853..7188d0af75 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -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 = "
Module Docs" 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) diff --git a/Misc/ACKS b/Misc/ACKS index ee3a465e34..c6a4bc02f7 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index 72e5396ca2..55f44bf69f 100644 --- 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? ================================================