我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用pydoc.__file__()。
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 run_pydoc(module_name, *args, **env): """ Runs pydoc on the specified module. Returns the stripped output of pydoc. """ args = args + (module_name,) # do not write bytecode files to avoid caching errors rc, out, err = assert_python_ok('-B', pydoc.__file__, *args, **env) return out.strip()
def test_url_requests(self): # Test for the correct title in the html pages returned. # This tests the different parts of the URL handler without # getting too picky about the exact html. requests = [ ("", "Pydoc: Index of Modules"), ("get?key=", "Pydoc: Index of Modules"), ("index", "Pydoc: Index of Modules"), ("topics", "Pydoc: Topics"), ("keywords", "Pydoc: Keywords"), ("pydoc", "Pydoc: module pydoc"), ("get?key=pydoc", "Pydoc: module pydoc"), ("search?key=pydoc", "Pydoc: Search Results"), ("topic?key=def", "Pydoc: KEYWORD def"), ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"), ("foobar", "Pydoc: Error - foobar"), ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"), ] for url, title in requests: text = pydoc._url_handler(url, "text/html") result = get_html_title(text) self.assertEqual(result, title) path = string.__file__ title = "Pydoc: getfile " + path url = "getfile?key=" + path text = pydoc._url_handler(url, "text/html") result = get_html_title(text) self.assertEqual(result, title)
def _restricted_walk_packages(self, walk_packages, path=None): """ A version of pkgutil.walk_packages() that will restrict itself to a given path. """ default_path = path or [os.path.dirname(__file__)] def wrapper(path=None, prefix='', onerror=None): return walk_packages(path or default_path, prefix, onerror) return wrapper
def test_url_requests(self): # Test for the correct title in the html pages returned. # This tests the different parts of the URL handler without # getting too picky about the exact html. requests = [ ("", "Pydoc: Index of Modules"), ("get?key=", "Pydoc: Index of Modules"), ("index", "Pydoc: Index of Modules"), ("topics", "Pydoc: Topics"), ("keywords", "Pydoc: Keywords"), ("pydoc", "Pydoc: module pydoc"), ("get?key=pydoc", "Pydoc: module pydoc"), ("search?key=pydoc", "Pydoc: Search Results"), ("topic?key=def", "Pydoc: KEYWORD def"), ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"), ("foobar", "Pydoc: Error - foobar"), ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"), ] with self.restrict_walk_packages(): for url, title in requests: text = pydoc._url_handler(url, "text/html") result = get_html_title(text) self.assertEqual(result, title, text) path = string.__file__ title = "Pydoc: getfile " + path url = "getfile?key=" + path text = pydoc._url_handler(url, "text/html") result = get_html_title(text) self.assertEqual(result, title)
def test_importfile(self): loaded_pydoc = pydoc.importfile(pydoc.__file__) self.assertIsNot(loaded_pydoc, pydoc) self.assertEqual(loaded_pydoc.__name__, 'pydoc') self.assertEqual(loaded_pydoc.__file__, pydoc.__file__) self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
def test_url_requests(self): # Test for the correct title in the html pages returned. # This tests the different parts of the URL handler without # getting too picky about the exact html. requests = [ ("", "Pydoc: Index of Modules"), ("get?key=", "Pydoc: Index of Modules"), ("index", "Pydoc: Index of Modules"), ("topics", "Pydoc: Topics"), ("keywords", "Pydoc: Keywords"), ("pydoc", "Pydoc: module pydoc"), ("get?key=pydoc", "Pydoc: module pydoc"), ("search?key=pydoc", "Pydoc: Search Results"), ("topic?key=def", "Pydoc: KEYWORD def"), ("topic?key=STRINGS", "Pydoc: TOPIC STRINGS"), ("foobar", "Pydoc: Error - foobar"), ("getfile?key=foobar", "Pydoc: Error - getfile?key=foobar"), ] with self.restrict_walk_packages(): for url, title in requests: self.call_url_handler(url, title) path = string.__file__ title = "Pydoc: getfile " + path url = "getfile?key=" + path self.call_url_handler(url, title)