@staticmethod<EOL><INDENT>def _make_safe_label_value(string):<DEDENT>
MAX_LABEL_LEN = <NUM_LIT><EOL>safe_label = re.sub(r'<STR_LIT>', '<STR_LIT>', string)<EOL>if len(safe_label) > MAX_LABEL_LEN or string != safe_label:<EOL><INDENT>safe_hash = hashlib.md5(string.encode()).hexdigest()[:<NUM_LIT:9>]<EOL>safe_label = safe_label[:MAX_LABEL_LEN - len(safe_hash) - <NUM_LIT:1>] + "<STR_LIT:->" + safe_hash<EOL><DEDENT>return safe_label<EOL>
Valid label values must be 63 characters or less and must be empty or begin and
end with an alphanumeric character ([a-z0-9A-Z]) with dashes (-), underscores (_),
dots (.), and alphanumerics between.

If the label value is then greater than 63 chars once made safe, or differs in any
way from the original value sent to this function, then we need to truncate to
53chars, and append it with a unique hash.