aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'gallery_dl/util.py')
-rw-r--r--gallery_dl/util.py29
1 files changed, 26 insertions, 3 deletions
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__ = ()