Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

[pyupgrade] config/ #9750

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion synapse/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/config/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -32,5 +31,5 @@
print(getattr(config, key))
sys.exit(0)
else:
sys.stderr.write("Unknown command %r\n" % (action,))
sys.stderr.write(f"Unknown command {action!r}\n")
sys.exit(1)
15 changes: 7 additions & 8 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017-2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
Expand Down Expand Up @@ -188,7 +187,7 @@ def path_exists(cls, file_path):
@classmethod
def check_file(cls, file_path, config_name):
if file_path is None:
raise ConfigError("Missing config for %s." % (config_name,))
raise ConfigError(f"Missing config for {config_name}.")
try:
os.stat(file_path)
except OSError as e:
Expand All @@ -207,7 +206,7 @@ def ensure_directory(cls, dir_path):
if e.errno != errno.EEXIST:
raise
if not os.path.isdir(dir_path):
raise ConfigError("%s is not a directory" % (dir_path,))
raise ConfigError(f"{dir_path} is not a directory")
return dir_path

@classmethod
Expand Down Expand Up @@ -313,12 +312,12 @@ def __init__(self):

for config_class in self.config_classes:
if config_class.section is None:
raise ValueError("%r requires a section name" % (config_class,))
raise ValueError(f"{config_class!r} requires a section name")

try:
conf = config_class(self)
except Exception as e:
raise Exception("Failed making %s: %r" % (config_class.section, e))
raise Exception(f"Failed making {config_class.section}: {e!r}")
self._configs[config_class.section] = conf

def __getattr__(self, item: str) -> Any:
Expand Down Expand Up @@ -354,7 +353,7 @@ def _get_unclassed_config(self, asking_section: Optional[str], item: str):
if item in dir(val):
return getattr(val, item)

raise AttributeError(item, "not found in %s" % (list(self._configs.keys()),))
raise AttributeError(item, "not found in {}".format(list(self._configs.keys())))

def invoke_all(self, func_name: str, *args, **kwargs) -> MutableMapping[str, Any]:
"""
Expand Down Expand Up @@ -668,7 +667,7 @@ def load_or_generate_config(cls, description, argv):

(config_path,) = config_files
if not path_exists(config_path):
print("Generating config file %s" % (config_path,))
print(f"Generating config file {config_path}")

if config_args.data_directory:
data_dir_path = config_args.data_directory
Expand Down Expand Up @@ -915,7 +914,7 @@ def read_file(file_path: Any, config_path: Iterable[str]) -> str:
with open(file_path) as file_stream:
return file_stream.read()
except OSError as e:
raise ConfigError("Error accessing file %r" % (file_path,), config_path) from e
raise ConfigError(f"Error accessing file {file_path!r}", config_path) from e


__all__ = [
Expand Down
1 change: 0 additions & 1 deletion synapse/config/_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
10 changes: 5 additions & 5 deletions synapse/config/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def read_config(self, config: JsonDict, **kwargs):

def generate_config_section(cls, **kwargs) -> str:
formatted_default_state_types = "\n".join(
" # - %s" % (t,) for t in _DEFAULT_PREJOIN_STATE_TYPES
f" # - {t}" for t in _DEFAULT_PREJOIN_STATE_TYPES
)

return """\
Expand All @@ -45,7 +45,7 @@ def generate_config_section(cls, **kwargs) -> str:
# By default, the following state event types are shared with users who
# receive invites to the room:
#
%(formatted_default_state_types)s
{formatted_default_state_types}
#
# Uncomment the following to disable these defaults (so that only the event
# types listed in 'additional_event_types' are shared). Defaults to 'false'.
Expand All @@ -59,9 +59,9 @@ def generate_config_section(cls, **kwargs) -> str:
#
#additional_event_types:
# - org.example.custom.event.type
""" % {
"formatted_default_state_types": formatted_default_state_types
}
""".format(
formatted_default_state_types=formatted_default_state_types
)

def _get_prejoin_state_types(self, config: JsonDict) -> Iterable[str]:
"""Get the event types to include in the prejoin state
Expand Down
8 changes: 3 additions & 5 deletions synapse/config/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_appservices(hostname, config_files):

for config_file in config_files:
try:
with open(config_file, "r") as f:
with open(config_file) as f:
appservice = _load_appservice(hostname, yaml.safe_load(f), config_file)
if appservice.id in seen_ids:
raise ConfigError(
Expand Down Expand Up @@ -97,15 +97,13 @@ def _load_appservice(hostname, as_info, config_filename):
required_string_fields = ["id", "as_token", "hs_token", "sender_localpart"]
for field in required_string_fields:
if not isinstance(as_info.get(field), str):
raise KeyError(
"Required string field: '%s' (%s)" % (field, config_filename)
)
raise KeyError(f"Required string field: '{field}' ({config_filename})")

# 'url' must either be a string or explicitly null, not missing
# to avoid accidentally turning off push for ASes.
if not isinstance(as_info.get("url"), str) and as_info.get("url", "") is not None:
raise KeyError(
"Required string field or explicit null: 'url' (%s)" % (config_filename,)
f"Required string field or explicit null: 'url' ({config_filename})"
)

localpart = as_info["sender_localpart"]
Expand Down
1 change: 0 additions & 1 deletion synapse/config/auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
Expand Down
5 changes: 1 addition & 4 deletions synapse/config/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -185,9 +184,7 @@ def read_config(self, config, **kwargs):

for cache, factor in individual_factors.items():
if not isinstance(factor, (int, float)):
raise ConfigError(
"caches.per_cache_factors.%s must be a number" % (cache,)
)
raise ConfigError(f"caches.per_cache_factors.{cache} must be a number")
self.cache_factors[cache] = factor

# Resize all caches (if necessary) with the new factors we've loaded
Expand Down
1 change: 0 additions & 1 deletion synapse/config/cas.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/consent_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/config/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
Expand Down Expand Up @@ -87,7 +86,7 @@ def __init__(self, name: str, db_config: dict):
db_engine = db_config.get("name", "sqlite3")

if db_engine not in ("sqlite3", "psycopg2"):
raise ConfigError("Unsupported database type %r" % (db_engine,))
raise ConfigError(f"Unsupported database type {db_engine!r}")

if db_engine == "sqlite3":
db_config.setdefault("args", {}).update(
Expand Down
1 change: 0 additions & 1 deletion synapse/config/emailconfig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015-2016 OpenMarket Ltd
# Copyright 2017-2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
Expand Down
1 change: 0 additions & 1 deletion synapse/config/experimental.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2021 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/federation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/groups.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/homeserver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2018 New Vector Ltd
#
Expand Down
1 change: 0 additions & 1 deletion synapse/config/jwt_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Niklas Riekenbrauck
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
9 changes: 4 additions & 5 deletions synapse/config/key.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
Expand Down Expand Up @@ -170,7 +169,7 @@ def generate_config_section(
base_key_name = os.path.join(config_dir_path, server_name)

if generate_secrets:
macaroon_secret_key = 'macaroon_secret_key: "%s"' % (
macaroon_secret_key = 'macaroon_secret_key: "{}"'.format(
random_string_with_symbols(50),
)
form_secret = 'form_secret: "%s"' % random_string_with_symbols(50)
Expand Down Expand Up @@ -292,7 +291,7 @@ def read_signing_keys(self, signing_key_path, name):
try:
return read_signing_keys(signing_keys.splitlines(True))
except Exception as e:
raise ConfigError("Error reading %s: %s" % (name, str(e)))
raise ConfigError("Error reading {}: {}".format(name, str(e)))

def read_old_signing_keys(self, old_signing_keys):
if old_signing_keys is None:
Expand All @@ -307,7 +306,7 @@ def read_old_signing_keys(self, old_signing_keys):
keys[key_id] = verify_key
else:
raise ConfigError(
"Unsupported signing algorithm for old key: %r" % (key_id,)
f"Unsupported signing algorithm for old key: {key_id!r}"
)
return keys

Expand All @@ -322,7 +321,7 @@ def generate_files(self, config, config_dir_path):
)

if not self.path_exists(signing_key_path):
print("Generating signing key file %s" % (signing_key_path,))
print(f"Generating signing key file {signing_key_path}")
with open(signing_key_path, "w") as signing_key_file:
key_id = "a_" + random_string(4)
write_signing_keys(signing_key_file, (generate_signing_key(key_id),))
Expand Down
1 change: 0 additions & 1 deletion synapse/config/logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
Expand Down
1 change: 0 additions & 1 deletion synapse/config/oidc_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 Quentin Gliech
# Copyright 2020-2021 The Matrix.org Foundation C.I.C.
#
Expand Down
1 change: 0 additions & 1 deletion synapse/config/password_auth_providers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Openmarket
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/push.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
# Copyright 2017 New Vector Ltd
#
Expand Down
1 change: 0 additions & 1 deletion synapse/config/redis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
5 changes: 2 additions & 3 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015, 2016 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -126,7 +125,7 @@ def read_config(self, config, **kwargs):
self.auto_join_rooms = config.get("auto_join_rooms", [])
for room_alias in self.auto_join_rooms:
if not RoomAlias.is_valid(room_alias):
raise ConfigError("Invalid auto_join_rooms entry %s" % (room_alias,))
raise ConfigError(f"Invalid auto_join_rooms entry {room_alias}")

# Options for creating auto-join rooms if they do not exist yet.
self.autocreate_auto_join_rooms = config.get("autocreate_auto_join_rooms", True)
Expand Down Expand Up @@ -191,7 +190,7 @@ def read_config(self, config, **kwargs):

def generate_config_section(self, generate_secrets=False, **kwargs):
if generate_secrets:
registration_shared_secret = 'registration_shared_secret: "%s"' % (
registration_shared_secret = 'registration_shared_secret: "{}"'.format(
random_string_with_symbols(50),
)
else:
Expand Down
1 change: 0 additions & 1 deletion synapse/config/repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014, 2015 OpenMarket Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/room.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
3 changes: 1 addition & 2 deletions synapse/config/room_directory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -170,7 +169,7 @@ def __init__(self, option_name, rule):
self.action = action
else:
raise ConfigError(
"%s rules can only have action of 'allow' or 'deny'" % (option_name,)
f"{option_name} rules can only have action of 'allow' or 'deny'"
)

self._alias_matches_all = alias == "*"
Expand Down
9 changes: 4 additions & 5 deletions synapse/config/saml2_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
Expand Down Expand Up @@ -317,7 +316,7 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# Instead of putting the config inline as above, you can specify a
# separate pysaml2 configuration file:
#
#config_path: "%(config_dir_path)s/sp_conf.py"
#config_path: "{config_dir_path}/sp_conf.py"

# The lifetime of a SAML session. This defines how long a user has to
# complete the authentication process, if allow_unsolicited is unset.
Expand Down Expand Up @@ -394,9 +393,9 @@ def generate_config_section(self, config_dir_path, server_name, **kwargs):
# option.
#
#idp_entityid: 'https://our_idp/entityid'
""" % {
"config_dir_path": config_dir_path
}
""".format(
config_dir_path=config_dir_path
)


ATTRIBUTE_REQUIREMENTS_SCHEMA = {
Expand Down
5 changes: 1 addition & 4 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017-2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
Expand Down Expand Up @@ -91,9 +90,7 @@ def generate_ip_set(
try:
network = IPNetwork(ip)
except AddrFormatError as e:
raise ConfigError(
"Invalid IP range provided: %s." % (ip,), config_path
) from e
raise ConfigError(f"Invalid IP range provided: {ip}.", config_path) from e
result.add(network)

# It is possible that these already exist in the set, but that's OK.
Expand Down
1 change: 0 additions & 1 deletion synapse/config/server_notices_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/spam_checker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2017 New Vector Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 0 additions & 1 deletion synapse/config/sso.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2020 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Loading