Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*OVERWRITE*, or if no duplication is found, return the dedup result
*(isdupkey, isdupval, invbyval, fwdbykey)*.
"""
fwd = self._fwd
inv = self._inv
fwdbykey = fwd.get(key, _MISS)
invbyval = inv.get(val, _MISS)
isdupkey = fwdbykey is not _MISS
isdupval = invbyval is not _MISS
if isdupkey and isdupval:
if self._isdupitem(key, val, invbyval, fwdbykey):
# (key, val) duplicates an existing item -> no-op.
return
# key and val each duplicate a different existing item.
if on_dup_kv is RAISE:
raise KeyAndValueDuplicationError(key, val)
elif on_dup_kv is IGNORE:
return
# else on_dup_kv is OVERWRITE. Fall through to return on last line.
elif isdupkey:
if on_dup_key is RAISE:
raise KeyDuplicationError(key)
elif on_dup_key is IGNORE:
return
# else on_dup_key is OVERWRITE. Fall through to return on last line.
elif isdupval:
if on_dup_val is RAISE:
raise ValueDuplicationError(val)
elif on_dup_val is IGNORE:
return
# else on_dup_val is OVERWRITE. Fall through to return on last line.
# else neither isdupkey nor isdupval.