Use f-strings

f-strings is a new, shorter alternative to `.format` method that was
introduced in Python 3.6.
This commit is contained in:
Yotam Nachum authored and Orip committed 2022-09-12 20:59:52 +03:00
1 parent a89af5355f
commit c4785c3f7c
11 files changed
+34 -44

No files matched your search

+8 -8
View File
@@ -26,7 +26,7 @@ class Application:
"BADGER": "badger-badger-badger",
"SNAKE": "mushroom-mushroom",
}
print("✔ spawn(argv={})".format(argv))
print(f"✔ spawn(argv={argv})")
pid = self._device.spawn(argv, env=env, stdio='pipe')
self._instrument(pid)
@@ -35,7 +35,7 @@ class Application:
self._stop_requested.set()
def _instrument(self, pid):
print("✔ attach(pid={})".format(pid))
print(f"✔ attach(pid={pid})")
session = self._device.attach(pid)
session.on("detached", lambda reason: self._reactor.schedule(lambda: self._on_detached(pid, session, reason)))
print("✔ enable_child_gating()")
@@ -54,27 +54,27 @@ Interceptor.attach(Module.getExportByName(null, 'open'), {
script.on("message", lambda message, data: self._reactor.schedule(lambda: self._on_message(pid, message)))
print("✔ load()")
script.load()
print("✔ resume(pid={})".format(pid))
print(f"✔ resume(pid={pid})")
self._device.resume(pid)
self._sessions.add(session)
def _on_child_added(self, child):
print("⚡ child_added: {}".format(child))
print(f"⚡ child_added: {child}")
self._instrument(child.pid)
def _on_child_removed(self, child):
print("⚡ child_removed: {}".format(child))
print(f"⚡ child_removed: {child}")
def _on_output(self, pid, fd, data):
print("⚡ output: pid={}, fd={}, data={}".format(pid, fd, repr(data)))
print(f"⚡ output: pid={pid}, fd={fd}, data={repr(data)}")
def _on_detached(self, pid, session, reason):
print("⚡ detached: pid={}, reason='{}'".format(pid, reason))
print(f"⚡ detached: pid={pid}, reason='{reason}'")
self._sessions.remove(session)
self._reactor.schedule(self._stop_if_idle, delay=0.5)
def _on_message(self, pid, message):
print("⚡ message: pid={}, payload={}".format(pid, message["payload"]))
print(f"⚡ message: pid={pid}, payload={message['payload']}")
app = Application()
+2 -2
View File
@@ -126,7 +126,7 @@ class Capture(NSObject):
self._delegate.captureRecvTotalDidChange()
else:
if not self.calls._handleStanza_(stanza):
print("Woot! Got stanza: %s from=%s" % (stanza['name'], stanza['from']))
print(f"Woot! Got stanza: {stanza['name']} from={stanza['from']}")
else:
print("Unhandled message:", message)
@@ -355,7 +355,7 @@ class FunctionCall(NSObject):
self = self.init()
self.func = func
self.args = args
self.summary = "%s(%s)" % (func.name, ", ".join(args))
self.summary = f"{func.name}({', '.join(args)})"
return self
SCRIPT_TEMPLATE = """
+2 -5
View File
@@ -17,8 +17,5 @@ for app in apps:
params = dict(app.parameters)
if 'icons' in params:
params['icons'] = [trim_icon(icon) for icon in params['icons']]
print("Application(identifier=\"{}\", name=\"{}\", pid={}, parameters={})".format(
app.identifier,
app.name,
app.pid,
highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip()))
parameters = highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip()
print(f"Application(identifier=\"{app.identifier}\", name=\"{app.name}\", pid={app.pid}, parameters={parameters})")
+1 -1
View File
@@ -17,4 +17,4 @@ for proc in processes:
params = dict(proc.parameters)
if 'icons' in params:
params['icons'] = [trim_icon(icon) for icon in params['icons']]
print("Process(pid={}, name=\"{}\", parameters={})".format(proc.pid, proc.name, highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip()))
print(f"Process(pid={proc.pid}, name=\"{proc.name}\", parameters={highlight(pformat(params), PythonLexer(), Terminal256Formatter()).rstrip()})")
+1 -1
View File
@@ -17,6 +17,6 @@ if app is not None:
params = dict(app.parameters)
if 'icons' in params:
params['icons'] = [trim_icon(icon) for icon in params['icons']]
print("{}:".format(app.identifier), highlight(pformat(params), PythonLexer(), Terminal256Formatter()))
print(f"{app.identifier}:", highlight(pformat(params), PythonLexer(), Terminal256Formatter()))
else:
print("No frontmost application")
+7 -7
View File
@@ -51,7 +51,7 @@ class Application:
})
channel = text[6:]
self._channel = channel
self._prompt = "{} > ".format(channel)
self._prompt = f"{channel} > "
self._bus.post({
'type': 'join',
'channel': channel
@@ -80,19 +80,19 @@ class Application:
self._print("*** Welcome! Available channels:", repr(message['channels']))
elif mtype == 'membership':
self._print("*** Joined", message['channel'])
self._print("- Members:\n\t" + "\n\t".join(["{} (connected from {})".format(m['nick'], m['address']) for m in message['members']]))
self._print("- Members:\n\t" + "\n\t".join([f"{m['nick']} (connected from {m['address']})" for m in message['members']]))
for item in message['history']:
self._print("<{}> {}".format(item['sender'], item['text']))
self._print(f"<{item['sender']}> {item['text']}")
elif mtype == 'join':
user = message['user']
self._print("👋 {} ({}) joined {}".format(user['nick'], user['address'], message['channel']))
self._print(f"👋 {user['nick']} ({user['address']}) joined {message['channel']}")
elif mtype == 'part':
user = message['user']
self._print("🚪 {} ({}) left {}".format(user['nick'], user['address'], message['channel']))
self._print(f"🚪 {user['nick']} ({user['address']}) left {message['channel']}")
elif mtype == 'chat':
self._print("<{}> {}".format(message['sender'], message['text']))
self._print(f"<{message['sender']}> {message['text']}")
elif mtype == 'announce':
self._print("📣 <{}> {}".format(message['sender'], message['text']))
self._print(f"📣 <{message['sender']}> {message['text']}")
else:
self._print("Unhandled message:", message)
+2 -2
View File
@@ -68,10 +68,10 @@ function puts(s) {
print("Unknown command")
def _on_detached(self, reason, crash):
print("⚡ detached: reason={}, crash={}".format(reason, crash))
print(f"⚡ detached: reason={reason}, crash={crash}")
def _on_message(self, message, data):
print("⚡ message: {}".format(message))
print(f"⚡ message: {message}")
app = Application()