diff --git a/zerver/tornado/application.py b/zerver/tornado/application.py index 95c44ee77a..2917976b53 100644 --- a/zerver/tornado/application.py +++ b/zerver/tornado/application.py @@ -1,14 +1,13 @@ import atexit -from django.conf import settings - -from zerver.tornado.handlers import AsyncDjangoHandler -from zerver.tornado.socket import get_sockjs_router -from zerver.lib.queue import get_queue_client - import tornado.autoreload import tornado.web +from django.conf import settings + +from zerver.lib.queue import get_queue_client +from zerver.tornado.handlers import AsyncDjangoHandler +from zerver.tornado.socket import get_sockjs_router def setup_tornado_rabbitmq() -> None: # When tornado is shut down, disconnect cleanly from rabbitmq diff --git a/zerver/tornado/exceptions.py b/zerver/tornado/exceptions.py index d69c3732f3..11a60c090f 100644 --- a/zerver/tornado/exceptions.py +++ b/zerver/tornado/exceptions.py @@ -2,7 +2,7 @@ from typing import Text from django.utils.translation import ugettext as _ -from zerver.lib.exceptions import JsonableError, ErrorCode +from zerver.lib.exceptions import ErrorCode, JsonableError class BadEventQueueIdError(JsonableError): code = ErrorCode.BAD_EVENT_QUEUE_ID diff --git a/zerver/tornado/handlers.py b/zerver/tornado/handlers.py index cd2736f42e..ce1c684d94 100644 --- a/zerver/tornado/handlers.py +++ b/zerver/tornado/handlers.py @@ -1,29 +1,28 @@ -import sys -import tornado.web import logging +import sys +import urllib +from threading import Lock +from typing import Any, Callable, Dict, List, Optional + +import tornado.web from django import http from django.conf import settings -from django.core.handlers.wsgi import WSGIRequest, get_script_name +from django.core import exceptions, signals, urlresolvers +from django.core.exceptions import MiddlewareNotUsed from django.core.handlers import base from django.core.handlers.exception import convert_exception_to_response +from django.core.handlers.wsgi import WSGIRequest, get_script_name from django.core.urlresolvers import set_script_prefix -from django.core import signals -from django.core import exceptions, urlresolvers -from django.core.exceptions import MiddlewareNotUsed from django.http import HttpRequest, HttpResponse from django.utils.module_loading import import_string -from threading import Lock from tornado.wsgi import WSGIContainer -import urllib from zerver.decorator import RespondAsynchronously from zerver.lib.response import json_response -from zerver.middleware import async_request_stop, async_request_restart +from zerver.middleware import async_request_restart, async_request_stop from zerver.tornado.descriptors import get_descriptor_by_handler_id -from typing import Any, Callable, Dict, List, Optional - current_handler_id = 0 handlers = {} # type: Dict[int, 'AsyncDjangoHandler'] diff --git a/zerver/tornado/ioloop_logging.py b/zerver/tornado/ioloop_logging.py index 63d30b73c2..52d01e8e7d 100644 --- a/zerver/tornado/ioloop_logging.py +++ b/zerver/tornado/ioloop_logging.py @@ -1,11 +1,11 @@ +import logging +import select +import time from typing import Any, List, Tuple -import logging -import time -import select from django.conf import settings - from tornado.ioloop import IOLoop, PollIOLoop + # There isn't a good way to get at what the underlying poll implementation # will be without actually constructing an IOLoop, so we just assume it will # be epoll. diff --git a/zerver/tornado/views.py b/zerver/tornado/views.py index e36f59d6db..1e4255e550 100644 --- a/zerver/tornado/views.py +++ b/zerver/tornado/views.py @@ -1,23 +1,21 @@ -from django.utils.translation import ugettext as _ -from django.http import HttpRequest, HttpResponse - -from zerver.models import get_client, UserProfile, Client - -from zerver.decorator import asynchronous, \ - internal_notify_view, RespondAsynchronously, \ - has_request_variables, REQ, _RespondAsynchronously - -from zerver.lib.response import json_success, json_error -from zerver.lib.validator import check_bool, check_list, check_string -from zerver.tornado.event_queue import get_client_descriptor, \ - process_notification, fetch_events -from zerver.tornado.exceptions import BadEventQueueIdError -from django.core.handlers.base import BaseHandler - -from typing import Union, Optional, Iterable, Sequence, List, Text import time +from typing import Iterable, List, Optional, Sequence, Text, Union + import ujson +from django.core.handlers.base import BaseHandler +from django.http import HttpRequest, HttpResponse +from django.utils.translation import ugettext as _ + +from zerver.decorator import REQ, RespondAsynchronously, \ + _RespondAsynchronously, asynchronous, \ + has_request_variables, internal_notify_view +from zerver.lib.response import json_error, json_success +from zerver.lib.validator import check_bool, check_list, check_string +from zerver.models import Client, UserProfile, get_client +from zerver.tornado.event_queue import fetch_events, \ + get_client_descriptor, process_notification +from zerver.tornado.exceptions import BadEventQueueIdError @internal_notify_view(True) def notify(request: HttpRequest) -> HttpResponse: