def upsert_link(self, link, overwrite_ref=False):
elink = self.__links.get(link.id_)<EOL>if elink:<EOL><INDENT>if elink.ref is None or overwrite_ref and link.ref:<EOL><INDENT>elink.ref = link.ref<EOL><DEDENT>if link._title is not None:<EOL><INDENT>elink.title = link._title<EOL><DEDENT>return elink<EOL><DEDENT>if not overwrite_ref:<EOL><INDENT>sym = self.__doc_db.get_symbol(link.id_)<EOL>if sym and sym.link:<EOL><INDENT>self.__links[link.id_] = sym.link<EOL>return sym.link<EOL><DEDENT><DEDENT>self.add_link(link)<EOL>return link<EOL>
Banana banana