diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index c6380ce1ca..da8febe43f 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -124,7 +124,7 @@ def renewal_amount(plan: CustomerPlan, event_time: datetime) -> int: # nocovera class BillingError(Exception): # error messages - CONTACT_SUPPORT = _("Something went wrong. Please contact %s." % (settings.ZULIP_ADMINISTRATOR,)) + CONTACT_SUPPORT = _("Something went wrong. Please contact %s.") % (settings.ZULIP_ADMINISTRATOR,) TRY_RELOADING = _("Something went wrong. Please reload the page.") # description is used only for tests diff --git a/corporate/views.py b/corporate/views.py index 22cbc20854..be42befea1 100644 --- a/corporate/views.py +++ b/corporate/views.py @@ -53,7 +53,7 @@ def check_upgrade_parameters( min_licenses = max(seat_count, MIN_INVOICED_LICENSES) if licenses is None or licenses < min_licenses: raise BillingError('not enough licenses', - _("You must invoice for at least {} users.".format(min_licenses))) + _("You must invoice for at least {} users.").format(min_licenses)) # Should only be called if the customer is being charged automatically def payment_method_string(stripe_customer: stripe.Customer) -> str: @@ -62,14 +62,14 @@ def payment_method_string(stripe_customer: stripe.Customer) -> str: if stripe_source is None: # nocoverage return _("No payment method on file") if stripe_source.object == "card": - return _("%(brand)s ending in %(last4)s" % { + return _("%(brand)s ending in %(last4)s") % { 'brand': cast(stripe.Card, stripe_source).brand, - 'last4': cast(stripe.Card, stripe_source).last4}) + 'last4': cast(stripe.Card, stripe_source).last4} # There might be one-off stuff we do for a particular customer that # would land them here. E.g. by default we don't support ACH for # automatic payments, but in theory we could add it for a customer via # the Stripe dashboard. - return _("Unknown payment method. Please contact %s." % (settings.ZULIP_ADMINISTRATOR,)) # nocoverage + return _("Unknown payment method. Please contact %s.") % (settings.ZULIP_ADMINISTRATOR,) # nocoverage @has_request_variables def upgrade(request: HttpRequest, user: UserProfile, diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 87bf809c52..3d999b6435 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -1887,7 +1887,7 @@ def recipient_for_user_ids(user_ids: Iterable[int], sender: UserProfile) -> Reci user_profile = get_user_by_id_in_realm_including_cross_realm( user_id, sender.realm) except UserProfile.DoesNotExist: - raise ValidationError(_("Invalid user ID {}".format(user_id))) + raise ValidationError(_("Invalid user ID {}").format(user_id)) user_profiles.append(user_profile) return recipient_for_user_profiles( @@ -2050,23 +2050,23 @@ def check_schedule_message(sender: UserProfile, client: Client, def check_stream_name(stream_name: str) -> None: if stream_name.strip() == "": - raise JsonableError(_("Invalid stream name '%s'" % (stream_name,))) + raise JsonableError(_("Invalid stream name '%s'") % (stream_name,)) if len(stream_name) > Stream.MAX_NAME_LENGTH: - raise JsonableError(_("Stream name too long (limit: %s characters)." % (Stream.MAX_NAME_LENGTH,))) + raise JsonableError(_("Stream name too long (limit: %s characters).") % (Stream.MAX_NAME_LENGTH,)) for i in stream_name: if ord(i) == 0: - raise JsonableError(_("Stream name '%s' contains NULL (0x00) characters." % (stream_name,))) + raise JsonableError(_("Stream name '%s' contains NULL (0x00) characters.") % (stream_name,)) def check_default_stream_group_name(group_name: str) -> None: if group_name.strip() == "": - raise JsonableError(_("Invalid default stream group name '%s'" % (group_name,))) + raise JsonableError(_("Invalid default stream group name '%s'") % (group_name,)) if len(group_name) > DefaultStreamGroup.MAX_NAME_LENGTH: - raise JsonableError(_("Default stream group name too long (limit: %s characters)" - % (DefaultStreamGroup.MAX_NAME_LENGTH,))) + raise JsonableError(_("Default stream group name too long (limit: %s characters)") + % (DefaultStreamGroup.MAX_NAME_LENGTH,)) for i in group_name: if ord(i) == 0: - raise JsonableError(_("Default stream group name '%s' contains NULL (0x00) characters." - % (group_name,))) + raise JsonableError(_("Default stream group name '%s' contains NULL (0x00) characters.") + % (group_name,)) def send_rate_limited_pm_notification_to_bot_owner(sender: UserProfile, realm: Realm, @@ -3643,7 +3643,7 @@ def lookup_default_stream_groups(default_stream_group_names: List[str], default_stream_group = DefaultStreamGroup.objects.get( name=group_name, realm=realm) except DefaultStreamGroup.DoesNotExist: - raise JsonableError(_('Invalid default stream group %s' % (group_name,))) + raise JsonableError(_('Invalid default stream group %s') % (group_name,)) default_stream_groups.append(default_stream_group) return default_stream_groups @@ -4053,7 +4053,7 @@ def do_update_message_flags(user_profile: UserProfile, messages: List[int]) -> int: valid_flags = [item for item in UserMessage.flags if item not in UserMessage.NON_API_FLAGS] if flag not in valid_flags: - raise JsonableError(_("Invalid flag: '%s'" % (flag,))) + raise JsonableError(_("Invalid flag: '%s'") % (flag,)) flagattr = getattr(UserMessage.flags, flag) assert messages is not None @@ -5394,7 +5394,7 @@ def check_add_user_group(realm: Realm, name: str, initial_members: List[UserProf user_group = create_user_group(name, initial_members, realm, description=description) do_send_create_user_group_event(user_group, initial_members) except django.db.utils.IntegrityError: - raise JsonableError(_("User group '%s' already exists." % (name,))) + raise JsonableError(_("User group '%s' already exists.") % (name,)) def do_send_user_group_update_event(user_group: UserGroup, data: Dict[str, Any]) -> None: event = dict(type="user_group", op='update', group_id=user_group.id, data=data) @@ -5405,7 +5405,7 @@ def do_update_user_group_name(user_group: UserGroup, name: str) -> None: user_group.name = name user_group.save(update_fields=['name']) except django.db.utils.IntegrityError: - raise JsonableError(_("User group '%s' already exists." % (name,))) + raise JsonableError(_("User group '%s' already exists.") % (name,)) do_send_user_group_update_event(user_group, dict(name=name)) def do_update_user_group_description(user_group: UserGroup, description: str) -> None: diff --git a/zerver/lib/addressee.py b/zerver/lib/addressee.py index 77ef78bbe4..ddf9c3f5fe 100644 --- a/zerver/lib/addressee.py +++ b/zerver/lib/addressee.py @@ -37,7 +37,7 @@ def get_user_profiles_by_ids(user_ids: Iterable[int], realm: Realm) -> List[User try: user_profile = get_user_by_id_in_realm_including_cross_realm(user_id, realm) except UserProfile.DoesNotExist: - raise JsonableError(_("Invalid user ID {}".format(user_id))) + raise JsonableError(_("Invalid user ID {}").format(user_id)) user_profiles.append(user_profile) return user_profiles diff --git a/zerver/lib/emoji.py b/zerver/lib/emoji.py index 7d6878b43e..80d6e41c67 100644 --- a/zerver/lib/emoji.py +++ b/zerver/lib/emoji.py @@ -50,7 +50,7 @@ def emoji_name_to_emoji_code(realm: Realm, emoji_name: str) -> Tuple[str, str]: return emoji_name, Reaction.ZULIP_EXTRA_EMOJI if emoji_name in name_to_codepoint: return name_to_codepoint[emoji_name], Reaction.UNICODE_EMOJI - raise JsonableError(_("Emoji '%s' does not exist" % (emoji_name,))) + raise JsonableError(_("Emoji '%s' does not exist") % (emoji_name,)) def check_valid_emoji(realm: Realm, emoji_name: str) -> None: emoji_name_to_emoji_code(realm, emoji_name) diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index d8f4ba45fb..e98d0df35c 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -110,7 +110,7 @@ def check_stream_name_available(realm: Realm, name: str) -> None: def access_stream_by_name(user_profile: UserProfile, stream_name: str, allow_realm_admin: bool=False) -> Tuple[Stream, Recipient, Optional[Subscription]]: - error = _("Invalid stream name '%s'" % (stream_name,)) + error = _("Invalid stream name '%s'") % (stream_name,) try: stream = get_realm_stream(stream_name, user_profile.realm_id) except Stream.DoesNotExist: @@ -177,7 +177,7 @@ def can_access_stream_history_by_name(user_profile: UserProfile, stream_name: st if stream.is_history_public_to_subscribers(): # In this case, we check if the user is subscribed. - error = _("Invalid stream name '%s'" % (stream_name,)) + error = _("Invalid stream name '%s'") % (stream_name,) try: (recipient, sub) = access_stream_common(user_profile, stream, error) except JsonableError: @@ -282,4 +282,4 @@ def access_default_stream_group_by_id(realm: Realm, group_id: int) -> DefaultStr try: return DefaultStreamGroup.objects.get(realm=realm, id=group_id) except DefaultStreamGroup.DoesNotExist: - raise JsonableError(_("Default stream group with id '%s' does not exist." % (group_id,))) + raise JsonableError(_("Default stream group with id '%s' does not exist.") % (group_id,)) diff --git a/zerver/lib/users.py b/zerver/lib/users.py index 9e2dfcd143..cbc378fcf3 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -148,12 +148,12 @@ def user_ids_to_users(user_ids: List[int], realm: Realm) -> List[UserProfile]: found_user_ids = user_profiles_by_id.keys() missed_user_ids = [user_id for user_id in user_ids if user_id not in found_user_ids] if missed_user_ids: - raise JsonableError(_("Invalid user ID: %s" % (missed_user_ids[0],))) + raise JsonableError(_("Invalid user ID: %s") % (missed_user_ids[0],)) user_profiles = list(user_profiles_by_id.values()) for user_profile in user_profiles: if user_profile.realm != realm: - raise JsonableError(_("Invalid user ID: %s" % (user_profile.id,))) + raise JsonableError(_("Invalid user ID: %s") % (user_profile.id,)) return user_profiles def access_bot_by_id(user_profile: UserProfile, user_id: int) -> UserProfile: diff --git a/zerver/lib/validator.py b/zerver/lib/validator.py index 6353d80131..6aaae8e52c 100644 --- a/zerver/lib/validator.py +++ b/zerver/lib/validator.py @@ -60,8 +60,8 @@ def check_capped_string(max_length: int) -> Validator: if not isinstance(val, str): return _('%s is not a string') % (var_name,) if len(val) > max_length: - return _("{var_name} is too long (limit: {max_length} characters)".format( - var_name=var_name, max_length=max_length)) + return _("{var_name} is too long (limit: {max_length} characters)").format( + var_name=var_name, max_length=max_length) return None return validator @@ -70,8 +70,8 @@ def check_string_fixed_length(length: int) -> Validator: if not isinstance(val, str): return _('%s is not a string') % (var_name,) if len(val) != length: - return _("{var_name} has incorrect length {length}; should be {target_length}".format( - var_name=var_name, target_length=length, length=len(val))) + return _("{var_name} has incorrect length {length}; should be {target_length}").format( + var_name=var_name, target_length=length, length=len(val)) return None return validator @@ -174,7 +174,7 @@ def check_dict(required_keys: Iterable[Tuple[str, Validator]]=[], optional_keys_set = set(x[0] for x in optional_keys) delta_keys = set(val.keys()) - required_keys_set - optional_keys_set if len(delta_keys) != 0: - return _("Unexpected arguments: %s" % (", ".join(list(delta_keys)),)) + return _("Unexpected arguments: %s") % (", ".join(list(delta_keys)),) return None diff --git a/zerver/models.py b/zerver/models.py index 57f944cb47..48affe900c 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -608,8 +608,8 @@ post_delete.connect(flush_realm_emoji, sender=RealmEmoji) def filter_pattern_validator(value: str) -> None: regex = re.compile(r'^(?:(?:[\w\-#_= /:]*|[+]|[!])(\(\?P<\w+>.+\)))+$') - error_msg = _('Invalid filter pattern. Valid characters are %s.' % ( - '[ a-zA-Z_#=/:+!-]',)) + error_msg = _('Invalid filter pattern. Valid characters are %s.') % ( + '[ a-zA-Z_#=/:+!-]',) if not regex.match(str(value)): raise ValidationError(error_msg) diff --git a/zerver/views/invite.py b/zerver/views/invite.py index 93ec38db5c..90396859ed 100644 --- a/zerver/views/invite.py +++ b/zerver/views/invite.py @@ -48,7 +48,7 @@ def invite_users_backend(request: HttpRequest, user_profile: UserProfile, (stream, recipient, sub) = access_stream_by_id(user_profile, stream_id) except JsonableError: return json_error( - _("Stream does not exist with id: {}. No invites were sent.".format(stream_id))) + _("Stream does not exist with id: {}. No invites were sent.").format(stream_id)) streams.append(stream) do_invite_users(user_profile, invitee_emails, streams, invite_as) @@ -128,7 +128,7 @@ def generate_multiuse_invite_backend( try: (stream, recipient, sub) = access_stream_by_id(user_profile, stream_id) except JsonableError: - return json_error(_("Invalid stream id {}. No invites were sent.".format(stream_id))) + return json_error(_("Invalid stream id {}. No invites were sent.").format(stream_id)) streams.append(stream) invite_link = do_create_multiuse_invite_link(user_profile, invite_as, streams) diff --git a/zerver/views/messages.py b/zerver/views/messages.py index ccdee5f415..e930f8fc06 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -717,8 +717,8 @@ def get_messages_backend(request: HttpRequest, user_profile: UserProfile, if anchor is None and not use_first_unread_anchor: return json_error(_("Missing 'anchor' argument (or set 'use_first_unread_anchor'=True).")) if num_before + num_after > MAX_MESSAGES_PER_FETCH: - return json_error(_("Too many messages requested (maximum %s)." - % (MAX_MESSAGES_PER_FETCH,))) + return json_error(_("Too many messages requested (maximum %s).") + % (MAX_MESSAGES_PER_FETCH,)) include_history = ok_to_include_history(narrow, user_profile) if include_history: diff --git a/zerver/views/presence.py b/zerver/views/presence.py index e58caa0a17..c000ea6348 100644 --- a/zerver/views/presence.py +++ b/zerver/views/presence.py @@ -37,7 +37,7 @@ def get_presence_backend(request: HttpRequest, user_profile: UserProfile, presence_dict = UserPresence.get_status_dict_by_user(target) if len(presence_dict) == 0: - return json_error(_('No presence data for %s' % (target.email,))) + return json_error(_('No presence data for %s') % (target.email,)) # For initial version, we just include the status and timestamp keys result = dict(presence=presence_dict[target.email]) diff --git a/zerver/views/realm.py b/zerver/views/realm.py index 3eb38417b8..229160d563 100644 --- a/zerver/views/realm.py +++ b/zerver/views/realm.py @@ -73,7 +73,7 @@ def update_realm( # Additional validation/error checking beyond types go here, so # the entire request can succeed or fail atomically. if default_language is not None and default_language not in get_available_language_codes(): - raise JsonableError(_("Invalid language '%s'" % (default_language,))) + raise JsonableError(_("Invalid language '%s'") % (default_language,)) if description is not None and len(description) > 1000: return json_error(_("Organization description is too long.")) if name is not None and len(name) > Realm.MAX_REALM_NAME_LENGTH: diff --git a/zerver/views/realm_domains.py b/zerver/views/realm_domains.py index a932f3b2f5..85d014226a 100644 --- a/zerver/views/realm_domains.py +++ b/zerver/views/realm_domains.py @@ -40,7 +40,7 @@ def patch_realm_domain(request: HttpRequest, user_profile: UserProfile, domain: realm_domain = RealmDomain.objects.get(realm=user_profile.realm, domain=domain) do_change_realm_domain(realm_domain, allow_subdomains) except RealmDomain.DoesNotExist: - return json_error(_('No entry found for domain %(domain)s.' % {'domain': domain})) + return json_error(_('No entry found for domain %(domain)s.') % {'domain': domain}) return json_success() @require_realm_admin @@ -51,5 +51,5 @@ def delete_realm_domain(request: HttpRequest, user_profile: UserProfile, realm_domain = RealmDomain.objects.get(realm=user_profile.realm, domain=domain) do_remove_realm_domain(realm_domain) except RealmDomain.DoesNotExist: - return json_error(_('No entry found for domain %(domain)s.' % {'domain': domain})) + return json_error(_('No entry found for domain %(domain)s.') % {'domain': domain}) return json_success() diff --git a/zerver/views/realm_emoji.py b/zerver/views/realm_emoji.py index 8c157809c5..83c8b6dfde 100644 --- a/zerver/views/realm_emoji.py +++ b/zerver/views/realm_emoji.py @@ -49,7 +49,7 @@ def delete_emoji(request: HttpRequest, user_profile: UserProfile, if not RealmEmoji.objects.filter(realm=user_profile.realm, name=emoji_name, deactivated=False).exists(): - raise JsonableError(_("Emoji '%s' does not exist" % (emoji_name,))) + raise JsonableError(_("Emoji '%s' does not exist") % (emoji_name,)) check_emoji_admin(user_profile, emoji_name) do_remove_realm_emoji(user_profile.realm, emoji_name) return json_success() diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 70c6e6dd58..a3e7cd172a 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -266,12 +266,12 @@ def you_were_just_subscribed_message(acting_user: UserProfile, stream_names: Set[str]) -> str: subscriptions = sorted(list(stream_names)) if len(subscriptions) == 1: - return _("Hi there! @**%(full_name)s** just subscribed you to the stream #**%(stream_name)s**." % - {"full_name": acting_user.full_name, - "stream_name": subscriptions[0]}) + return _("Hi there! @**%(full_name)s** just subscribed you to the stream #**%(stream_name)s**.") % \ + {"full_name": acting_user.full_name, + "stream_name": subscriptions[0]} - message = _("Hi there! @**%(full_name)s** just subscribed you to the following streams:" % - {"full_name": acting_user.full_name}) + message = _("Hi there! @**%(full_name)s** just subscribed you to the following streams:") % \ + {"full_name": acting_user.full_name} message += "\n\n" for stream_name in subscriptions: message += "* #**%s**\n" % (stream_name,) diff --git a/zerver/views/user_groups.py b/zerver/views/user_groups.py index 22ef31f1fc..0b7c7775e1 100644 --- a/zerver/views/user_groups.py +++ b/zerver/views/user_groups.py @@ -92,7 +92,7 @@ def add_members_to_group_backend(request: HttpRequest, user_profile: UserProfile for user_profile in user_profiles: if user_profile.id in existing_member_ids: - raise JsonableError(_("User %s is already a member of this group" % (user_profile.id,))) + raise JsonableError(_("User %s is already a member of this group") % (user_profile.id,)) bulk_add_members_to_user_group(user_group, user_profiles) return json_success() @@ -107,7 +107,7 @@ def remove_members_from_group_backend(request: HttpRequest, user_profile: UserPr group_member_ids = get_user_group_members(user_group) for member in members: if (member not in group_member_ids): - raise JsonableError(_("There is no member '%s' in this user group" % (member,))) + raise JsonableError(_("There is no member '%s' in this user group") % (member,)) remove_members_from_user_group(user_group, user_profiles) return json_success() diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index e8d686d0ed..5843374a5f 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -127,15 +127,15 @@ def update_display_settings_backend( if (default_language is not None and default_language not in get_available_language_codes()): - raise JsonableError(_("Invalid language '%s'" % (default_language,))) + raise JsonableError(_("Invalid language '%s'") % (default_language,)) if (timezone is not None and timezone not in get_all_timezones()): - raise JsonableError(_("Invalid timezone '%s'" % (timezone,))) + raise JsonableError(_("Invalid timezone '%s'") % (timezone,)) if (emojiset is not None and emojiset not in UserProfile.emojiset_choices()): - raise JsonableError(_("Invalid emojiset '%s'" % (emojiset,))) + raise JsonableError(_("Invalid emojiset '%s'") % (emojiset,)) request_settings = {k: v for k, v in list(locals().items()) if k in user_profile.property_types} result = {} # type: Dict[str, Any] diff --git a/zerver/webhooks/librato/view.py b/zerver/webhooks/librato/view.py index 58e15fa400..877c65ee4a 100644 --- a/zerver/webhooks/librato/view.py +++ b/zerver/webhooks/librato/view.py @@ -159,7 +159,7 @@ def api_librato_webhook(request: HttpRequest, user_profile: UserProfile, try: content = message_handler.handle() except Exception as e: - return json_error(_(str(e))) + return json_error(str(e)) check_send_webhook_message(request, user_profile, topic, content) return json_success() diff --git a/zerver/webhooks/wordpress/view.py b/zerver/webhooks/wordpress/view.py index c489980bd4..bdf0898343 100644 --- a/zerver/webhooks/wordpress/view.py +++ b/zerver/webhooks/wordpress/view.py @@ -42,7 +42,7 @@ def api_wordpress_webhook(request: HttpRequest, user_profile: UserProfile, data = WP_LOGIN_TEMPLATE.format(name=user_login) else: - return json_error(_("Unknown WordPress webhook action: " + hook)) + return json_error(_("Unknown WordPress webhook action: %s") % (hook,)) topic = 'WordPress Notification' diff --git a/zilencer/views.py b/zilencer/views.py index a8dc7c9c1e..5045906bbf 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -155,7 +155,7 @@ def validate_count_stats(server: RemoteZulipServer, model: Any, last_id = get_last_id_from_server(server, model) for item in counts: if item['property'] not in COUNT_STATS: - raise JsonableError(_("Invalid property %s" % (item['property'],))) + raise JsonableError(_("Invalid property %s") % (item['property'],)) if item['id'] <= last_id: raise JsonableError(_("Data is out of order.")) last_id = item['id']