[Epydoc-commits] SF.net SVN: epydoc: [1300] trunk/epydoc/src/epydoc/docwriter
Brought to you by:
edloper
From: <ed...@us...> - 2006-08-23 05:25:20
|
Revision: 1300 Author: edloper Date: 2006-08-22 22:25:13 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/epydoc/?rev=1300&view=rev Log Message: ----------- - Modified html_colorize.PythonSourceColorizer constructor to take a name_to_docs dictionary as an argument, rather than recomputing it each time. The name_to_docs dictionary is computed by HTMLWriter, and pre-sorted. This optimization should make source colorization faster. Based on a patch provided by Daniel von Dincklage. - In PythonSourceColorizer, check to make sure docindex, url_func, etc. exist before using them. Modified Paths: -------------- trunk/epydoc/src/epydoc/docwriter/html.py trunk/epydoc/src/epydoc/docwriter/html_colorize.py Modified: trunk/epydoc/src/epydoc/docwriter/html.py =================================================================== --- trunk/epydoc/src/epydoc/docwriter/html.py 2006-08-23 02:04:55 UTC (rev 1299) +++ trunk/epydoc/src/epydoc/docwriter/html.py 2006-08-23 05:25:13 UTC (rev 1300) @@ -565,9 +565,22 @@ # Write source code files. if self._incl_sourcecode: + # Build a map from short names to APIDocs, used when + # linking names in the source code. + name_to_docs = {} + for api_doc in self.indexed_docs: + if (api_doc.canonical_name is not None and + self.url(api_doc) is not None): + name = api_doc.canonical_name[-1] + name_to_docs.setdefault(name, []).append(api_doc) + # Sort each entry of the name_to_docs list. + for doc_list in name_to_docs.values(): + doc_list.sort() + # Write the source code for each module. for doc in self.modules_with_sourcecode: filename = urllib.unquote(self.pysrc_url(doc)) - self._write(self.write_sourcecode, directory, filename, doc) + self._write(self.write_sourcecode, directory, filename, doc, + name_to_docs) # Write the index.html files. # (this must be done last, since it might copy another file) @@ -682,7 +695,7 @@ #{ 2.??. Source Code Pages #//////////////////////////////////////////////////////////// - def write_sourcecode(self, out, doc): + def write_sourcecode(self, out, doc, name_to_docs): filename = doc.filename name = str(doc.canonical_name) @@ -696,7 +709,7 @@ self.href(doc, label='%s %s' % (self.doc_kind(doc), name))) out('<pre class="py-src">\n') out(PythonSourceColorizer(filename, name, self.docindex, - self.indexed_docs, self.url).colorize()) + self.url, name_to_docs).colorize()) out('</pre>\n<br />\n') # Footer Modified: trunk/epydoc/src/epydoc/docwriter/html_colorize.py =================================================================== --- trunk/epydoc/src/epydoc/docwriter/html_colorize.py 2006-08-23 02:04:55 UTC (rev 1299) +++ trunk/epydoc/src/epydoc/docwriter/html_colorize.py 2006-08-23 05:25:13 UTC (rev 1300) @@ -488,7 +488,6 @@ </script> ''' - import tokenize, sys, token, cgi, keyword try: from cStringIO import StringIO except: from StringIO import StringIO @@ -602,7 +601,7 @@ GUESS_LINK_TARGETS = True def __init__(self, module_filename, module_name, - docindex=None, api_docs=None, url_func=None): + docindex=None, url_func=None, name_to_docs=None): """ Create a new HTML colorizer for the specified module. @@ -622,17 +621,18 @@ #: The dotted name of the module we're colorizing. self.module_name = module_name + #: A docindex, used to create href links from identifiers to + #: the API documentation for their values. self.docindex = docindex - #: A mapping from short names to lists of ValueDoc. - self.name_to_docs = {} - for api_doc in api_docs: - if (api_doc.canonical_name is not None and - url_func(api_doc) is not None): - name = api_doc.canonical_name[-1] - self.name_to_docs.setdefault(name,set()).add(api_doc) + #: A mapping from short names to lists of ValueDoc, used to + #: decide which values an identifier might map to when creating + #: href links from identifiers to the API docs for their values. + self.name_to_docs = name_to_docs - #: A function that maps APIDoc -> URL + #: A function that maps APIDoc -> URL, used to create href + #: links from identifiers to the API documentation for their + #: values. self.url_func = url_func #: The index in C{text} of the last character of the last @@ -935,7 +935,8 @@ # a function, then that function is our context, not # the namespace that contains it. [xx] this isn't always # the right thing to do. - if self.GUESS_LINK_TARGETS: + if (self.GUESS_LINK_TARGETS and self.docindex is not None + and self.url_func is not None): context = [n for n in self.context if n is not None] container = DottedName(self.module_name, *context) doc = self.docindex.get_vardoc(container+toktext) @@ -943,8 +944,9 @@ url = self.url_func(doc) # Otherwise, check the name_to_docs index to see what # else this name might refer to. - if url is None: - docs = sorted(self.name_to_docs.get(toktext, [])) + if (url is None and self.name_to_docs is not None + and self.url_func is not None): + docs = self.name_to_docs.get(toktext, []) if docs: tooltip='\n'.join([str(d.canonical_name) for d in docs]) @@ -1074,7 +1076,8 @@ elif isinstance(doc, StaticMethodDoc): return 'Static Method' elif isinstance(doc, RoutineDoc): - if isinstance(self.docindex.container(doc), ClassDoc): + if (self.docindex is not None and + isinstance(self.docindex.container(doc), ClassDoc)): return 'Method' else: return 'Function' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |