MCPcopy
hub / github.com/django/django / truncate_name

Function truncate_name

django/db/backends/utils.py:283–301  ·  view source on GitHub ↗

Shorten an SQL identifier to a repeatable mangled version with the given length. If a quote stripped name contains a namespace, e.g. USERNAME"."TABLE, truncate the table portion only.

(identifier, length=None, hash_len=4)

Source from the content-addressed store, hash-verified

281
282
283def truncate_name(identifier, length=None, hash_len=4):
284 """
285 Shorten an SQL identifier to a repeatable mangled version with the given
286 length.
287
288 If a quote stripped name contains a namespace, e.g. USERNAME"."TABLE,
289 truncate the table portion only.
290 """
291 namespace, name = split_identifier(identifier)
292
293 if length is None or len(name) <= length:
294 return identifier
295
296 digest = names_digest(name, length=hash_len)
297 return "%s%s%s" % (
298 '%s"."' % namespace if namespace else "",
299 name[: length - hash_len],
300 digest,
301 )
302
303
304def names_digest(*args, length):

Calls 2

split_identifierFunction · 0.85
names_digestFunction · 0.85