Add types to confirmation/views.py and zerver/tornadoviews.py

This commit is contained in:
Max 2016-06-02 18:47:17 -07:00 committed by Tim Abbott
parent 4fd569f910
commit a6e60419c4
2 changed files with 12 additions and 2 deletions

View File

@ -8,12 +8,14 @@ __revision__ = '$Id: views.py 21 2008-12-05 09:21:03Z jarek.zgoda $'
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from django.template import RequestContext from django.template import RequestContext
from django.conf import settings from django.conf import settings
from django.http import HttpRequest, HttpResponse
from confirmation.models import Confirmation from confirmation.models import Confirmation
from zproject.jinja2 import render_to_response from zproject.jinja2 import render_to_response
def confirm(request, confirmation_key): def confirm(request, confirmation_key):
# type: (HttpRequest, str) -> HttpResponse
confirmation_key = confirmation_key.lower() confirmation_key = confirmation_key.lower()
obj = Confirmation.objects.confirm(confirmation_key) obj = Confirmation.objects.confirm(confirmation_key)
confirmed = True confirmed = True

View File

@ -2,19 +2,23 @@ from __future__ import absolute_import
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from zerver.models import get_client from django.http import HttpRequest, HttpResponse
from zerver.models import get_client, UserProfile, Client
from zerver.decorator import asynchronous, \ from zerver.decorator import asynchronous, \
authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \ authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \
has_request_variables, REQ has_request_variables, REQ, _RespondAsynchronously
from zerver.lib.response import json_success, json_error from zerver.lib.response import json_success, json_error
from zerver.lib.validator import check_bool, check_list, check_string from zerver.lib.validator import check_bool, check_list, check_string
from zerver.lib.event_queue import allocate_client_descriptor, get_client_descriptor, \ from zerver.lib.event_queue import allocate_client_descriptor, get_client_descriptor, \
process_notification, fetch_events process_notification, fetch_events
from zerver.lib.handlers import allocate_handler_id from zerver.lib.handlers import allocate_handler_id
from zerver.lib.narrow import check_supported_events_narrow_filter from zerver.lib.narrow import check_supported_events_narrow_filter
from typing import Union, Optional, Tuple, List, Any
import time import time
import ujson import ujson
import logging import logging
@ -24,11 +28,13 @@ rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(req
@internal_notify_view @internal_notify_view
def notify(request): def notify(request):
# type: (HttpRequest) -> HttpResponse
process_notification(ujson.loads(request.POST['data'])) process_notification(ujson.loads(request.POST['data']))
return json_success() return json_success()
@has_request_variables @has_request_variables
def cleanup_event_queue(request, user_profile, queue_id=REQ()): def cleanup_event_queue(request, user_profile, queue_id=REQ()):
# type: (HttpRequest, UserProfile, str) -> HttpResponse
client = get_client_descriptor(queue_id) client = get_client_descriptor(queue_id)
if client is None: if client is None:
return json_error(_("Bad event queue id: %s") % (queue_id,)) return json_error(_("Bad event queue id: %s") % (queue_id,))
@ -40,6 +46,7 @@ def cleanup_event_queue(request, user_profile, queue_id=REQ()):
@authenticated_json_post_view @authenticated_json_post_view
def json_get_events(request, user_profile): def json_get_events(request, user_profile):
# type: (HttpRequest, UserProfile) -> Union[HttpResponse, _RespondAsynchronously]
return get_events_backend(request, user_profile, apply_markdown=True) return get_events_backend(request, user_profile, apply_markdown=True)
@asynchronous @asynchronous
@ -54,6 +61,7 @@ def get_events_backend(request, user_profile, handler,
dont_block = REQ(default=False, validator=check_bool), dont_block = REQ(default=False, validator=check_bool),
narrow = REQ(default=[], validator=check_list(None)), narrow = REQ(default=[], validator=check_list(None)),
lifespan_secs = REQ(default=0, converter=int)): lifespan_secs = REQ(default=0, converter=int)):
# type: (HttpRequest, UserProfile, Any, Optional[Client], Optional[int], Optional[List[str]], bool, bool, Optional[str], bool, List[Tuple[str, str]], int) -> Union[HttpResponse, _RespondAsynchronously]
if user_client is None: if user_client is None:
user_client = request.client user_client = request.client