Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def lru_to_url(lru):
# Handling both stems and serialized lru
if isinstance(lru, string_type):
stems = unserialize_lru(lru)
else:
stems = lru
# Indexing stems
stems_index = {}
for stem in stems:
tag, value = stem.split(':', 1)
if tag == 'h' and tag in stems_index:
stems_index[tag] = value + '.' + stems_index[tag]
elif tag == 'p' and tag in stems_index:
stems_index[tag] += '/' + value
else:
stems_index[tag] = value
def ensure_lru_stems(lru):
if isinstance(lru, string_type):
return unserialize_lru(lru)
return lru