1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-25 04:02:32 +01:00

use 'True if COND else False' for bool conversions

faster than 'bool(COND)', especially on older Pythons < 3.11
This commit is contained in:
Mike Fährmann 2024-10-14 20:53:49 +02:00
parent c148e200a4
commit d68bb78f44
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
4 changed files with 14 additions and 12 deletions

View File

@ -74,8 +74,9 @@ def load_cookies_firefox(profile=None, container=None, domain=None):
cookies = [
Cookie(
0, name, value, None, False,
domain, bool(domain), domain.startswith("."),
path, bool(path), secure, expires, False, None, None, {},
domain, True if domain else False, domain.startswith("."),
path, True if path else False, secure, expires,
False, None, None, {},
)
for name, value, domain, path, secure, expires in db.execute(
sql, parameters)
@ -157,9 +158,9 @@ def load_cookies_chromium(browser_name, profile=None,
cookies.append(Cookie(
0, name, value, None, False,
domain, bool(domain), domain.startswith("."),
path, bool(path), secure, expires or None, False,
None, None, {},
domain, True if domain else False, domain.startswith("."),
path, True if path else False, secure, expires or None,
False, None, None, {},
))
if failed_cookies > 0:
@ -284,7 +285,7 @@ def _safari_parse_cookies_record(data, cookies, host=None):
record_size = p.read_uint()
p.skip(4, "unknown record field 1")
flags = p.read_uint()
is_secure = bool(flags & 0x0001)
is_secure = True if (flags & 0x0001) else False
p.skip(4, "unknown record field 2")
domain_offset = p.read_uint()
name_offset = p.read_uint()
@ -322,9 +323,9 @@ def _safari_parse_cookies_record(data, cookies, host=None):
cookies.append(Cookie(
0, name, value, None, False,
domain, bool(domain), domain.startswith("."),
path, bool(path), is_secure, expiration_date, False,
None, None, {},
domain, True if domain else False, domain.startswith("."),
path, True if path else False, is_secure, expiration_date,
False, None, None, {},
))
return record_size

View File

@ -109,7 +109,7 @@ class CohostUserExtractor(CohostExtractor):
"projectHandle": self.groups[0],
"page": 0,
"options": {
"pinnedPostsAtTop" : bool(self.pinned),
"pinnedPostsAtTop" : True if self.pinned else False,
"hideReplies" : not self.replies,
"hideShares" : not self.shares,
"hideAsks" : not self.asks,

View File

@ -1301,7 +1301,7 @@ class DeviantartOAuthAPI():
metadata = extractor.config("metadata", False)
if not metadata:
metadata = bool(extractor.extra)
metadata = True if extractor.extra else False
if metadata:
self.metadata = True

View File

@ -63,7 +63,8 @@ class NozomiExtractor(Extractor):
yield Message.Directory, post
for post["num"], image in enumerate(images, 1):
post["filename"] = post["dataid"] = did = image["dataid"]
post["is_video"] = video = bool(image.get("is_video"))
post["is_video"] = video = \
True if image.get("is_video") else False
ext = image["type"]
if video: