def _index(self, doctree): tag = string.lower(doctree.tag()) attr = "index_" + tag if hasattr(self, attr): exec "self.%s(doctree)" % attr for child in doctree.children(): self._index(child)
def find_specials(doctree): while doctree.parent() and doctree.tag() != "Module": doctree = doctree.parent() author = doctree.child(name='__author__') version = doctree.child(name='__version__') if author: author = author.child(tag='Value').text()[1:-1] # Check for email address from pythondoc.docregex import email_regex match = email_regex.search(author) if match: email = match.group(0) author = author[:match.start()] + \ author[match.start() + len(email):] author = string.strip(author) while author[-1] in ',.:;-': author = author[:-1] author = 'Author: <A HREF="mailto:%s">%s</A>' % ( email, pythondoc.doctree.escape(author)) if version: version = "Version: %s" % pythondoc.doctree.escape( version.child(tag='Value').text()[1:-1]) return author or '', version or ''
def _index(self, doctree): tag = string.lower(doctree.tag()) if tag == 'module': path = doctree.attribute('id') if path not in map(lambda (a, b): a, self.__entries): # Find oneliner esc = pythondoc.doctree.escape oneliner = doctree.child(tag="Oneliner") if oneliner: oneliner = ' - ' + esc(oneliner.text()) else: oneliner = '' self.__entries.append((path, oneliner)) for child in doctree.children(tag="Module"): self._index(child)
class HTML4Formatter: css_copied = 0 def __init__(self, module_tree=None): self.in_pre = 0 self.module_tree = module_tree def document(self, doctree): """Generate HTML page(s) for tree. Generates one or many HTML pages documenting the given doctree object.""" # Copy default stylesheet if no stylesheet is given by user if not self.css_copied: HTML4Formatter.css_copied = 1 stylesheet_given = _options.read_value(formatter_name, 'stylesheet')[0] if not stylesheet_given: dir = _options.read_value('main', 'directory')[1] filename = 'pythondoc.css' if dir: filename = os.path.join(dir, filename) file = open(filename, 'w') css_file = os.path.join(os.path.dirname(__file__), 'HTML4styles.css') pythondoc.message.information( make_msg("Copying CSS file from " + css_file)) try: file.write(open(css_file).read()) except IOError, msg: pythondoc.message.error( make_msg("Couldn't find default style sheet file: %s" & css_file)) file.close() self.open_file(doctree) exec "self.write_%s(doctree)" % string.lower(doctree.tag()) author, version = find_specials(doctree) footer = open_file('footer_file') % vars() self.file.write(S.FILE_END % vars())
def find_specials(doctree): while doctree.parent() and doctree.tag() != "Module": doctree = doctree.parent() author = doctree.child(name='__author__') version = doctree.child(name='__version__') if author: author = author.child(tag='Value').text()[1:-1] # Check for email address from pythondoc.docregex import email_regex match = email_regex.search(author) if match: email = match.group(0) author = author[:match.start()] + \ author[match.start() + len(email):] author = string.strip(author) while author[-1] in ',.:;-': author = author[:-1] author = 'Author: <A HREF="mailto:%s">%s</A>' % (email, pythondoc.doctree.escape(author)) if version: version = "Version: %s" % pythondoc.doctree.escape(version.child(tag='Value').text()[1:-1]) return author or '', version or ''