import html def escape_html(value): if value is None: return "—" return html.escape( str(value), quote=True, ) def display_value(value): if value is None or str(value).strip() == "": return "—" return escape_html(value) def format_security( encryption=None, cipher=None, akm=None, ): parts = [] for value in ( encryption, cipher, akm, ): if value is None: continue value = str(value).strip() if not value or value == "—": continue if value not in parts: parts.append(value) return " / ".join( escape_html(value) for value in parts ) or "—" def aggregate_credentials(credentials): """ Aggregate credentials by exact password value. A password is verified if at least one matching database record has verified=1. Sources are combined without duplicates. """ aggregated = {} for credential in credentials or []: password = credential["password"] if password is None or str(password) == "": continue password = str(password) if password not in aggregated: aggregated[password] = { "password": password, "verified": False, "sources": [], } item = aggregated[password] if credential["verified"]: item["verified"] = True source = credential["source"] if source is not None: source = str(source).strip() if source and source not in item["sources"]: item["sources"].append(source) return list(aggregated.values()) def format_credentials(credentials): aggregated = aggregate_credentials(credentials) if not aggregated: return "—" items = [] for credential in aggregated: password = escape_html( credential["password"] ) verified_class = ( "verified" if credential["verified"] else "unverified" ) verified_label = ( "Проверен" if credential["verified"] else "Не проверен" ) sources = ", ".join( escape_html(source) for source in credential["sources"] ) or "—" items.append( "