Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <philipp@hoerist.com>2023-05-28 15:55:54 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-05-28 22:12:04 +0300
commited674b8cb125c98d068ca75c418a1164bae05b0d (patch)
tree5b856555e5bbd9ef88a4c11b18167c0500f4a917
parent79f003214d7df869c53fcd1a05374d97b7a38017 (diff)
cq: Simplify string formatting
-rw-r--r--gajim/common/jingle_session.py9
-rw-r--r--gajim/common/modules/base.py6
-rw-r--r--gajim/common/modules/omemo.py2
-rw-r--r--gajim/common/preview_helpers.py2
-rw-r--r--gajim/common/settings.py24
-rw-r--r--gajim/common/structs.py9
-rw-r--r--gajim/common/styling.py2
-rw-r--r--gajim/gajim.py20
-rw-r--r--gajim/gtk/accounts.py6
-rw-r--r--gajim/gtk/application.py2
-rw-r--r--gajim/gtk/css_config.py2
-rw-r--r--gajim/gtk/discovery.py20
-rw-r--r--gajim/gtk/exception.py6
-rw-r--r--gajim/gtk/groupchat_join.py2
-rw-r--r--gajim/gtk/omemo_trust_manager.py2
-rw-r--r--gajim/gtk/util.py11
-rw-r--r--pyproject.toml2
17 files changed, 61 insertions, 66 deletions
diff --git a/gajim/common/jingle_session.py b/gajim/common/jingle_session.py
index b2066931b..263e07bb5 100644
--- a/gajim/common/jingle_session.py
+++ b/gajim/common/jingle_session.py
@@ -731,8 +731,7 @@ class JingleSession:
name = content['name']
creator = content['creator']
if (creator, name) not in self.contents:
- text = 'Content %s (created by %s) does not exist' % (name,
- creator)
+ text = f'Content {name} (created by {creator}) does not exist'
self.__send_error(stanza,
'bad-request',
text=text,
@@ -753,7 +752,7 @@ class JingleSession:
if reason not in ('success', 'cancel', 'decline'):
self.__dispatch_error(reason, text)
if text:
- text = '%s (%s)' % (reason, text)
+ text = f'{reason} ({text})'
else:
# TODO
text = reason
@@ -828,7 +827,7 @@ class JingleSession:
type_: str | None = None
) -> None:
if text:
- text = '%s (%s)' % (error, text)
+ text = '{error} ({text})'
if type_ != 'modify':
self._raise_event('jingle-error-received', reason=text or error)
@@ -877,7 +876,7 @@ class JingleSession:
text: str | None = None,
type_: str | None = None
) -> None:
- err_stanza = nbxmpp.Error(stanza, '%s %s' % (Namespace.STANZAS, error))
+ err_stanza = nbxmpp.Error(stanza, f'{Namespace.STANZAS} {error}')
err = err_stanza.getTag('error')
if type_:
err.setAttr('type', type_)
diff --git a/gajim/common/modules/base.py b/gajim/common/modules/base.py
index f378f256d..d7351cdb6 100644
--- a/gajim/common/modules/base.py
+++ b/gajim/common/modules/base.py
@@ -65,9 +65,9 @@ class BaseModule(EventHelper):
def __getattr__(self, key: str) -> Any:
if key not in self._nbxmpp_methods:
raise AttributeError(
- "attribute '%s' is neither part of object '%s' "
- " nor declared in '_nbxmpp_methods'" % (
- key, self.__class__.__name__))
+ f'attribute "{key}" is neither part of object '
+ f'"{self.__class__.__name__}" nor declared in '
+ '"_nbxmpp_methods"')
if not app.account_is_connected(self._account):
self._log.warning('Account not connected, can’t use %s', key)
diff --git a/gajim/common/modules/omemo.py b/gajim/common/modules/omemo.py
index 8b1c8d4fe..08f67c852 100644
--- a/gajim/common/modules/omemo.py
+++ b/gajim/common/modules/omemo.py
@@ -317,7 +317,7 @@ class OMEMO(BaseModule):
transfer.size = len(result.payload)
fragment = binascii.hexlify(result.iv + result.key).decode()
transfer.set_uri_transform_func(
- lambda uri: 'aesgcm%s#%s' % (uri[5:], fragment))
+ lambda uri: f'aesgcm{uri[5:]}#{fragment}')
transfer.set_encrypted_data(result.payload)
GLib.idle_add(callback, transfer)
diff --git a/gajim/common/preview_helpers.py b/gajim/common/preview_helpers.py
index 43f6050ff..443967d1e 100644
--- a/gajim/common/preview_helpers.py
+++ b/gajim/common/preview_helpers.py
@@ -391,7 +391,7 @@ def format_geo_coords(lat: float, lon: float) -> str:
slon = p_('positive longitude', '%sE') % fmt(lon)
else:
slon = p_('negative longitude', '%sW') % fmt(-lon)
- return '%s %s' % (slat, slon)
+ return f'{slat} {slon}'
def filename_from_uri(uri: str) -> str:
diff --git a/gajim/common/settings.py b/gajim/common/settings.py
index a286eeda5..f423ee958 100644
--- a/gajim/common/settings.py
+++ b/gajim/common/settings.py
@@ -92,18 +92,18 @@ CREATE_SQL = '''
settings TEXT
);
- INSERT INTO settings(name, settings) VALUES ('app', '{}');
- INSERT INTO settings(name, settings) VALUES ('soundevents', '{}');
- INSERT INTO settings(name, settings) VALUES ('status_presets', '%s');
- INSERT INTO settings(name, settings) VALUES ('proxies', '%s');
- INSERT INTO settings(name, settings) VALUES ('plugins', '{}');
- INSERT INTO settings(name, settings) VALUES ('workspaces', '%s');
-
- PRAGMA user_version=%s;
- ''' % (json.dumps(STATUS_PRESET_EXAMPLES),
- json.dumps(PROXY_EXAMPLES),
- json.dumps(INITAL_WORKSPACE),
- CURRENT_USER_VERSION)
+ INSERT INTO settings(name, settings) VALUES ('app', '{{}}');
+ INSERT INTO settings(name, settings) VALUES ('soundevents', '{{}}');
+ INSERT INTO settings(name, settings) VALUES ('status_presets', '{status}');
+ INSERT INTO settings(name, settings) VALUES ('proxies', '{proxies}');
+ INSERT INTO settings(name, settings) VALUES ('plugins', '{{}}');
+ INSERT INTO settings(name, settings) VALUES ('workspaces', '{workspaces}');
+
+ PRAGMA user_version={version};
+ '''.format(status=json.dumps(STATUS_PRESET_EXAMPLES),
+ proxies=json.dumps(PROXY_EXAMPLES),
+ workspaces=json.dumps(INITAL_WORKSPACE),
+ version=CURRENT_USER_VERSION)
_SignalCallable = Callable[[Any, str, str | None, JID | None], Any]
diff --git a/gajim/common/structs.py b/gajim/common/structs.py
index 2d74d2cd7..726726784 100644
--- a/gajim/common/structs.py
+++ b/gajim/common/structs.py
@@ -106,7 +106,7 @@ class OutgoingMessage:
) -> None:
if type_ not in ('chat', 'groupchat', 'normal', 'headline'):
- raise ValueError('Unknown message type: %s' % type_)
+ raise ValueError(f'Unknown message type: {type_}')
if not message and chatstate is None and marker is None:
raise ValueError('Trying to send message without content')
@@ -286,7 +286,7 @@ class VariantMixin:
if 'JID' in field_type:
return JID, f'{variant_str}s'
- raise ValueError('unknown type: %s' % field_type)
+ raise ValueError(f'unknown type: {field_type}')
def to_variant(self) -> GLib.Variant:
__types = {}
@@ -299,8 +299,7 @@ class VariantMixin:
continue
if not isinstance(value, field_t):
- raise ValueError('invalid type: %s is not a %s' % (value,
- field_t))
+ raise ValueError(f'invalid type: {value} is not a {field_t}')
conversion_func = self._type_to_variant_funcs.get(field_t)
if conversion_func is not None:
@@ -322,6 +321,6 @@ class VariantMixin:
value = vdict[field_name]
conversion_func = cls._variant_to_type_funcs.get(value_t_name)
if conversion_func is None:
- raise ValueError('no conversion for: %s' % value_t_name)
+ raise ValueError(f'no conversion for: {value_t_name}')
vdict[field_name] = conversion_func(value)
return cls(**vdict)
diff --git a/gajim/common/styling.py b/gajim/common/styling.py
index 1731cbb63..bfe828caf 100644
--- a/gajim/common/styling.py
+++ b/gajim/common/styling.py
@@ -185,7 +185,7 @@ def find_byte_index(text: str, index: int):
if index == index_:
return byte_index
- raise ValueError('index not in string: %s, %s' % (text, index))
+ raise ValueError(f'index not in string: {text}, {index}')
def process(text: str | bytes, level: int = 0) -> ParsingResult:
diff --git a/gajim/gajim.py b/gajim/gajim.py
index 349092807..12eb4e318 100644
--- a/gajim/gajim.py
+++ b/gajim/gajim.py
@@ -40,22 +40,22 @@ _MIN_SQLITE_VER = '3.33.0'
def check_version(dep_name: str, current_ver: str, min_ver: str) -> None:
if V(current_ver) < V(min_ver):
- sys.exit('Gajim needs %s >= %s (found %s) to run. '
- 'Quitting...' % (dep_name, min_ver, current_ver))
+ sys.exit(f'Gajim needs {dep_name} >= {min_ver} '
+ f'(found {current_ver}) to run. Quitting...')
def _check_required_deps() -> None:
- error_message = 'Gajim needs %s to run. Quitting… (Error: %s)'
+ error_message = 'Gajim needs {lib} to run. Quitting… (Error: {error})'
try:
import nbxmpp
except ImportError as error:
- sys.exit(error_message % ('python-nbxmpp', error))
+ sys.exit(error_message.format('python-nbxmpp', error))
try:
import gi
except ImportError as error:
- sys.exit(error_message % ('pygobject', error))
+ sys.exit(error_message.format('pygobject', error))
try:
gi.require_versions({'GLib': '2.0',
@@ -66,17 +66,17 @@ def _check_required_deps() -> None:
'Pango': '1.0',
'PangoCairo': '1.0'})
except ValueError as error:
- sys.exit('Missing dependency: %s' % error)
+ sys.exit(f'Missing dependency: {error}')
try:
import cairo
except ImportError as error:
- sys.exit(error_message % ('pycairo', error))
+ sys.exit(error_message.format('pycairo', error))
from gi.repository import Gtk
- gtk_ver = '%s.%s.%s' % (Gtk.get_major_version(),
- Gtk.get_minor_version(),
- Gtk.get_micro_version())
+ gtk_ver = '.'.join(map(str, [Gtk.get_major_version(),
+ Gtk.get_minor_version(),
+ Gtk.get_micro_version()]))
from gi.repository import GLib
glib_ver = '.'.join(map(str, [GLib.MAJOR_VERSION,
diff --git a/gajim/gtk/accounts.py b/gajim/gtk/accounts.py
index a745071b4..593e88200 100644
--- a/gajim/gtk/accounts.py
+++ b/gajim/gtk/accounts.py
@@ -941,9 +941,9 @@ class EncryptionOMEMOPage(GenericSettingPage):
btbv_label = Gtk.Label()
btbv_label.set_xalign(0)
- markup = '<a href="%s">%s</a>' % (
- 'https://dev.gajim.org/gajim/gajim/-/wikis/help/OMEMO',
- _('Read more about blind trust'))
+ wiki_url = 'https://dev.gajim.org/gajim/gajim/-/wikis/help/OMEMO'
+ link_text = _('Read more about blind trust')
+ markup = f'<a href="{wiki_url}">{link_text}</a>'
btbv_label.set_markup(markup)
self.add(btbv_label)
diff --git a/gajim/gtk/application.py b/gajim/gtk/application.py
index 8b0479370..43779da1b 100644
--- a/gajim/gtk/application.py
+++ b/gajim/gtk/application.py
@@ -372,7 +372,7 @@ class GajimApplication(Gtk.Application, CoreApplication):
# Incorporate profile name into application id
# to have a single app instance for each profile.
profile = profile.get_string()
- app_id = '%s.%s' % (self.get_application_id(), profile)
+ app_id = f'{self.get_application_id()}.{profile}'
self.set_application_id(app_id)
configpaths.set_profile(profile)
diff --git a/gajim/gtk/css_config.py b/gajim/gtk/css_config.py
index b7f78a89a..28dfe6330 100644
--- a/gajim/gtk/css_config.py
+++ b/gajim/gtk/css_config.py
@@ -640,7 +640,7 @@ class CSSConfig:
for index, account in enumerate(accounts):
color = app.settings.get_account_setting(account, 'account_color')
css_class = f'gajim_class_{index}'
- css += '.%s { background-color: %s }\n' % (css_class, color)
+ css += f'.{css_class} {{ background-color: {color} }}\n'
self._dynamic_dict[account] = css_class
self._dynamic_provider.load_from_data(css.encode())
diff --git a/gajim/gtk/discovery.py b/gajim/gtk/discovery.py
index ea1faefe4..a0d2834d9 100644
--- a/gajim/gtk/discovery.py
+++ b/gajim/gtk/discovery.py
@@ -208,7 +208,7 @@ def get_agent_address(jid, node=None):
Get an agent's address for displaying in the GUI
'''
if node:
- return '%s@%s' % (node, str(jid))
+ return f'{node}@{str(jid)}'
return str(jid)
@@ -301,7 +301,7 @@ class ServicesCache:
service_name = addr.split('.')[0]
# Or load it
- icon_name = 'gajim-agent-%s' % service_name
+ icon_name = f'gajim-agent-{service_name}'
if icon_exists(icon_name):
return icon_name
return 'gajim-agent-jabber'
@@ -1139,7 +1139,7 @@ class ToplevelAgentBrowser(AgentBrowser):
def add_self_line(self):
addr = get_agent_address(self.jid, self.node)
- descr = '<b>%s</b>' % addr
+ descr = f'<b>{addr}</b>'
# Guess which kind of service this is
identities = []
type_ = app.get_transport_name_from_jid(self.jid,
@@ -1541,9 +1541,9 @@ class ToplevelAgentBrowser(AgentBrowser):
# Row text
addr = get_agent_address(jid, node)
if 'name' in item:
- descr = '<b>%s</b>\n%s' % (item['name'], addr)
+ descr = f'<b>{item["name"]}</b>\n{addr}'
else:
- descr = '<b>%s</b>' % addr
+ descr = f'<b>{addr}</b>'
# Guess which kind of service this is
identities = []
type_ = app.get_transport_name_from_jid(
@@ -1570,21 +1570,21 @@ class ToplevelAgentBrowser(AgentBrowser):
def _update_item(self, iter_, jid, node, item):
addr = get_agent_address(jid, node)
if 'name' in item:
- descr = '<b>%s</b>\n%s' % (item['name'], addr)
+ descr = f'<b>{item["name"]}</b>\n{addr}'
else:
- descr = '<b>%s</b>' % addr
+ descr = f'<b>{addr}</b>'
self.model[iter_][3] = descr
def _update_info(self, iter_, jid, node, identities, features, data):
addr = get_agent_address(jid, node)
if not identities:
- descr = '<b>%s</b>' % addr
+ descr = '<b>{addr}</b>'
else:
name = identities[0].name or ''
if name:
- descr = '<b>%s</b>\n%s' % (name, addr)
+ descr = f'<b>{name}</b>\n{addr}'
else:
- descr = '<b>%s</b>' % addr
+ descr = f'<b>{addr}</b>'
# Update progress
self._progress += 1
diff --git a/gajim/gtk/exception.py b/gajim/gtk/exception.py
index 0787012d7..38d912d18 100644
--- a/gajim/gtk/exception.py
+++ b/gajim/gtk/exception.py
@@ -190,13 +190,13 @@ class ExceptionDialog(Gtk.ApplicationWindow):
def _parse_endpoint(self, request: HTTPRequest) -> str:
if not request.is_complete():
- raise ValueError('Failed to retrieve sentry endpoint: %s %s' % (
- request.get_status(), request.get_error()))
+ raise ValueError('Failed to retrieve sentry endpoint: '
+ f'{request.get_status()} {request.get_error()}')
try:
data = json.loads(request.get_data())
except Exception as error:
- raise ValueError('Json parsing error: %s' % error)
+ raise ValueError(f'Json parsing error: {error}')
endpoint = data.get('sentry_endpoint')
if endpoint is None:
diff --git a/gajim/gtk/groupchat_join.py b/gajim/gtk/groupchat_join.py
index fe8aef314..394d45f49 100644
--- a/gajim/gtk/groupchat_join.py
+++ b/gajim/gtk/groupchat_join.py
@@ -142,7 +142,7 @@ class GroupchatJoin(Gtk.ApplicationWindow):
if error.condition == 'gone':
reason = error.get_text(get_rfc5646_lang())
if reason:
- text = '%s:\n%s' % (text, reason)
+ text = f'{text}:\n{reason}'
self._show_error_page(text)
def _set_error_from_code(self, error_code: str) -> None:
diff --git a/gajim/gtk/omemo_trust_manager.py b/gajim/gtk/omemo_trust_manager.py
index 465d9ca02..f47fdd9ec 100644
--- a/gajim/gtk/omemo_trust_manager.py
+++ b/gajim/gtk/omemo_trust_manager.py
@@ -355,7 +355,7 @@ class TrustButton(Gtk.MenuButton):
if not self._row.active:
css_class = 'omemo-inactive-color'
- tooltip = '%s - %s' % (_('Inactive'), tooltip)
+ tooltip = f'{_("Inactive")} - {tooltip}'
image.get_style_context().add_class(css_class)
self._css_class = css_class
diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py
index aa1783514..c3c6c8f81 100644
--- a/gajim/gtk/util.py
+++ b/gajim/gtk/util.py
@@ -323,7 +323,7 @@ def convert_rgba_to_hex(rgba: Gdk.RGBA) -> str:
red = int(rgba.red * 255)
green = int(rgba.green * 255)
blue = int(rgba.blue * 255)
- return '#%02x%02x%02x' % (red, green, blue)
+ return f'#{red:02x}{green:02x}{blue:02x}'
def convert_rgb_to_hex(rgb_string: str) -> str:
@@ -428,8 +428,7 @@ def format_location(location: LocationData) -> str:
tag = LOCATION_DATA.get(attr)
if tag is None:
continue
- location_string += '\n<b>%(tag)s</b>: %(text)s' % {
- 'tag': tag.capitalize(), 'text': text}
+ location_string += f'\n<b>{tag.capitalize()}</b>: {text}'
return location_string.strip()
@@ -456,7 +455,7 @@ def format_fingerprint(fingerprint: str) -> str:
wordsize = fplen // 8
buf = ''
for char in range(0, fplen, wordsize):
- buf += '{0} '.format(fingerprint[char:char + wordsize])
+ buf += f'{fingerprint[char:char + wordsize]} '
buf = textwrap.fill(buf, width=36)
return buf.rstrip().upper()
@@ -670,8 +669,8 @@ def make_href_markup(string: str) -> str:
url = match.group()
if '://' not in url:
url = 'https://' + url
- return '<a href="%s"><span foreground="%s">%s</span></a>' % (
- url, color, match.group())
+ return (f'<a href="{url}"><span foreground="{color}">'
+ f'{match.group()}</span></a>')
return URL_REGEX.sub(_to_href, string)
diff --git a/pyproject.toml b/pyproject.toml
index fae748650..49f1079e6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -233,8 +233,6 @@ ignore = [
"SIM201", # Use x instead of not x
"SIM212", # Use `value if value else ''` instead of `'' if not value else value`
"SIM300", # Yoda conditions are discouraged use x instead
- "UP030", # Use implicit references for positional format fields
- "UP031", # Use format specifiers instead of percent format
"UP032", # Use f-string instead of `format` call
"UP034", # Avoid extraneous parentheses
"UP035", # Import from `collections.abc` instead: `Callable`