From 67bf71472aa7e920959b2f3c5b2a8474e4f847d6 Mon Sep 17 00:00:00 2001 From: Aditya Bansal Date: Fri, 11 May 2018 05:08:41 +0530 Subject: [PATCH] zilencer: Change use of typing.Text to str. --- zilencer/management/commands/populate_db.py | 12 ++++++------ zilencer/models.py | 11 +++++------ zilencer/views.py | 6 +++--- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 2f6c8988df..212cd027a6 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -2,7 +2,7 @@ import itertools import os import random from typing import Any, Callable, Dict, Iterable, List, \ - Mapping, Optional, Sequence, Set, Text, Tuple + Mapping, Optional, Sequence, Set, Tuple import ujson from django.conf import settings @@ -34,10 +34,10 @@ settings.CACHES['default'] = { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache' } -def create_users(realm: Realm, name_list: Iterable[Tuple[Text, Text]], +def create_users(realm: Realm, name_list: Iterable[Tuple[str, str]], bot_type: Optional[int]=None, bot_owner: Optional[UserProfile]=None) -> None: - user_set = set() # type: Set[Tuple[Text, Text, Text, bool]] + user_set = set() # type: Set[Tuple[str, str, str, bool]] for full_name, email in name_list: short_name = email_to_username(email) user_set.add((email, full_name, short_name, True)) @@ -229,7 +229,7 @@ class Command(BaseCommand): "invite_only": False, "is_web_public": False}, "Rome": {"description": "Yet another Italian city", "invite_only": False, "is_web_public": True} - } # type: Dict[Text, Dict[Text, Any]] + } # type: Dict[str, Dict[str, Any]] bulk_create_streams(zulip_realm, stream_dict) recipient_streams = [Stream.objects.get(name=name, realm=zulip_realm).id @@ -414,7 +414,7 @@ class Command(BaseCommand): "invite_only": False, "is_web_public": False}, "sales": {"description": "For sales discussion", "invite_only": False, "is_web_public": False} - } # type: Dict[Text, Dict[Text, Any]] + } # type: Dict[str, Dict[str, Any]] # Calculate the maximum number of digits in any extra stream's # number, since a stream with name "Extra Stream 3" could show @@ -578,7 +578,7 @@ def send_messages(data: Tuple[int, Sequence[Sequence[int]], Mapping[str, Any], # Pick a random subscriber to the stream message.sender = random.choice(Subscription.objects.filter( recipient=message.recipient)).user_profile - message.subject = stream.name + Text(random.randint(1, 3)) + message.subject = stream.name + str(random.randint(1, 3)) saved_data['subject'] = message.subject # Spoofing time not supported with threading diff --git a/zilencer/models.py b/zilencer/models.py index 232c49fc2f..101520935f 100644 --- a/zilencer/models.py +++ b/zilencer/models.py @@ -1,11 +1,10 @@ import datetime -from typing import Text from django.db import models from zerver.models import AbstractPushDeviceToken, Realm -def get_remote_server_by_uuid(uuid: Text) -> 'RemoteZulipServer': +def get_remote_server_by_uuid(uuid: str) -> 'RemoteZulipServer': return RemoteZulipServer.objects.get(uuid=uuid) class RemoteZulipServer(models.Model): @@ -13,11 +12,11 @@ class RemoteZulipServer(models.Model): API_KEY_LENGTH = 64 HOSTNAME_MAX_LENGTH = 128 - uuid = models.CharField(max_length=UUID_LENGTH, unique=True) # type: Text - api_key = models.CharField(max_length=API_KEY_LENGTH) # type: Text + uuid = models.CharField(max_length=UUID_LENGTH, unique=True) # type: str + api_key = models.CharField(max_length=API_KEY_LENGTH) # type: str - hostname = models.CharField(max_length=HOSTNAME_MAX_LENGTH) # type: Text - contact_email = models.EmailField(blank=True, null=False) # type: Text + hostname = models.CharField(max_length=HOSTNAME_MAX_LENGTH) # type: str + contact_email = models.EmailField(blank=True, null=False) # type: str last_updated = models.DateTimeField('last updated', auto_now=True) # type: datetime.datetime def __str__(self) -> str: diff --git a/zilencer/views.py b/zilencer/views.py index a69dd565d7..ec6352861e 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -1,5 +1,5 @@ -from typing import Any, Dict, Optional, Text, Union, cast +from typing import Any, Dict, Optional, Union, cast from django.core.exceptions import ValidationError from django.core.validators import validate_email, URLValidator @@ -84,7 +84,7 @@ def register_remote_server( def register_remote_push_device(request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], user_id: int=REQ(), token: bytes=REQ(), token_kind: int=REQ(validator=check_int), - ios_app_id: Optional[Text]=None) -> HttpResponse: + ios_app_id: Optional[str]=None) -> HttpResponse: validate_bouncer_token_request(entity, token, token_kind) server = cast(RemoteZulipServer, entity) @@ -110,7 +110,7 @@ def register_remote_push_device(request: HttpRequest, entity: Union[UserProfile, def unregister_remote_push_device(request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], token: bytes=REQ(), token_kind: int=REQ(validator=check_int), - ios_app_id: Optional[Text]=None) -> HttpResponse: + ios_app_id: Optional[str]=None) -> HttpResponse: validate_bouncer_token_request(entity, token, token_kind) server = cast(RemoteZulipServer, entity) deleted = RemotePushDeviceToken.objects.filter(token=token,