Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _condense_cfgstr(self, cfgstr=None):
cfgstr = self._rectify_cfgstr(cfgstr)
# The 49 char maxlen is just long enough for an 8 char name, an 1 char
# underscore, and a 40 char sha1 hash.
max_len = 49
if len(cfgstr) > max_len:
from ubelt import util_hash
condensed = util_hash.hash_data(cfgstr, hasher=self.hasher, base='hex')
condensed = condensed[0:max_len]
else:
condensed = cfgstr
return condensed
def _hashable(item):
"""
Returns the item if it is naturally hashable, otherwise it tries to use
ub.hash_data to make it hashable. Errors if it cannot.
"""
try:
hash(item)
except TypeError:
return util_hash.hash_data(item)
else:
return item