def handle_links(self, infile): links = self.extract(infile) try: from links_database import LINKS except ImportError: LINKS = {} out = {} for link in links: value = "" if link in LINKS: value = LINKS.get(link) out.update({ link : value }) cont = "" tpl = "\n.. _%s: %s" for k, v in out.iteritems(): cont += tpl % (k, v) content = self.get_content(infile) content += cont self.write_content(infile, content)