create_stream.py: Fix broken code.

* get_realm returns None if no matching realm is present, but
  create_stream.py assumed it raises Realm.DoesNotExist.
* encoded/decode strings properly.
This commit is contained in:
Eklavya Sharma 2016-07-05 07:09:01 +05:30 committed by Tim Abbott
parent 7956fcbf0d
commit 17cb6e00bd
2 changed files with 7 additions and 7 deletions

View File

@ -41,7 +41,6 @@ exclude_py2 = []
exclude_py3 = """ exclude_py3 = """
zerver/lib/ccache.py zerver/lib/ccache.py
zerver/management/commands/create_stream.py
zerver/management/commands/email-mirror.py zerver/management/commands/email-mirror.py
zerver/management/commands/enqueue_file.py zerver/management/commands/enqueue_file.py
zerver/management/commands/rename_stream.py zerver/management/commands/rename_stream.py

View File

@ -1,11 +1,13 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function from __future__ import print_function
from six import text_type
from typing import Any from typing import Any
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.lib.actions import do_create_stream from zerver.lib.actions import do_create_stream
from zerver.lib.str_utils import force_text
from zerver.models import Realm, get_realm from zerver.models import Realm, get_realm
from argparse import ArgumentParser from argparse import ArgumentParser
@ -27,13 +29,12 @@ the command."""
def handle(self, *args, **options): def handle(self, *args, **options):
# type: (*Any, **str) -> None # type: (*Any, **str) -> None
domain = options['domain'] domain = options['domain']
stream_name = options['stream_name']
encoding = sys.getfilesystemencoding() encoding = sys.getfilesystemencoding()
stream_name = options['stream_name']
try: realm = get_realm(force_text(domain, encoding))
realm = get_realm(domain) if realm is None:
except Realm.DoesNotExist:
print("Unknown domain %s" % (domain,)) print("Unknown domain %s" % (domain,))
exit(1) exit(1)
else:
do_create_stream(realm, stream_name.decode(encoding)) do_create_stream(realm, force_text(stream_name, encoding))