diff --git a/tools/run-mypy b/tools/run-mypy index c5c9773265..84e933ec72 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -41,7 +41,6 @@ exclude_py2 = [] exclude_py3 = """ zerver/lib/ccache.py -zerver/management/commands/create_stream.py zerver/management/commands/email-mirror.py zerver/management/commands/enqueue_file.py zerver/management/commands/rename_stream.py diff --git a/zerver/management/commands/create_stream.py b/zerver/management/commands/create_stream.py index 3d2bdf94ea..5721938ff6 100644 --- a/zerver/management/commands/create_stream.py +++ b/zerver/management/commands/create_stream.py @@ -1,11 +1,13 @@ from __future__ import absolute_import from __future__ import print_function +from six import text_type from typing import Any from django.core.management.base import BaseCommand from zerver.lib.actions import do_create_stream +from zerver.lib.str_utils import force_text from zerver.models import Realm, get_realm from argparse import ArgumentParser @@ -27,13 +29,12 @@ the command.""" def handle(self, *args, **options): # type: (*Any, **str) -> None domain = options['domain'] - stream_name = options['stream_name'] encoding = sys.getfilesystemencoding() + stream_name = options['stream_name'] - try: - realm = get_realm(domain) - except Realm.DoesNotExist: + realm = get_realm(force_text(domain, encoding)) + if realm is None: print("Unknown domain %s" % (domain,)) exit(1) - - do_create_stream(realm, stream_name.decode(encoding)) + else: + do_create_stream(realm, force_text(stream_name, encoding))