Skip to content

Commit

Permalink
Convert to using f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmueller committed Jan 6, 2024
1 parent 130c1b4 commit 1a9b1e2
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 442 deletions.
8 changes: 4 additions & 4 deletions osc/OscConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _add_option(self, optname, value=None, line=None, sep='='):
raise configparser.Error('value and line are mutually exclusive')

if value is not None:
line = '%s%s%s' % (optname, sep, value)
line = f'{optname}{sep}{value}'
opt = self._find(optname)
if opt:
opt.format(line)
Expand Down Expand Up @@ -253,10 +253,10 @@ def _read(self, fp, fpname):
#cursect[optname] = "%s\n%s" % (cursect[optname], value)
#self.set(cursect, optname, "%s\n%s" % (self.get(cursect, optname), value))
if cursect == configparser.DEFAULTSECT:
self._defaults[optname] = "%s\n%s" % (self._defaults[optname], value)
self._defaults[optname] = f"{self._defaults[optname]}\n{value}"

Check warning on line 256 in osc/OscConfigParser.py

View check run for this annotation

Codecov / codecov/patch

osc/OscConfigParser.py#L256

Added line #L256 was not covered by tests
else:
# use the raw value here (original version uses raw=False)
self._sections[cursect]._find(optname).value = '%s\n%s' % (self.get(cursect, optname, raw=True), value)
self._sections[cursect]._find(optname).value = f'{self.get(cursect, optname, raw=True)}\n{value}'
# a section header or option header?
else:
# is it a section header?
Expand Down Expand Up @@ -342,7 +342,7 @@ def __str__(self):
first = False
else:
ret.append('')
ret.append('[%s]' % line.name)
ret.append(f'[{line.name}]')
for sline in line._lines:
if sline.name == '__name__':
continue
Expand Down
342 changes: 171 additions & 171 deletions osc/commandline.py

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ def get_apiurl_api_host_options(apiurl):
apiurl = sanitize_apiurl(apiurl)
if is_known_apiurl(apiurl):
return config['api_host_options'][apiurl]
raise oscerr.ConfigMissingApiurl('missing credentials for apiurl: \'%s\'' % apiurl,
raise oscerr.ConfigMissingApiurl(f'missing credentials for apiurl: \'{apiurl}\'',

Check warning on line 1544 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L1544

Added line #L1544 was not covered by tests
'', apiurl)


Expand Down Expand Up @@ -1642,10 +1642,10 @@ def config_set_option(section, opt, val=None, delete=False, update=True, creds_m

section = sections.get(section.rstrip('/'), section)
if section not in cp.sections():
raise oscerr.ConfigError('unknown section \'%s\'' % section, config['conffile'])
raise oscerr.ConfigError(f'unknown section \'{section}\'', config['conffile'])

Check warning on line 1645 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L1645

Added line #L1645 was not covered by tests
if section == 'general' and opt not in general_opts or \
section != 'general' and opt not in api_host_options:
raise oscerr.ConfigError('unknown config option \'%s\'' % opt, config['conffile'])
raise oscerr.ConfigError(f'unknown config option \'{opt}\'', config['conffile'])

Check warning on line 1648 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L1648

Added line #L1648 was not covered by tests

if not val and not delete and opt == 'pass' and creds_mgr_descr is not None:
# change password store
Expand Down Expand Up @@ -1758,7 +1758,7 @@ def _get_credentials_manager(url, cp):
if cp.has_option(url, credentials.AbstractCredentialsManager.config_entry):
creds_mgr = credentials.create_credentials_manager(url, cp)
if creds_mgr is None:
msg = 'Unable to instantiate creds mgr (section: %s)' % url
msg = f'Unable to instantiate creds mgr (section: {url})'

Check warning on line 1761 in osc/conf.py

View check run for this annotation

Codecov / codecov/patch

osc/conf.py#L1761

Added line #L1761 was not covered by tests
conffile = get_configParser.conffile
raise oscerr.ConfigMissingCredentialsError(msg, conffile, url)
return creds_mgr
Expand Down
2 changes: 1 addition & 1 deletion osc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def add_signature_auth_header(self, req, auth):
auth = self.get_authorization(chal)
if not auth:
return False
auth_val = 'Signature %s' % auth
auth_val = f'Signature {auth}'

Check warning on line 671 in osc/connection.py

View check run for this annotation

Codecov / codecov/patch

osc/connection.py#L671

Added line #L671 was not covered by tests
req.add('Authorization', auth_val)
return True

Expand Down
Loading

0 comments on commit 1a9b1e2

Please sign in to comment.