Remove obsolete MD5 compatibility wrapper

Inline the two callers, preserving usedforsecurity=False, which has been supported since Python 3.9.
This commit is contained in:
Simon Willison 2026-10-12 11:54:05 -07:00
commit 95dc7f9070
2 changed files with 5 additions and 11 deletions

View file

@ -1,6 +1,7 @@
import asyncio
import atexit
import contextvars
import hashlib
import inspect
import os
import queue
@ -58,7 +59,6 @@ from .utils import (
escape_sqlite,
get_all_foreign_keys,
get_outbound_foreign_keys,
md5_not_usedforsecurity,
sqlite3,
sqlite_timelimit,
table_column_details,
@ -160,7 +160,9 @@ class Database:
def color(self):
if self.hash:
return self.hash[:6]
return md5_not_usedforsecurity(self.name)[:6]
return hashlib.md5(self.name.encode("utf8"), usedforsecurity=False).hexdigest()[
:6
]
def suggest_name(self):
if self.is_temp_disk:

View file

@ -957,7 +957,7 @@ def to_css_class(s):
"""
if css_class_re.match(s):
return s
md5_suffix = md5_not_usedforsecurity(s)[:6]
md5_suffix = hashlib.md5(s.encode("utf8"), usedforsecurity=False).hexdigest()[:6]
# Strip leading _, -
s = s.lstrip("_").lstrip("-")
# Replace any whitespace with hyphens
@ -1757,14 +1757,6 @@ def redact_keys(original: dict, key_patterns: Iterable) -> dict:
return redact(original)
def md5_not_usedforsecurity(s):
try:
return hashlib.md5(s.encode("utf8"), usedforsecurity=False).hexdigest()
except TypeError:
# For Python 3.8 which does not support usedforsecurity=False
return hashlib.md5(s.encode("utf8")).hexdigest()
_etag_cache = {}