def OverrideIdentity(idurl, xml_src): """ """ global _OverriddenIdentities xml_src = str(xml_src.strip()) if idurl in _OverriddenIdentities: if _OverriddenIdentities[idurl] == xml_src: if _Debug: lg.out(4, 'identitycache.OverrideIdentity SKIPPED "%s", no changes' % idurl) return False if _Debug: lg.out(4, 'identitycache.OverrideIdentity replacing overriden identity "%s" with new one' % idurl) lg.out(4, '\nOVERRIDDEN OLD:\n' + _OverriddenIdentities[idurl]) lg.out(4, '\nOVERRIDDEN NEW:\n' + xml_src) else: orig = identitydb.get(idurl).serialize() if identitydb.has_idurl(idurl) else '' if orig and orig == xml_src: if _Debug: lg.out(4, 'identitycache.OverrideIdentity SKIPPED "%s" , overriden copy is the same as original' % idurl) return False if _Debug: lg.out(4, 'identitycache.OverrideIdentity replacing original identity for "%s"' % idurl) lg.out(4, '\nORIGINAL:\n' + orig) lg.out(4, '\nNEW:\n' + xml_src) _OverriddenIdentities[idurl] = xml_src if _Debug: lg.out(4, ' total number of overrides: %d' % len(_OverriddenIdentities)) return True
def FromCache(idurl): """ Get identity object from cache. """ if IsOverridden(idurl): overridden_xmlsrc = ReadOverriddenIdentityXMLSource(idurl) if overridden_xmlsrc: if _Debug: lg.out(14, ' returning overridden identity (%d bytes) for %s' % (len(overridden_xmlsrc), idurl)) return identity.identity(xmlsrc=overridden_xmlsrc) return identitydb.get(idurl)