ssl, json, and multiprocessing are now ubiquitous.
Also misc pyflakes cleanups (unused imports)
import hashlib
import hmac
import time
-import urllib
import uuid
from tornado import httpclient
from __future__ import absolute_import, division, print_function, with_statement
import functools
-import sys
from tornado.stack_context import ExceptionStackContext
-from tornado.util import raise_exc_info
try:
from concurrent import futures
try:
from urllib.parse import parse_qs # py3
except ImportError:
- try:
- from urlparse import parse_qs # Python 2.6+
- except ImportError:
- from cgi import parse_qs
+ from urlparse import parse_qs # Python 2.6+
try:
import htmlentitydefs # py2
except ImportError:
import urllib as urllib_parse # py2
-# json module is in the standard library as of python 2.6; fall back to
-# simplejson if present for older versions.
-try:
- import json
- assert hasattr(json, "loads") and hasattr(json, "dumps")
- _json_decode = json.loads
- _json_encode = json.dumps
-except Exception:
- try:
- import simplejson
- _json_decode = lambda s: simplejson.loads(_unicode(s))
- _json_encode = lambda v: simplejson.dumps(v)
- except ImportError:
- try:
- # For Google AppEngine
- from django.utils import simplejson
- _json_decode = lambda s: simplejson.loads(_unicode(s))
- _json_encode = lambda v: simplejson.dumps(v)
- except ImportError:
- def _json_decode(s):
- raise NotImplementedError(
- "A JSON parser is required, e.g., simplejson at "
- "http://pypi.python.org/pypi/simplejson/")
- _json_encode = _json_decode
+import json
try:
unichr
# the javscript. Some json libraries do this escaping by default,
# although python's standard library does not, so we do it here.
# http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped
- return _json_encode(recursive_unicode(value)).replace("</", "<\\/")
+ return json.dumps(recursive_unicode(value)).replace("</", "<\\/")
def json_decode(value):
"""Returns Python objects for the given JSON string."""
- return _json_decode(to_basestring(value))
+ return json.loads(to_basestring(value))
def squeeze(value):
from __future__ import absolute_import, division, print_function, with_statement
import socket
+import ssl
import time
from tornado.escape import native_str, parse_qs_bytes
from tornado import stack_context
from tornado.util import bytes_type
-try:
- import ssl # Python 2.6+
-except ImportError:
- ssl = None
-
try:
import Cookie # py2
except ImportError:
from __future__ import absolute_import, division, print_function, with_statement
-import urllib
import re
from tornado.escape import native_str, parse_qs_bytes, utf8
import numbers
import os
import select
-import sys
import threading
import time
import traceback
import numbers
import os
import socket
+import ssl
import sys
import re
from tornado import stack_context
from tornado.util import bytes_type
-try:
- import ssl # Python 2.6+
-except ImportError:
- ssl = None
-
try:
from tornado.platform.posix import _set_nonblocking
except ImportError:
import errno
import os
import socket
+import ssl
import stat
from tornado import process
from tornado.log import app_log
from tornado.platform.auto import set_close_exec
-try:
- import ssl # Python 2.6+
-except ImportError:
- ssl = None
-
class TCPServer(object):
r"""A non-blocking, single-threaded TCP server.
"""EPoll-based IOLoop implementation for Linux systems."""
from __future__ import absolute_import, division, print_function, with_statement
-import os
import select
from tornado.ioloop import PollIOLoop
import functools
import datetime
-import time
from twisted.internet.posixbase import PosixReactorBase
from twisted.internet.interfaces import \
from __future__ import absolute_import, division, print_function, with_statement
import errno
-import functools
+import multiprocessing
import os
import signal
import subprocess
from tornado.log import gen_log
from tornado import stack_context
-try:
- import multiprocessing # Python 2.6+
-except ImportError:
- multiprocessing = None
-
try:
long # py2
except NameError:
import os.path
import re
import socket
+import ssl
import sys
-import time
try:
from io import BytesIO # python 3
except ImportError:
from cStringIO import StringIO as BytesIO # python 2
-try:
- import ssl # python 2.6+
-except ImportError:
- ssl = None
-
try:
import urlparse # py2
except ImportError:
import binascii
from contextlib import closing
import functools
-import re
import sys
from tornado.escape import utf8
import os
import shutil
import socket
+import ssl
import sys
import tempfile
-try:
- import ssl
-except ImportError:
- ssl = None
-
class HandlerBaseTestCase(AsyncHTTPTestCase):
def get_app(self):
})
# This actually works because both files exist
- server = HTTPServer(application, ssl_options={
+ HTTPServer(application, ssl_options={
"certfile": existing_certificate,
"keyfile": existing_certificate
})
connection reuse and closing.
"""
def get_app(self):
- test = self
-
class HelloHandler(RequestHandler):
def get(self):
self.finish('Hello world')
import os
import platform
import socket
+import ssl
import sys
-import time
-
-try:
- import ssl
-except ImportError:
- ssl = None
skipIfNoSSL = unittest.skipIf(ssl is None, "ssl module not present")
from tornado.escape import utf8, native_str, to_unicode
from tornado.template import Template, DictLoader, ParseError, Loader
-from tornado.testing import ExpectLog
from tornado.test.util import unittest
from tornado.util import u, bytes_type, ObjectDict, unicode_type
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function, with_statement
-import time
from tornado.testing import AsyncTestCase
from tornado.test.util import unittest
import signal
import socket
import sys
-import time
try:
from io import StringIO # py3
import sys
import time
import tornado
-import urllib
from tornado import escape
from tornado import httputil
from tornado.log import access_log
from tornado import web
-from tornado.escape import native_str, utf8, parse_qs_bytes
+from tornado.escape import native_str, parse_qs_bytes
from tornado.util import bytes_type, unicode_type
try: