diff --git a/zerver/management/commands/check_redis.py b/zerver/management/commands/check_redis.py index ba4accfeb8..bc94e12b59 100644 --- a/zerver/management/commands/check_redis.py +++ b/zerver/management/commands/check_redis.py @@ -12,7 +12,8 @@ import logging import time class Command(BaseCommand): - help = """Checks redis to make sure our rate limiting system hasn't grown a bug and left redis with a bunch of data + help = """Checks redis to make sure our rate limiting system hasn't grown a bug + and left redis with a bunch of data Usage: ./manage.py [--trim] check_redis""" diff --git a/zerver/management/commands/create_default_stream_groups.py b/zerver/management/commands/create_default_stream_groups.py index c1f8089c82..f4968e30f2 100644 --- a/zerver/management/commands/create_default_stream_groups.py +++ b/zerver/management/commands/create_default_stream_groups.py @@ -45,9 +45,11 @@ Create default stream groups which the users can choose during sign up. streams.append(stream) try: - default_stream_group = DefaultStreamGroup.objects.get(name=options["default_stream_group"], realm=realm) + default_stream_group = DefaultStreamGroup.objects.get( + name=options["default_stream_group"], realm=realm) except DefaultStreamGroup.DoesNotExist: - default_stream_group = DefaultStreamGroup.objects.create(name=options["default_stream_group"], realm=realm) + default_stream_group = DefaultStreamGroup.objects.create( + name=options["default_stream_group"], realm=realm) default_stream_group.streams = streams default_stream_group.save() diff --git a/zerver/management/commands/create_user.py b/zerver/management/commands/create_user.py index 880a1cf39d..abc68ad3ea 100644 --- a/zerver/management/commands/create_user.py +++ b/zerver/management/commands/create_user.py @@ -46,7 +46,8 @@ Omit both and for interactive user creation. help='The file containing the password of the new user.') parser.add_argument('email', metavar='', type=str, nargs='?', default=argparse.SUPPRESS, help='email address of new user') - parser.add_argument('full_name', metavar='', type=str, nargs='?', default=argparse.SUPPRESS, + parser.add_argument('full_name', metavar='', type=str, nargs='?', + default=argparse.SUPPRESS, help='full name of new user') self.add_realm_args(parser, True, "The name of the existing realm to which to add the user.") diff --git a/zerver/management/commands/deliver_email.py b/zerver/management/commands/deliver_email.py index 46b27e0417..62e455cf4e 100644 --- a/zerver/management/commands/deliver_email.py +++ b/zerver/management/commands/deliver_email.py @@ -43,7 +43,8 @@ Usage: ./manage.py deliver_email with lockfile("/tmp/zulip_email_deliver.lockfile"): while True: - email_jobs_to_deliver = ScheduledEmail.objects.filter(scheduled_timestamp__lte=timezone_now()) + email_jobs_to_deliver = ScheduledEmail.objects.filter( + scheduled_timestamp__lte=timezone_now()) if email_jobs_to_deliver: for job in email_jobs_to_deliver: try: @@ -53,5 +54,6 @@ Usage: ./manage.py deliver_email logger.warning("%r not delivered" % (job,)) time.sleep(10) else: - # Less load on the db during times of activity, and more responsiveness when the load is low + # Less load on the db during times of activity, + # and more responsiveness when the load is low time.sleep(2) diff --git a/zerver/management/commands/generate_realm_creation_link.py b/zerver/management/commands/generate_realm_creation_link.py index c5c078e730..724194d2e4 100644 --- a/zerver/management/commands/generate_realm_creation_link.py +++ b/zerver/management/commands/generate_realm_creation_link.py @@ -31,7 +31,8 @@ class Command(BaseCommand): sys.exit(1) url = generate_realm_creation_url() - self.stdout.write(self.style.SUCCESS("Please visit the following secure single-use link to register your ")) + self.stdout.write(self.style.SUCCESS("Please visit the following " + "secure single-use link to register your ")) self.stdout.write(self.style.SUCCESS("new Zulip organization:\033[0m")) self.stdout.write("") self.stdout.write(self.style.SUCCESS(" \033[1;92m%s\033[0m" % (url,))) diff --git a/zerver/management/commands/import.py b/zerver/management/commands/import.py index bce9e4a9b3..068ac8229d 100644 --- a/zerver/management/commands/import.py +++ b/zerver/management/commands/import.py @@ -43,7 +43,8 @@ import a database dump from one or more JSON files.""" if count: print("Zulip instance is not empty, found %d rows in %s table. " % (count, model._meta.db_table)) - print("You may use --destroy-rebuild-database to destroy and rebuild the database prior to import.") + print("You may use --destroy-rebuild-database to destroy and " + "rebuild the database prior to import.") exit(1) def do_destroy_and_rebuild_database(self, db_name: str) -> None: diff --git a/zerver/management/commands/makemessages.py b/zerver/management/commands/makemessages.py index 32aee21510..9aa5d39a9e 100644 --- a/zerver/management/commands/makemessages.py +++ b/zerver/management/commands/makemessages.py @@ -25,7 +25,7 @@ unfortunately isn't extensible, so we can: We are currently doing that last thing. It turns out there we are lucky for once: It's simply a matter of extending two regular expressions. Credit for the approach goes to: -http://stackoverflow.com/questions/2090717/getting-translation-strings-for-jinja2-templates-integrated-with-django-1-x +http://stackoverflow.com/questions/2090717 """ @@ -44,7 +44,8 @@ from django.utils.translation import template from zerver.lib.str_utils import force_text -strip_whitespace_right = re.compile("(%s-?\\s*(trans|pluralize).*?-%s)\\s+" % (BLOCK_TAG_START, BLOCK_TAG_END), re.U) +strip_whitespace_right = re.compile("(%s-?\\s*(trans|pluralize).*?-%s)\\s+" % ( + BLOCK_TAG_START, BLOCK_TAG_END), re.U) strip_whitespace_left = re.compile("\\s+(%s-\\s*(endtrans|pluralize).*?-?%s)" % ( BLOCK_TAG_START, BLOCK_TAG_END), re.U) diff --git a/zerver/management/commands/soft_deactivate_users.py b/zerver/management/commands/soft_deactivate_users.py index bec65f84c0..a7952d97c8 100644 --- a/zerver/management/commands/soft_deactivate_users.py +++ b/zerver/management/commands/soft_deactivate_users.py @@ -64,7 +64,8 @@ class Command(ZulipBaseCommand): user_emails_found = [user.email for user in users_to_activate] for user in user_emails: if user not in user_emails_found: - raise Exception('User with email %s was not found. Check if the email is correct.' % (user)) + raise Exception('User with email %s was not found. ' + 'Check if the email is correct.' % (user)) users_activated = do_soft_activate_users(users_to_activate) logger.info('Soft Reactivated %d user(s)' % (len(users_activated))) @@ -86,7 +87,8 @@ class Command(ZulipBaseCommand): else: if realm is not None: filter_kwargs = dict(user_profile__realm=realm) - users_to_deactivate = get_users_for_soft_deactivation(int(options['inactive_for']), filter_kwargs) + users_to_deactivate = get_users_for_soft_deactivation(int(options['inactive_for']), + filter_kwargs) if users_to_deactivate: users_deactivated = do_soft_deactivate_users(users_to_deactivate) diff --git a/zerver/models.py b/zerver/models.py index 9c693ece12..cf51f7fa28 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -374,7 +374,8 @@ def get_realm_domains(realm): class RealmEmoji(models.Model): author = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE) realm = models.ForeignKey(Realm, on_delete=CASCADE) # type: Realm - # Second part of the regex (negative lookbehind) disallows names ending with one of the punctuation characters + # Second part of the regex (negative lookbehind) disallows names ending with + # one of the punctuation characters name = models.TextField(validators=[MinLengthValidator(1), RegexValidator(regex=r'^[0-9a-z.\-_]+(? Dict[int, List[Tuple[Text, Text, int]]] filters = defaultdict(list) # type: DefaultDict[int, List[Tuple[Text, Text, int]]] for realm_filter in RealmFilter.objects.all(): - filters[realm_filter.realm_id].append((realm_filter.pattern, realm_filter.url_format_string, realm_filter.id)) + filters[realm_filter.realm_id].append((realm_filter.pattern, + realm_filter.url_format_string, + realm_filter.id)) return filters @@ -503,7 +507,8 @@ class UserProfile(AbstractBaseUser, PermissionsMixin): since they can't be used to read messages. """ INCOMING_WEBHOOK_BOT = 2 - # This value is also being used in static/js/settings_bots.js. On updating it here, update it there as well. + # This value is also being used in static/js/settings_bots.js. + # On updating it here, update it there as well. OUTGOING_WEBHOOK_BOT = 3 """ Embedded bots run within the Zulip server itself; events are added to the @@ -1207,7 +1212,8 @@ class Message(AbstractMessage): @staticmethod def content_has_image(content): # type: (Text) -> bool - return bool(re.search(r'[/\-]user[\-_]uploads[/\.-]\S+\.(bmp|gif|jpg|jpeg|png|webp)', content, re.IGNORECASE)) + return bool(re.search(r'[/\-]user[\-_]uploads[/\.-]\S+\.(bmp|gif|jpg|jpeg|png|webp)', + content, re.IGNORECASE)) @staticmethod def content_has_link(content): @@ -1972,8 +1978,9 @@ class Service(models.Model): def get_realm_outgoing_webhook_services_name(realm): # type: (Realm) -> List[Any] - return list(Service.objects.filter(user_profile__realm=realm, user_profile__is_bot=True, - user_profile__bot_type=UserProfile.OUTGOING_WEBHOOK_BOT).values('name')) + return list(Service.objects.filter( + user_profile__realm=realm, user_profile__is_bot=True, + user_profile__bot_type=UserProfile.OUTGOING_WEBHOOK_BOT).values('name')) def get_bot_services(user_profile_id): # type: (str) -> List[Service] diff --git a/zerver/views/messages.py b/zerver/views/messages.py index e1e7aa3f58..24bcec7406 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -61,8 +61,11 @@ class BadNarrowOperator(JsonableError): # type: () -> str return _('Invalid narrow operator: {desc}') -Query = Any # TODO: Should be Select, but sqlalchemy stubs are busted -ConditionTransform = Any # TODO: should be Callable[[ColumnElement], ColumnElement], but sqlalchemy stubs are busted +# TODO: Should be Select, but sqlalchemy stubs are busted +Query = Any + +# TODO: should be Callable[[ColumnElement], ColumnElement], but sqlalchemy stubs are busted +ConditionTransform = Any # When you add a new operator to this, also update zerver/lib/narrow.py class NarrowBuilder: diff --git a/zerver/views/report.py b/zerver/views/report.py index 082394ab45..928153749f 100644 --- a/zerver/views/report.py +++ b/zerver/views/report.py @@ -38,7 +38,8 @@ def report_send_times(request: HttpRequest, user_profile: UserProfile, received: int=REQ(converter=to_non_negative_int, default=-1), displayed: int=REQ(converter=to_non_negative_int, default=-1), locally_echoed: bool=REQ(validator=check_bool, default=False), - rendered_content_disparity: bool=REQ(validator=check_bool, default=False)) -> HttpResponse: + rendered_content_disparity: bool=REQ(validator=check_bool, + default=False)) -> HttpResponse: received_str = "(unknown)" if received > 0: received_str = str(received)