replace old %-formatted and .format(…) strings with f-strings (#7671)
mostly using flynt https://github.com/ikamensh/flynt
This commit is contained in:
@@ -43,7 +43,7 @@ def load_cookies(browser_specification):
|
||||
elif browser_name in SUPPORTED_BROWSERS_CHROMIUM:
|
||||
return load_cookies_chromium(browser_name, profile, keyring, domain)
|
||||
else:
|
||||
raise ValueError("unknown browser '{}'".format(browser_name))
|
||||
raise ValueError(f"unknown browser '{browser_name}'")
|
||||
|
||||
|
||||
def load_cookies_firefox(browser_name, profile=None,
|
||||
@@ -59,7 +59,7 @@ def load_cookies_firefox(browser_name, profile=None,
|
||||
if container_id is False:
|
||||
conditions.append("NOT INSTR(originAttributes,'userContextId=')")
|
||||
elif container_id:
|
||||
uid = "%userContextId={}".format(container_id)
|
||||
uid = f"%userContextId={container_id}"
|
||||
conditions.append("originAttributes LIKE ? OR originAttributes LIKE ?")
|
||||
parameters += (uid, uid + "&%")
|
||||
|
||||
@@ -72,7 +72,7 @@ def load_cookies_firefox(browser_name, profile=None,
|
||||
parameters += (domain, "." + domain)
|
||||
|
||||
if conditions:
|
||||
sql = "{} WHERE ( {} )".format(sql, " ) AND ( ".join(conditions))
|
||||
sql = f"{sql} WHERE ( {' ) AND ( '.join(conditions)} )"
|
||||
|
||||
with DatabaseConnection(path) as db:
|
||||
cookies = [
|
||||
@@ -186,7 +186,7 @@ def load_cookies_chromium(browser_name, profile=None,
|
||||
))
|
||||
|
||||
if failed_cookies > 0:
|
||||
failed_message = " ({} could not be decrypted)".format(failed_cookies)
|
||||
failed_message = f" ({failed_cookies} could not be decrypted)"
|
||||
else:
|
||||
failed_message = ""
|
||||
|
||||
@@ -212,9 +212,8 @@ def _firefox_cookies_database(browser_name, profile=None, container=None):
|
||||
|
||||
path = _find_most_recently_used_file(search_root, "cookies.sqlite")
|
||||
if path is None:
|
||||
raise FileNotFoundError(
|
||||
"Unable to find {} cookies database in {}".format(
|
||||
browser_name.capitalize(), search_root))
|
||||
raise FileNotFoundError(f"Unable to find {browser_name.capitalize()} "
|
||||
f"cookies database in {search_root}")
|
||||
|
||||
_log_debug("Extracting cookies from %s", path)
|
||||
|
||||
@@ -245,8 +244,7 @@ def _firefox_cookies_database(browser_name, profile=None, container=None):
|
||||
container_id = context["userContextId"]
|
||||
break
|
||||
else:
|
||||
raise ValueError("Unable to find Firefox container '{}'".format(
|
||||
container))
|
||||
raise ValueError(f"Unable to find Firefox container '{container}'")
|
||||
_log_debug("Only loading cookies from container '%s' (ID %s)",
|
||||
container, container_id)
|
||||
|
||||
@@ -391,8 +389,8 @@ def _chromium_cookies_database(profile, config):
|
||||
|
||||
path = _find_most_recently_used_file(search_root, "Cookies")
|
||||
if path is None:
|
||||
raise FileNotFoundError("Unable to find {} cookies database in "
|
||||
"'{}'".format(config["browser"], search_root))
|
||||
raise FileNotFoundError(f"Unable to find {config['browser']} cookies "
|
||||
f"database in '{search_root}'")
|
||||
return path
|
||||
|
||||
|
||||
@@ -716,9 +714,9 @@ def _get_kwallet_password(browser_keyring_name):
|
||||
)
|
||||
|
||||
if proc.returncode != 0:
|
||||
_log_error("kwallet-query failed with return code {}. "
|
||||
"Please consult the kwallet-query man page "
|
||||
"for details".format(proc.returncode))
|
||||
_log_error(f"kwallet-query failed with return code "
|
||||
f"{proc.returncode}. Please consult the kwallet-query "
|
||||
f"man page for details")
|
||||
return b""
|
||||
|
||||
if stdout.lower().startswith(b"failed to read"):
|
||||
@@ -847,7 +845,7 @@ class DataParser:
|
||||
|
||||
def read_bytes(self, num_bytes):
|
||||
if num_bytes < 0:
|
||||
raise ParserError("invalid read of {} bytes".format(num_bytes))
|
||||
raise ParserError(f"invalid read of {num_bytes} bytes")
|
||||
end = self.cursor + num_bytes
|
||||
if end > len(self._data):
|
||||
raise ParserError("reached end of input")
|
||||
@@ -858,8 +856,8 @@ class DataParser:
|
||||
def expect_bytes(self, expected_value, message):
|
||||
value = self.read_bytes(len(expected_value))
|
||||
if value != expected_value:
|
||||
raise ParserError("unexpected value: {} != {} ({})".format(
|
||||
value, expected_value, message))
|
||||
raise ParserError(f"unexpected value: {value} != {expected_value} "
|
||||
f"({message})")
|
||||
|
||||
def read_uint(self, big_endian=False):
|
||||
data_format = ">I" if big_endian else "<I"
|
||||
@@ -880,10 +878,10 @@ class DataParser:
|
||||
|
||||
def skip(self, num_bytes, description="unknown"):
|
||||
if num_bytes > 0:
|
||||
_log_debug("Skipping {} bytes ({}): {!r}".format(
|
||||
num_bytes, description, self.read_bytes(num_bytes)))
|
||||
_log_debug(f"Skipping {num_bytes} bytes ({description}): "
|
||||
f"{self.read_bytes(num_bytes)!r}")
|
||||
elif num_bytes < 0:
|
||||
raise ParserError("Invalid skip of {} bytes".format(num_bytes))
|
||||
raise ParserError(f"Invalid skip of {num_bytes} bytes")
|
||||
|
||||
def skip_to(self, offset, description="unknown"):
|
||||
self.skip(offset - self.cursor, description)
|
||||
@@ -906,7 +904,7 @@ class DatabaseConnection():
|
||||
if util.WINDOWS:
|
||||
path = "/" + os.path.abspath(path)
|
||||
|
||||
uri = "file:{}?mode=ro&immutable=1".format(path)
|
||||
uri = f"file:{path}?mode=ro&immutable=1"
|
||||
self.database = sqlite3.connect(
|
||||
uri, uri=True, isolation_level=None, check_same_thread=False)
|
||||
return self.database
|
||||
@@ -1104,9 +1102,9 @@ def _parse_browser_specification(
|
||||
browser, profile=None, keyring=None, container=None, domain=None):
|
||||
browser = browser.lower()
|
||||
if browser not in SUPPORTED_BROWSERS:
|
||||
raise ValueError("Unsupported browser '{}'".format(browser))
|
||||
raise ValueError(f"Unsupported browser '{browser}'")
|
||||
if keyring and keyring not in SUPPORTED_KEYRINGS:
|
||||
raise ValueError("Unsupported keyring '{}'".format(keyring))
|
||||
raise ValueError(f"Unsupported keyring '{keyring}'")
|
||||
if profile and _is_path(profile):
|
||||
profile = os.path.expanduser(profile)
|
||||
return browser, profile, keyring, container, domain
|
||||
|
||||
Reference in New Issue
Block a user