def addPyListings(document, dir):
 for node in domhelpers.findElementsWithAttribute(document, 'class', 'py-listing'):
  filename = node.getAttribute('href')
  outfile = cStringIO.StringIO()
  lines = map(string.rstrip, open(os.path.join(dir, filename)).readlines())
  skip = (node.getAttribute('skipLines') or 0)
  lines = lines[int(skip):]
  howManyLines = len(lines)
  data = '\n'.join(lines)
  data = cStringIO.StringIO(text.removeLeadingTrailingBlanks(data))
  htmlizer.filter(data, outfile, writer=htmlizer.SmallerHTMLWriter)
  sourceNode = dom.parseString(outfile.getvalue()).documentElement
  sourceNode.insertBefore(_makeLineNumbers(howManyLines), sourceNode.firstChild)
  _replaceWithListing(node, sourceNode.toxml(), filename, 'py-listing')

def addPyListings ( document , dir ) : for node in domhelpers . findElementsWithAttribute ( document , 'class' , 'py-listing' ) : filename = node . getAttribute ( 'href' ) outfile = cStringIO . StringIO ( ) lines = map ( string . rstrip , open ( os . path . join ( dir , filename ) ) . readlines ( ) ) skip = ( node . getAttribute ( 'skipLines' ) or 0 ) lines = lines [ int ( skip ) : ] howManyLines = len ( lines ) data = '\n' . join ( lines ) data = cStringIO . StringIO ( text . removeLeadingTrailingBlanks ( data ) ) htmlizer . filter ( data , outfile , writer = htmlizer . SmallerHTMLWriter ) sourceNode = dom . parseString ( outfile . getvalue ( ) ) . documentElement sourceNode . insertBefore ( _makeLineNumbers ( howManyLines ) , sourceNode . firstChild ) _replaceWithListing ( node , sourceNode . toxml ( ) , filename , 'py-listing' )
insert python source listings into the given document from files in the given directory based on c{py-listing} nodes .