aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/util.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2024-10-25 17:27:30 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2024-10-25 17:27:30 -0400
commitfc004701f923bb954a22c7fec2ae8d607e78cb2b (patch)
treea5bea4ed6447ea43c099131430e3bd6182ee87d7 /gallery_dl/util.py
parent0db541f524e1774865efebcbe5653e9ad76ea2e8 (diff)
New upstream version 1.27.7.upstream/1.27.7
Diffstat (limited to 'gallery_dl/util.py')
-rw-r--r--gallery_dl/util.py37
1 files changed, 30 insertions, 7 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py
index d5bc171..6cdd994 100644
--- a/gallery_dl/util.py
+++ b/gallery_dl/util.py
@@ -403,9 +403,9 @@ def set_mtime(path, mtime):
pass
-def cookiestxt_load(fp, cookiejar):
- """Parse a Netscape cookies.txt file and add its Cookies to 'cookiejar'"""
- set_cookie = cookiejar.set_cookie
+def cookiestxt_load(fp):
+ """Parse a Netscape cookies.txt file and add return its Cookies"""
+ cookies = []
for line in fp:
@@ -427,18 +427,20 @@ def cookiestxt_load(fp, cookiejar):
name = value
value = None
- set_cookie(Cookie(
+ cookies.append(Cookie(
0, name, value,
None, False,
domain,
domain_specified == "TRUE",
- domain.startswith("."),
+ domain[0] == "." if domain else False,
path, False,
secure == "TRUE",
None if expires == "0" or not expires else expires,
False, None, None, {},
))
+ return cookies
+
def cookiestxt_store(fp, cookies):
"""Write 'cookies' in Netscape cookies.txt format to 'fp'"""
@@ -456,9 +458,10 @@ def cookiestxt_store(fp, cookies):
name = cookie.name
value = cookie.value
+ domain = cookie.domain
write("\t".join((
- cookie.domain,
- "TRUE" if cookie.domain.startswith(".") else "FALSE",
+ domain,
+ "TRUE" if domain and domain[0] == "." else "FALSE",
cookie.path,
"TRUE" if cookie.secure else "FALSE",
"0" if cookie.expires is None else str(cookie.expires),
@@ -529,6 +532,24 @@ class HTTPBasicAuth():
return request
+class ModuleProxy():
+ __slots__ = ()
+
+ def __getitem__(self, key, modules=sys.modules):
+ try:
+ return modules[key]
+ except KeyError:
+ pass
+ try:
+ __import__(key)
+ except ImportError:
+ modules[key] = NONE
+ return NONE
+ return modules[key]
+
+ __getattr__ = __getitem__
+
+
class LazyPrompt():
__slots__ = ()
@@ -537,6 +558,7 @@ class LazyPrompt():
class NullContext():
+ __slots__ = ()
def __enter__(self):
return None
@@ -643,6 +665,7 @@ GLOBALS = {
"restart" : raises(exception.RestartExtraction),
"hash_sha1": sha1,
"hash_md5" : md5,
+ "std" : ModuleProxy(),
"re" : re,
}