old_contents: """
  parse data from govtrack.us
  
  from: data/crawl/govtrack/people.xml
  """
  
  import web
  from xml.sax import make_parser, handler
  
  class PeopleXML(handler.ContentHandler):
      def __init__(self, callback):
          self.callback = callback
          self.current = None
          
      def startElement(self, name, attrs):
          if name == 'person':
              self.current = web.storage(attrs)
              if self.current.get('district'):
                  self.current.represents = self.current.state + '-' + self.current.district.zfill(2)
              else:
                  if self.current.get('state'):
                      self.current.represents = self.current.state
                      assert self.current.title == 'Sen.'
          if name == 'current-committee-assignment':
              self.current.active = True
      
      def endElement(self, name):
          if name == 'person':
              self.callback(self.current)
              self.current = None
  
  def callback(pol):
      if pol.get('active', False):
          print pol.represents
  
  def main(callback):
      parser = make_parser()
      parser.setContentHandler(PeopleXML(callback))
      parser.parse('../data/crawl/govtrack/people.xml')
  
  if __name__ == "__main__": main(callback)
  
new_contents: """
  parse data from govtrack.us
  
  from: data/crawl/govtrack/people.xml
  """
  
  PEOPLE_XML = '../data/crawl/govtrack/people.xml'
  
  from xml.dom import pulldom
  import web
  import tools
  
  def parse():
      dom = pulldom.parse(PEOPLE_XML)
      for event, node in dom:
          if event == "START_ELEMENT" and node.tagName == "person":
              out = web.storage(node.attributes.items())
              dom.expandNode(node)
              
              if out.get('district'):
                  out.represents = out.state + '-' + out.district.zfill(2)
              else:
                  if out.get('state'):
                      out.represents = out.state
                      assert out.title == 'Sen.'
              
              if 'current-committee-assignment' in [
                hasattr(x, 'tagName') and x.tagName for x in node.childNodes
              ]:
                  out.active = True
  
              yield out
  
  if __name__ == "__main__": tools.export(parse())
  
subject: move govtrack.py to new coding standards (http://watchdog.jottit.com/standards)