From 5b5fda2354f4488693f0f00def68eb8a9b426e67 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Thu, 4 Mar 2021 15:02:39 -0800 Subject: [PATCH] Fix % formatting without a tuple. Signed-off-by: Anders Kaseorg --- .../integrations/bridge_with_irc/irc_mirror_backend.py | 2 +- zulip/integrations/bridge_with_matrix/matrix_bridge.py | 2 +- zulip/integrations/codebase/zulip_codebase_mirror | 4 ++-- zulip/integrations/trac/zulip_trac.py | 2 +- zulip/zulip/__init__.py | 10 +++++----- zulip/zulip/send.py | 2 +- zulip_bots/zulip_bots/bots/giphy/giphy.py | 4 ++-- zulip_bots/zulip_bots/bots/xkcd/xkcd.py | 10 +++++----- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py index 9b2ce00..7726dc6 100644 --- a/zulip/integrations/bridge_with_irc/irc_mirror_backend.py +++ b/zulip/integrations/bridge_with_irc/irc_mirror_backend.py @@ -64,7 +64,7 @@ class IRCBot(irc.bot.SingleServerIRCBot): in_the_specified_stream = msg["display_recipient"] == self.stream at_the_specified_subject = msg["subject"].casefold() == self.topic.casefold() if in_the_specified_stream and at_the_specified_subject: - msg["content"] = ("@**%s**: " % msg["sender_full_name"]) + msg["content"] + msg["content"] = ("@**%s**: " % (msg["sender_full_name"],)) + msg["content"] send = lambda x: self.c.privmsg(self.channel, x) else: return diff --git a/zulip/integrations/bridge_with_matrix/matrix_bridge.py b/zulip/integrations/bridge_with_matrix/matrix_bridge.py index 0b140c7..a0665d0 100644 --- a/zulip/integrations/bridge_with_matrix/matrix_bridge.py +++ b/zulip/integrations/bridge_with_matrix/matrix_bridge.py @@ -72,7 +72,7 @@ def matrix_to_zulip( """ content = get_message_content_from_event(event, no_noise) - zulip_bot_user = ('@%s:matrix.org' % matrix_config['username']) + zulip_bot_user = '@%s:matrix.org' % (matrix_config['username'],) # We do this to identify the messages generated from Zulip -> Matrix # and we make sure we don't forward it again to the Zulip stream. not_from_zulip_bot = event['sender'] != zulip_bot_user diff --git a/zulip/integrations/codebase/zulip_codebase_mirror b/zulip/integrations/codebase/zulip_codebase_mirror index 469e814..3086e82 100755 --- a/zulip/integrations/codebase/zulip_codebase_mirror +++ b/zulip/integrations/codebase/zulip_codebase_mirror @@ -231,7 +231,7 @@ def handle_event(event: Dict[str, Any]) -> None: "subject": subject, "content": content}) if res['result'] == 'success': - logging.info("Successfully sent Zulip with id: %s" % (res['id'])) + logging.info("Successfully sent Zulip with id: %s" % (res['id'],)) else: logging.warn("Failed to send Zulip: %s %s" % (res['result'], res['msg'])) @@ -251,7 +251,7 @@ def run_mirror() -> None: else: since = datetime.fromtimestamp(float(timestamp), tz=pytz.utc) except (ValueError, OSError) as e: - logging.warn("Could not open resume file: %s" % (str(e))) + logging.warn("Could not open resume file: %s" % (str(e),)) since = default_since() try: diff --git a/zulip/integrations/trac/zulip_trac.py b/zulip/integrations/trac/zulip_trac.py index d607721..646c0ae 100644 --- a/zulip/integrations/trac/zulip_trac.py +++ b/zulip/integrations/trac/zulip_trac.py @@ -103,5 +103,5 @@ class ZulipPlugin(Component): def ticket_deleted(self, ticket: Any) -> None: """Called when a ticket is deleted.""" - content = "%s was deleted." % markdown_ticket_url(ticket, heading="Ticket") + content = "%s was deleted." % (markdown_ticket_url(ticket, heading="Ticket"),) send_update(ticket, content) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 3ae1e32..35d5523 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -565,7 +565,7 @@ class Client: continue else: end_error_retry(False) - return {'msg': "Connection error:\n%s" % traceback.format_exc(), + return {'msg': "Connection error:\n%s" % (traceback.format_exc(),), "result": "connection-error"} except requests.exceptions.ConnectionError: if not self.has_connected: @@ -578,11 +578,11 @@ class Client: if error_retry(""): continue end_error_retry(False) - return {'msg': "Connection error:\n%s" % traceback.format_exc(), + return {'msg': "Connection error:\n%s" % (traceback.format_exc(),), "result": "connection-error"} except Exception: # We'll split this out into more cases as we encounter new bugs. - return {'msg': "Unexpected error:\n%s" % traceback.format_exc(), + return {'msg': "Unexpected error:\n%s" % (traceback.format_exc(),), "result": "unexpected-error"} try: @@ -630,7 +630,7 @@ class Client: if 'error' in res['result']: if self.verbose: - print("Server returned error:\n%s" % res['msg']) + print("Server returned error:\n%s" % (res['msg'],)) time.sleep(1) else: return (res['queue_id'], res['last_event_id']) @@ -653,7 +653,7 @@ class Client: print("Connection error fetching events -- probably server is temporarily down?") else: if self.verbose: - print("Server returned error:\n%s" % res["msg"]) + print("Server returned error:\n%s" % (res["msg"],)) # Eventually, we'll only want the # BAD_EVENT_QUEUE_ID check, but we check for the # old string to support legacy Zulip servers. We diff --git a/zulip/zulip/send.py b/zulip/zulip/send.py index ea89460..6c2feb3 100755 --- a/zulip/zulip/send.py +++ b/zulip/zulip/send.py @@ -20,7 +20,7 @@ def do_send_message(client: zulip.Client, message_data: Dict[str, Any]) -> bool: log.info('Sending message to stream "%s", subject "%s"... ' % (message_data['to'], message_data['subject'])) else: - log.info('Sending message to %s... ' % message_data['to']) + log.info('Sending message to %s... ' % (message_data['to'],)) response = client.send_message(message_data) if response['result'] == 'success': log.info('Message sent.') diff --git a/zulip_bots/zulip_bots/bots/giphy/giphy.py b/zulip_bots/zulip_bots/bots/giphy/giphy.py index 6d41bf9..2c985c2 100644 --- a/zulip_bots/zulip_bots/bots/giphy/giphy.py +++ b/zulip_bots/zulip_bots/bots/giphy/giphy.py @@ -94,9 +94,9 @@ def get_bot_giphy_response(message: Dict[str, str], bot_handler: BotHandler, con 'let\'s try again later! :grin:') except GiphyNoResultException: return ('Sorry, I don\'t have a GIF for "%s"! ' - ':astonished:' % (keyword)) + ':astonished:' % (keyword,)) return ('[Click to enlarge](%s)' '[](/static/images/interactive-bot/giphy/powered-by-giphy.png)' - % (gif_url)) + % (gif_url,)) handler_class = GiphyHandler diff --git a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py index c01f00b..1cdb231 100644 --- a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py @@ -64,7 +64,7 @@ def get_xkcd_bot_response(message: Dict[str, str], quoted_name: str) -> str: try: if command == 'help': - return commands_help % ('xkcd bot supports these commands:') + return commands_help % ('xkcd bot supports these commands:',) elif command == 'latest': fetched = fetch_xkcd_query(XkcdBotCommand.LATEST) elif command == 'random': @@ -72,13 +72,13 @@ def get_xkcd_bot_response(message: Dict[str, str], quoted_name: str) -> str: elif command.isdigit(): fetched = fetch_xkcd_query(XkcdBotCommand.COMIC_ID, command) else: - return commands_help % ("xkcd bot only supports these commands, not `%s`:" % (command,)) + return commands_help % ("xkcd bot only supports these commands, not `%s`:" % (command,),) except (requests.exceptions.ConnectionError, XkcdServerError): logging.exception('Connection error occurred when trying to connect to xkcd server') return 'Sorry, I cannot process your request right now, please try again later!' except XkcdNotFoundError: logging.exception('XKCD server responded 404 when trying to fetch comic with id %s' - % (command)) + % (command,)) return 'Sorry, there is likely no xkcd comic strip with id: #%s' % (command,) else: return ("#%s: **%s**\n[%s](%s)" % (fetched['num'], @@ -99,12 +99,12 @@ def fetch_xkcd_query(mode: int, comic_id: Optional[str] = None) -> Dict[str, str latest_id = latest.json()['num'] random_id = random.randint(1, latest_id) - url = XKCD_TEMPLATE_URL % (str(random_id)) + url = XKCD_TEMPLATE_URL % (str(random_id),) elif mode == XkcdBotCommand.COMIC_ID: # Fetch specific comic strip by id number. if comic_id is None: raise Exception('Missing comic_id argument') - url = XKCD_TEMPLATE_URL % (comic_id) + url = XKCD_TEMPLATE_URL % (comic_id,) fetched = requests.get(url)