def __fmt_key(self, key):
"""Formats the hash key for more consistent hits; hence fetching the
'Message-ID' key should still be fetched even if the user indexes
with 'message-id'.
"""
def _fmt(_k):
return _k.group(1) + _k.group(2).upper()
if not isinstance(key, basestring):
# Handle invalid key entries types
key = str(key)
key = re.sub(
# Flip -id to ID (short for Identifier)
# Flip -crc to CRC (short for Cyclic Redundancy Check)
r'([_-])((id|crc)([^a-z0-9]|$))',
_fmt,
re.sub(r'(^|\s|[_-])(\S)', _fmt, key.strip().lower()),
flags=re.IGNORECASE,
)
if key in VALID_HEADER_ENTRIES or key.startswith(UNKNOWN_PREFIX):
return key
return UNKNOWN_PREFIX + key
评论列表
文章目录