Skip to content

Commit 19e2a9c

Browse files
artemrysArtem Rys
authored andcommitted
refactor: use pyupgrade with --py37-plus
1 parent bb402a7 commit 19e2a9c

File tree

12 files changed

+41
-41
lines changed

12 files changed

+41
-41
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ repos:
33
rev: v2.29.0
44
hooks:
55
- id: pyupgrade
6-
args: [--py3-plus]
6+
args: [--py37-plus]
77
- repo: https://github.com/psf/black
88
rev: 21.9b0
99
hooks:

examples/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
def setup_environment():
3737
print("Setup solnlib demo environment...")
38-
print("Copying {} to {}".format(source_dir, target_dir))
38+
print(f"Copying {source_dir} to {target_dir}")
3939
shutil.copytree(source_dir, target_dir)
4040
shutil.copytree(solnlib_lib_dir, solnlib_lib_target_dir)
4141
os.system(splunk_bin + " start")

examples/test_splunkenv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ def test_splunkenv():
4444
assert port
4545

4646
uri = splunkenv.get_splunkd_uri()
47-
assert uri == "{scheme}://{host}:{port}".format(scheme=scheme, host=host, port=port)
47+
assert uri == f"{scheme}://{host}:{port}"

solnlib/conf_manager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __init__(
8282
host=None,
8383
port=None,
8484
realm=None,
85-
**context
85+
**context,
8686
):
8787
self._name = name
8888
self._conf = conf
@@ -112,7 +112,7 @@ def _cred_mgr(self):
112112
scheme=self._scheme,
113113
host=self._host,
114114
port=self._port,
115-
**self._context
115+
**self._context,
116116
)
117117

118118
return self._cred_manager
@@ -222,12 +222,12 @@ def get(self, stanza_name, only_current_app=False):
222222
raise
223223

224224
raise ConfStanzaNotExistException(
225-
"Stanza: {} does not exist in {}.conf".format(stanza_name, self._name)
225+
f"Stanza: {stanza_name} does not exist in {self._name}.conf"
226226
)
227227

228228
if len(stanza_mgrs) == 0:
229229
raise ConfStanzaNotExistException(
230-
"Stanza: {} does not exist in {}.conf".format(stanza_name, self._name)
230+
f"Stanza: {stanza_name} does not exist in {self._name}.conf"
231231
)
232232

233233
stanza = self._decrypt_stanza(stanza_mgrs[0].name, stanza_mgrs[0].content)
@@ -257,7 +257,7 @@ def get_all(self, only_current_app=False):
257257
"""
258258

259259
if only_current_app:
260-
stanza_mgrs = self._conf.list(search="eai:acl.app={}".format(self._app))
260+
stanza_mgrs = self._conf.list(search=f"eai:acl.app={self._app}")
261261
else:
262262
stanza_mgrs = self._conf.list()
263263
res = {}
@@ -337,7 +337,7 @@ def delete(self, stanza_name):
337337
"Delete stanza: %s error: %s.", stanza_name, traceback.format_exc()
338338
)
339339
raise ConfStanzaNotExistException(
340-
"Stanza: {} does not exist in {}.conf".format(stanza_name, self._name)
340+
f"Stanza: {stanza_name} does not exist in {self._name}.conf"
341341
)
342342

343343
@retry(exceptions=[binding.HTTPError])
@@ -405,7 +405,7 @@ def __init__(
405405
host=None,
406406
port=None,
407407
realm=None,
408-
**context
408+
**context,
409409
):
410410
self._session_key = session_key
411411
self._app = app
@@ -421,7 +421,7 @@ def __init__(
421421
scheme=self._scheme,
422422
host=self._host,
423423
port=self._port,
424-
**self._context
424+
**self._context,
425425
)
426426
self._confs = None
427427
self._realm = realm
@@ -462,7 +462,7 @@ def get_conf(self, name, refresh=False):
462462
self._host,
463463
self._port,
464464
self._realm,
465-
**self._context
465+
**self._context,
466466
)
467467

468468
@retry(exceptions=[binding.HTTPError])
@@ -489,5 +489,5 @@ def create_conf(self, name):
489489
self._host,
490490
self._port,
491491
self._realm,
492-
**self._context
492+
**self._context,
493493
)

solnlib/credentials.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
scheme=None,
9999
host=None,
100100
port=None,
101-
**context
101+
**context,
102102
):
103103
self._realm = realm
104104
self.service = rest_client.SplunkRestClient(
@@ -108,7 +108,7 @@ def __init__(
108108
scheme=scheme,
109109
host=host,
110110
port=port,
111-
**context
111+
**context,
112112
)
113113
self._storage_passwords = self.service.storage_passwords
114114

@@ -139,7 +139,7 @@ def get_password(self, user):
139139
return password["clear_password"]
140140

141141
raise CredentialNotExistException(
142-
"Failed to get password of realm={}, user={}.".format(self._realm, user)
142+
f"Failed to get password of realm={self._realm}, user={user}."
143143
)
144144

145145
@retry(exceptions=[binding.HTTPError])
@@ -244,7 +244,7 @@ def delete_password(self, user):
244244
def _get_all_passwords_in_realm(self):
245245
if self._realm:
246246
all_passwords = self._storage_passwords.list(
247-
count=-1, search="realm={}".format(self._realm)
247+
count=-1, search=f"realm={self._realm}"
248248
)
249249
else:
250250
all_passwords = self._storage_passwords.list(count=-1, search="")
@@ -255,7 +255,7 @@ def _get_all_passwords(self):
255255
all_passwords = self._storage_passwords.list(count=-1)
256256

257257
results = {}
258-
ptn = re.compile(r"(.+){cred_sep}(\d+)".format(cred_sep=self.SEP))
258+
ptn = re.compile(fr"(.+){self.SEP}(\d+)")
259259
for password in all_passwords:
260260
match = ptn.match(password.name)
261261
if match:

solnlib/log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def _reset_root_logger(cls):
146146
@classmethod
147147
def _get_log_file(cls, name):
148148
if cls._default_namespace:
149-
name = "{}_{}.log".format(cls._default_namespace, name)
149+
name = f"{cls._default_namespace}_{name}.log"
150150
else:
151-
name = "{}.log".format(name)
151+
name = f"{name}.log"
152152

153153
if cls._default_directory:
154154
directory = cls._default_directory

solnlib/net_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def wrapper(*args, **kwargs):
152152
if arg in optional and optional[arg] == value:
153153
continue
154154
if not func(value):
155-
raise ValueError("Illegal argument: {}={}".format(arg, value))
155+
raise ValueError(f"Illegal argument: {arg}={value}")
156156
return f(*args, **kwargs)
157157

158158
return wrapper

solnlib/splunk_rest_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _get_proxy_info(context):
4747
if context.get("proxy_username") and context.get("proxy_password"):
4848
username = quote(context["proxy_username"], safe="")
4949
password = quote(context["proxy_password"], safe="")
50-
user_pass = "{user}:{password}@".format(user=username, password=password)
50+
user_pass = f"{username}:{password}@"
5151

5252
proxy = "http://{user_pass}{host}:{port}".format(
5353
user_pass=user_pass, host=context["proxy_hostname"], port=context["proxy_port"]
@@ -148,7 +148,7 @@ def request(url, message, **kwargs):
148148
verify=verify,
149149
proxies=proxies,
150150
cert=cert,
151-
**kwargs
151+
**kwargs,
152152
)
153153
except Exception as e:
154154
logging.error(
@@ -208,7 +208,7 @@ def __init__(
208208
scheme=None,
209209
host=None,
210210
port=None,
211-
**context
211+
**context,
212212
):
213213
# Only do splunkd URI discovery in SPLUNK env (SPLUNK_HOME is set)
214214
if not all([scheme, host, port]) and os.environ.get("SPLUNK_HOME"):

solnlib/splunkenv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def make_splunkhome_path(parts):
140140
# Check that we haven't escaped from intended parent directories.
141141
if os.path.relpath(fullpath, basepath)[0:2] == "..":
142142
raise ValueError(
143-
'Illegal escape from parent directory "{}": {}'.format(basepath, fullpath)
143+
f'Illegal escape from parent directory "{basepath}": {fullpath}'
144144
)
145145
return fullpath
146146

@@ -207,7 +207,7 @@ def get_splunkd_uri():
207207
return os.environ["SPLUNKD_URI"]
208208

209209
scheme, host, port = get_splunkd_access_info()
210-
return "{scheme}://{host}:{port}".format(scheme=scheme, host=host, port=port)
210+
return f"{scheme}://{host}:{port}"
211211

212212

213213
def get_conf_key_value(conf_name, stanza, key):

solnlib/user_access.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def __init__(
291291
scheme=None,
292292
host=None,
293293
port=None,
294-
**context
294+
**context,
295295
):
296296
collection_name = "{app}_{collection_name}".format(
297297
app=app, collection_name=collection_name
@@ -613,7 +613,7 @@ def __init__(
613613
scheme=None,
614614
host=None,
615615
port=None,
616-
**context
616+
**context,
617617
):
618618
self._app = app
619619

@@ -722,7 +722,7 @@ def check_user_access(
722722
scheme=None,
723723
host=None,
724724
port=None,
725-
**context
725+
**context,
726726
):
727727
"""User access checker.
728728
@@ -778,7 +778,7 @@ def check_user_access(
778778
scheme=scheme,
779779
host=host,
780780
port=port,
781-
**context
781+
**context,
782782
):
783783
raise UserAccessException(
784784
"Permission denied, %s does not have the capability: %s."
@@ -868,7 +868,7 @@ def get_user_capabilities(
868868
_rest_client = rest_client.SplunkRestClient(
869869
session_key, "-", scheme=scheme, host=host, port=port, **context
870870
)
871-
url = "/services/authentication/users/{username}".format(username=username)
871+
url = f"/services/authentication/users/{username}"
872872
try:
873873
response = _rest_client.get(url, output_mode="json").body.read()
874874
except binding.HTTPError as e:
@@ -947,7 +947,7 @@ def get_user_roles(session_key, username, scheme=None, host=None, port=None, **c
947947
_rest_client = rest_client.SplunkRestClient(
948948
session_key, "-", scheme=scheme, host=host, port=port, **context
949949
)
950-
url = "/services/authentication/users/{username}".format(username=username)
950+
url = f"/services/authentication/users/{username}"
951951
try:
952952
response = _rest_client.get(url, output_mode="json").body.read()
953953
except binding.HTTPError as e:

0 commit comments

Comments
 (0)