mirror of https://github.com/zulip/zulip.git
zilencer: Use python 3 syntax for typing.
This commit is contained in:
parent
0449dc8b8a
commit
138c486548
|
@ -30,13 +30,11 @@ From image editing program:
|
|||
* Remove mute (and edit) icons from recipient bar
|
||||
"""
|
||||
|
||||
def set_avatar(self, user, filename):
|
||||
# type: (UserProfile, str) -> None
|
||||
def set_avatar(self, user: UserProfile, filename: str) -> None:
|
||||
upload_avatar_image(open(filename, 'rb'), user, user)
|
||||
do_change_avatar_fields(user, UserProfile.AVATAR_FROM_USER)
|
||||
|
||||
def add_message_formatting_conversation(self):
|
||||
# type: () -> None
|
||||
def add_message_formatting_conversation(self) -> None:
|
||||
realm = get_realm('zulip')
|
||||
stream, _ = create_stream_if_needed(realm, 'zulip features')
|
||||
|
||||
|
@ -106,6 +104,5 @@ From image editing program:
|
|||
# thumbs_up shows up second
|
||||
do_add_reaction_legacy(starr, preview_message, 'thumbs_up')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
def handle(self, *args: Any, **options: str) -> None:
|
||||
self.add_message_formatting_conversation()
|
||||
|
|
|
@ -9,8 +9,7 @@ from zerver.models import Realm, UserProfile
|
|||
class Command(ZulipBaseCommand):
|
||||
help = """Add a new realm and initial user for manual testing of the onboarding process."""
|
||||
|
||||
def handle(self, **options):
|
||||
# type: (**Any) -> None
|
||||
def handle(self, **options: Any) -> None:
|
||||
string_id = 'realm%02d' % (
|
||||
Realm.objects.filter(string_id__startswith='realm').count(),)
|
||||
realm = do_create_realm(string_id, string_id)
|
||||
|
|
|
@ -11,12 +11,10 @@ class Command(ZulipBaseCommand):
|
|||
If realm is unspecified, will try to use a realm created by add_new_realm,
|
||||
and will otherwise fall back to the zulip realm."""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# type: (CommandParser) -> None
|
||||
def add_arguments(self, parser: CommandParser) -> None:
|
||||
self.add_realm_args(parser)
|
||||
|
||||
def handle(self, **options):
|
||||
# type: (**Any) -> None
|
||||
def handle(self, **options: Any) -> None:
|
||||
realm = self.get_realm(options)
|
||||
if realm is None:
|
||||
realm = Realm.objects.filter(string_id__startswith='realm') \
|
||||
|
|
|
@ -9,13 +9,11 @@ class Command(BaseCommand):
|
|||
Usage: ./manage.py render_messages <destination> <--amount>
|
||||
"""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# type: (CommandParser) -> None
|
||||
def add_arguments(self, parser: CommandParser) -> None:
|
||||
parser.add_argument('dump1', help='First file to compare')
|
||||
parser.add_argument('dump2', help='Second file to compare')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
total_count = 0
|
||||
changed_count = 0
|
||||
with open(options['dump1'], 'r') as dump1, open(options['dump2'], 'r') as dump2:
|
||||
|
|
|
@ -11,8 +11,7 @@ from zerver.models import UserMessage, UserProfile
|
|||
class Command(BaseCommand):
|
||||
help = """Script to mark all messages as unread."""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
assert settings.DEVELOPMENT
|
||||
UserMessage.objects.all().update(flags=F('flags').bitand(~UserMessage.flags.read))
|
||||
UserProfile.objects.all().update(pointer=0)
|
||||
|
|
|
@ -8,8 +8,7 @@ from zerver.models import Subscription
|
|||
class Command(BaseCommand):
|
||||
help = """One-off script to migration users' stream notification settings."""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
for subscription in Subscription.objects.all():
|
||||
subscription.desktop_notifications = subscription.notifications
|
||||
subscription.audible_notifications = subscription.notifications
|
||||
|
|
|
@ -30,8 +30,9 @@ settings.CACHES['default'] = {
|
|||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'
|
||||
}
|
||||
|
||||
def create_users(realm, name_list, bot_type=None, bot_owner=None):
|
||||
# type: (Realm, Iterable[Tuple[Text, Text]], Optional[int], Optional[UserProfile]) -> None
|
||||
def create_users(realm: Realm, name_list: Iterable[Tuple[Text, Text]],
|
||||
bot_type: Optional[int]=None,
|
||||
bot_owner: Optional[UserProfile]=None) -> None:
|
||||
user_set = set() # type: Set[Tuple[Text, Text, Text, bool]]
|
||||
for full_name, email in name_list:
|
||||
short_name = email_to_username(email)
|
||||
|
@ -42,8 +43,7 @@ def create_users(realm, name_list, bot_type=None, bot_owner=None):
|
|||
class Command(BaseCommand):
|
||||
help = "Populate a test database"
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# type: (CommandParser) -> None
|
||||
def add_arguments(self, parser: CommandParser) -> None:
|
||||
parser.add_argument('-n', '--num-messages',
|
||||
dest='num_messages',
|
||||
type=int,
|
||||
|
@ -109,8 +109,7 @@ class Command(BaseCommand):
|
|||
action="store_true",
|
||||
help='Whether to delete all the existing messages.')
|
||||
|
||||
def handle(self, **options):
|
||||
# type: (**Any) -> None
|
||||
def handle(self, **options: Any) -> None:
|
||||
if options["percent_huddles"] + options["percent_personals"] > 100:
|
||||
self.stderr.write("Error! More than 100% of messages allocated.\n")
|
||||
return
|
||||
|
@ -395,8 +394,7 @@ class Command(BaseCommand):
|
|||
self.stdout.write("Successfully populated test database.\n")
|
||||
|
||||
recipient_hash = {} # type: Dict[int, Recipient]
|
||||
def get_recipient_by_id(rid):
|
||||
# type: (int) -> Recipient
|
||||
def get_recipient_by_id(rid: int) -> Recipient:
|
||||
if rid in recipient_hash:
|
||||
return recipient_hash[rid]
|
||||
return Recipient.objects.get(id=rid)
|
||||
|
@ -408,8 +406,8 @@ def get_recipient_by_id(rid):
|
|||
# - multiple personals converastions
|
||||
# - multiple messages per subject
|
||||
# - both single and multi-line content
|
||||
def send_messages(data):
|
||||
# type: (Tuple[int, Sequence[Sequence[int]], Mapping[str, Any], Callable[[str], Any], int]) -> int
|
||||
def send_messages(data: Tuple[int, Sequence[Sequence[int]], Mapping[str, Any],
|
||||
Callable[[str], Any], int]) -> int:
|
||||
(tot_messages, personals_pairs, options, output, random_seed) = data
|
||||
random.seed(random_seed)
|
||||
|
||||
|
@ -492,8 +490,7 @@ def send_messages(data):
|
|||
num_messages += 1
|
||||
return tot_messages
|
||||
|
||||
def create_user_presences(user_profiles):
|
||||
# type: (Iterable[UserProfile]) -> None
|
||||
def create_user_presences(user_profiles: Iterable[UserProfile]) -> None:
|
||||
for user in user_profiles:
|
||||
status = 1 # type: int
|
||||
date = timezone_now()
|
||||
|
|
|
@ -9,14 +9,12 @@ class Command(ZulipBaseCommand):
|
|||
|
||||
fmt = '%-30s %-16s %-32s'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# type: (ArgumentParser) -> None
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
parser.add_argument('emails', metavar='<email>', type=str, nargs='*',
|
||||
help="email of user to show password and API key for")
|
||||
self.add_realm_args(parser)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **str) -> None
|
||||
def handle(self, *args: Any, **options: str) -> None:
|
||||
realm = self.get_realm(options)
|
||||
print(self.fmt % ('email', 'password', 'API key'))
|
||||
for email in options['emails']:
|
||||
|
|
|
@ -13,13 +13,11 @@ from zerver.views.messages import get_messages_backend
|
|||
request_logger = LogRequests()
|
||||
|
||||
class MockSession:
|
||||
def __init__(self):
|
||||
# type: () -> None
|
||||
def __init__(self) -> None:
|
||||
self.modified = False
|
||||
|
||||
class MockRequest(HttpRequest):
|
||||
def __init__(self, user):
|
||||
# type: (UserProfile) -> None
|
||||
def __init__(self, user: UserProfile) -> None:
|
||||
self.user = user
|
||||
self.path = '/'
|
||||
self.method = "POST"
|
||||
|
@ -33,12 +31,10 @@ class MockRequest(HttpRequest):
|
|||
self.GET = {} # type: Dict[Any, Any]
|
||||
self.session = MockSession()
|
||||
|
||||
def get_full_path(self):
|
||||
# type: () -> str
|
||||
def get_full_path(self) -> str:
|
||||
return self.path
|
||||
|
||||
def profile_request(request):
|
||||
# type: (HttpRequest) -> HttpResponse
|
||||
def profile_request(request: HttpRequest) -> HttpResponse:
|
||||
request_logger.process_request(request)
|
||||
prof = cProfile.Profile()
|
||||
prof.enable()
|
||||
|
@ -51,13 +47,11 @@ def profile_request(request):
|
|||
return ret
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
# type: (CommandParser) -> None
|
||||
def add_arguments(self, parser: CommandParser) -> None:
|
||||
parser.add_argument("email", metavar="<email>", type=str, help="Email address of the user")
|
||||
self.add_realm_args(parser)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
realm = self.get_realm(options)
|
||||
user = self.get_user(options["email"], realm)
|
||||
profile_request(MockRequest(user))
|
||||
|
|
|
@ -8,8 +8,7 @@ from django.db.models import QuerySet
|
|||
from zerver.lib.message import render_markdown
|
||||
from zerver.models import Message
|
||||
|
||||
def queryset_iterator(queryset, chunksize=5000):
|
||||
# type: (QuerySet, int) -> Iterator[Any]
|
||||
def queryset_iterator(queryset: QuerySet, chunksize: int=5000) -> Iterator[Any]:
|
||||
queryset = queryset.order_by('id')
|
||||
while queryset.exists():
|
||||
for row in queryset[:chunksize]:
|
||||
|
@ -24,14 +23,12 @@ class Command(BaseCommand):
|
|||
Usage: ./manage.py render_messages <destination> [--amount=10000]
|
||||
"""
|
||||
|
||||
def add_arguments(self, parser):
|
||||
# type: (CommandParser) -> None
|
||||
def add_arguments(self, parser: CommandParser) -> None:
|
||||
parser.add_argument('destination', help='Destination file path')
|
||||
parser.add_argument('--amount', default=100000, help='Number of messages to render')
|
||||
parser.add_argument('--latest_id', default=0, help="Last message id to render")
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
dest_dir = os.path.realpath(os.path.dirname(options['destination']))
|
||||
amount = int(options['amount'])
|
||||
latest = int(options['latest_id']) or Message.objects.latest('id').id
|
||||
|
|
|
@ -9,8 +9,7 @@ from zerver.models import UserProfile, get_realm, get_user
|
|||
class Command(BaseCommand):
|
||||
help = """Sync your API key from ~/.zuliprc into your development instance"""
|
||||
|
||||
def handle(self, *args, **options):
|
||||
# type: (*Any, **Any) -> None
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
config_file = os.path.join(os.environ["HOME"], ".zuliprc")
|
||||
if not os.path.exists(config_file):
|
||||
raise RuntimeError("No ~/.zuliprc found")
|
||||
|
|
|
@ -5,8 +5,7 @@ from django.db import models
|
|||
|
||||
import zerver.models
|
||||
|
||||
def get_remote_server_by_uuid(uuid):
|
||||
# type: (Text) -> RemoteZulipServer
|
||||
def get_remote_server_by_uuid(uuid: Text) -> 'RemoteZulipServer':
|
||||
return RemoteZulipServer.objects.get(uuid=uuid)
|
||||
|
||||
class RemoteZulipServer(models.Model):
|
||||
|
|
|
@ -15,13 +15,12 @@ from zerver.models import UserProfile
|
|||
from zerver.views.push_notifications import validate_token
|
||||
from zilencer.models import RemotePushDeviceToken, RemoteZulipServer
|
||||
|
||||
def validate_entity(entity):
|
||||
# type: (Union[UserProfile, RemoteZulipServer]) -> None
|
||||
def validate_entity(entity: Union[UserProfile, RemoteZulipServer]) -> None:
|
||||
if not isinstance(entity, RemoteZulipServer):
|
||||
raise JsonableError(_("Must validate with valid Zulip server API key"))
|
||||
|
||||
def validate_bouncer_token_request(entity, token, kind):
|
||||
# type: (Union[UserProfile, RemoteZulipServer], bytes, int) -> None
|
||||
def validate_bouncer_token_request(entity: Union[UserProfile, RemoteZulipServer],
|
||||
token: bytes, kind: int) -> None:
|
||||
if kind not in [RemotePushDeviceToken.APNS, RemotePushDeviceToken.GCM]:
|
||||
raise JsonableError(_("Invalid token type"))
|
||||
validate_entity(entity)
|
||||
|
|
Loading…
Reference in New Issue