From 30dee4697019389ef29458b2e3931adc976389b2 Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Mon, 11 Dec 2023 01:12:30 -0500 Subject: New upstream version 1.26.4. --- gallery_dl/util.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'gallery_dl/util.py') diff --git a/gallery_dl/util.py b/gallery_dl/util.py index 62aa12d..53502ef 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -14,6 +14,7 @@ import sys import json import time import random +import getpass import hashlib import sqlite3 import binascii @@ -274,7 +275,7 @@ Response Headers if hide_auth: authorization = req_headers.get("Authorization") if authorization: - atype, sep, _ = authorization.partition(" ") + atype, sep, _ = str(authorization).partition(" ") req_headers["Authorization"] = atype + " ***" if sep else "***" cookie = req_headers.get("Cookie") @@ -290,15 +291,17 @@ Response Headers r"(^|, )([^ =]+)=[^,;]*", r"\1\2=***", set_cookie, ) + fmt_nv = "{}: {}".format + fp.write(outfmt.format( request=request, response=response, request_headers="\n".join( - name + ": " + value + fmt_nv(name, value) for name, value in req_headers.items() ), response_headers="\n".join( - name + ": " + value + fmt_nv(name, value) for name, value in res_headers.items() ), ).encode()) @@ -487,6 +490,26 @@ CODES = { } +class HTTPBasicAuth(): + __slots__ = ("authorization",) + + def __init__(self, username, password): + self.authorization = b"Basic " + binascii.b2a_base64( + username.encode("latin1") + b":" + str(password).encode("latin1") + )[:-1] + + def __call__(self, request): + request.headers["Authorization"] = self.authorization + return request + + +class LazyPrompt(): + __slots__ = () + + def __str__(self): + return getpass.getpass() + + class CustomNone(): """None-style type that supports more operations than regular None""" __slots__ = () -- cgit v1.2.3