From 8a847143722827ae0b54aa4395bf9674fd376ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sun, 18 Jan 2026 21:13:42 +0100 Subject: [PATCH] [util] use function for HTTPBasicAuth more lightweight and faster than a class --- gallery_dl/util.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gallery_dl/util.py b/gallery_dl/util.py index e4557086..fca3e665 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -521,16 +521,15 @@ CODES = { } -class HTTPBasicAuth(): - __slots__ = ("authorization",) +def HTTPBasicAuth(username, password): + authorization = b"Basic " + binascii.b2a_base64( + f"{username}:{password}".encode("latin1"), newline=False) + del username, password - def __init__(self, username, password): - self.authorization = b"Basic " + binascii.b2a_base64( - f"{username}:{password}".encode("latin1"), newline=False) - - def __call__(self, request): - request.headers["Authorization"] = self.authorization + def _apply(request): + request.headers["Authorization"] = authorization return request + return _apply class ModuleProxy():