import re,sys,string,time def extract(files): class_def = re.compile('^((class|def).+)$') fulldef = re.compile('.*:.*') startdoc = re.compile('^\s*("""|\'\'\')(.+)') enddoc = re.compile('^\s*("""|\'\'\')\s*$') subdef = re.compile('^\s+(def.+)$') for file in files: print "

",file,"

" f = open(file) line = f.readline() # see if there's docstring m = startdoc.match(line) doc = '' if m: doc = m.group(2) line = f.readline() m = enddoc.match(line) while line and not m: doc = doc + line line = f.readline() m = enddoc.match(line) if doc: print structured_text(doc) contents = [] while line: m = class_def.match(line) if not m: line = f.readline() continue group = [] doc = '' defstmt = line # make sure we got the whole thing while line: m = fulldef.match(line) if m: break line = f.readline() defstmt = defstmt + line line = f.readline() # see if there's docstring m = startdoc.match(line) if m: doc = m.group(2) line = f.readline() m = enddoc.match(line) while line and not m: doc = doc + line line = f.readline() m = enddoc.match(line) contents.append((defstmt, doc, group)) # no do methods while line: # break on new top level def|class m = class_def.match(line) if m: break # break on new top level def|class m = subdef.match(line) if not m: line = f.readline() continue defstmt = m.group(1) doc = '' # make sure we got the whole thing m = fulldef.match(line) while line and not m: line = f.readline() defstmt = defstmt + line m = fulldef.match(line) # see if there's docstring line = f.readline() m = startdoc.match(line) if m: doc = m.group(2) line = f.readline() m = enddoc.match(line) while line and not m: doc = doc + line line = f.readline() m = enddoc.match(line) line = f.readline() group.append((defstmt, doc)) print "
" for stmt, doc, group in contents: print "
",stmt,"" if doc: print "
",structured_text(doc) for stmt, doc in group: print "
",stmt,"" if doc: print "
",structured_text(doc) print "
" print "

" print "

" def structured_text(text): newText = [] bp = 0 text = string.strip(text) for line in string.split(text, '\n'): if not line: newText.append('

') continue if re.match('^\*[^\*]', line) and bp == 0: newText.append('

') bp=1 if re.match('^\*\*', line) and bp == 1: newText.append(''*bp) bp=0 continue if line[:2] == '**': line = '
  • '+line[2:] if line[0] == '*': line = '
  • '+line[1:] newText.append(line) if bp > 0: newText.append(''*bp) return string.join(newText, '\n') if __name__ == '__main__': print """ NSC - Object Reference """ extract(sys.argv[1:]) print """
    Last Generated: %s
    Contents of nsc.bofh.asn.au owned and copyright 1997-1999 by Richard Jones. Email me if you want to talk about the source or access to it. """%time.strftime("%e %B %Y", time.localtime(time.time()))