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
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:
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',
(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
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,
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()
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)