Project: pygitweb

"""Gravatar avatar URLs (https://gravatar.com)."""
from __future__ import annotations
import hashlib
from urllib.parse import urlencode
_GRAVATAR_BASE = "https://www.gravatar.com/avatar"
def gravatar_url(email: str, *, size: int = 64) -> str:
"""Return a Gravatar image URL for ``email`` (``d=404`` when no profile exists)."""
normalized = email.strip().lower().encode("utf-8")
digest = hashlib.md5(normalized).hexdigest() # noqa: S324
params = urlencode({"s": str(size), "d": "404"})
return f"{_GRAVATAR_BASE}/{digest}?{params}"