]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Remove conditional imports for py25.
authorBen Darnell <ben@bendarnell.com>
Sat, 19 Jan 2013 18:38:48 +0000 (13:38 -0500)
committerBen Darnell <ben@bendarnell.com>
Sat, 19 Jan 2013 18:38:48 +0000 (13:38 -0500)
ssl, json, and multiprocessing are now ubiquitous.

Also misc pyflakes cleanups (unused imports)

19 files changed:
tornado/auth.py
tornado/concurrent.py
tornado/escape.py
tornado/httpserver.py
tornado/httputil.py
tornado/ioloop.py
tornado/iostream.py
tornado/netutil.py
tornado/platform/epoll.py
tornado/platform/twisted.py
tornado/process.py
tornado/simple_httpclient.py
tornado/test/httpclient_test.py
tornado/test/httpserver_test.py
tornado/test/iostream_test.py
tornado/test/template_test.py
tornado/test/testing_test.py
tornado/testing.py
tornado/wsgi.py

index 6fa65442c29bd509dc4bf5eee4ddbf5b8a3225ef..d158410a13e70fecb4d310abdc5cea63b0bde036 100644 (file)
@@ -51,7 +51,6 @@ import binascii
 import hashlib
 import hmac
 import time
-import urllib
 import uuid
 
 from tornado import httpclient
index 14786b03b8b30470956f40d026e4062f50628cfa..8af16d73e02909256edb2c71d5fa2e4c2f5ece80 100644 (file)
 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
index 6a2cbbb01d2e1552e0e6022ee438d56f3a8261a9..8b3e67b4cc7e5ba3c180d64c64916b66beaa79ee 100644 (file)
@@ -30,10 +30,7 @@ from tornado.util import bytes_type, unicode_type, basestring_type, u
 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
@@ -45,30 +42,7 @@ try:
 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
@@ -98,12 +72,12 @@ def json_encode(value):
     # 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):
index ae063fedd75c8b99b01eabcdf94031aa13c77deb..9498ea01f1d93e902fdc15af7f1ae8a8438ffb14 100644 (file)
@@ -27,6 +27,7 @@ This module also defines the `HTTPRequest` class which is exposed via
 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
@@ -37,11 +38,6 @@ from tornado.netutil import TCPServer
 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:
index e01550626b05e6df700676bbb25f9d0f78da04a3..ceed539c2ca8fd4e4dae3e12e9431e90fc23ea87 100644 (file)
@@ -18,7 +18,6 @@
 
 from __future__ import absolute_import, division, print_function, with_statement
 
-import urllib
 import re
 
 from tornado.escape import native_str, parse_qs_bytes, utf8
index 4731564cd7901c07d47a5284a7fc0f78673d658d..362f68eddf7506baa4e79780f0f87863fe622b90 100644 (file)
@@ -36,7 +36,6 @@ import logging
 import numbers
 import os
 import select
-import sys
 import threading
 import time
 import traceback
index 4aca7b11f6aaa4407a631bd56bee0c11066f2225..cf5307dd6d438093b57c9dcc49b2701a7b25f941 100644 (file)
@@ -31,6 +31,7 @@ import errno
 import numbers
 import os
 import socket
+import ssl
 import sys
 import re
 
@@ -39,11 +40,6 @@ from tornado.log import gen_log, app_log
 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:
index ed768cc9604d6b569e894cd31ce094eb7282f7f0..f54c960da0c88db5e40261d984995c44e4dcb645 100644 (file)
@@ -21,6 +21,7 @@ from __future__ import absolute_import, division, print_function, with_statement
 import errno
 import os
 import socket
+import ssl
 import stat
 
 from tornado import process
@@ -30,11 +31,6 @@ from tornado.iostream import IOStream, SSLIOStream
 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.
index 2b20a41bde67f3d1bf23f82e5c74e7934026a880..790b2869223d321a5767cbe2e3e53da754f5be11 100644 (file)
@@ -16,7 +16,6 @@
 """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
index 07db8085c901cddbb834a6082c8b5303ca7d24c2..c61019ac7efcdaf058adc34d782e4b78e4ef3862 100644 (file)
@@ -68,7 +68,6 @@ from __future__ import absolute_import, division, print_function, with_statement
 
 import functools
 import datetime
-import time
 
 from twisted.internet.posixbase import PosixReactorBase
 from twisted.internet.interfaces import \
index 90294b4c3b0a62e9ed9ab152741133a61600ea7d..96c174ec3b232ca825a51d0cc21ae1441465dcf8 100644 (file)
@@ -19,7 +19,7 @@
 from __future__ import absolute_import, division, print_function, with_statement
 
 import errno
-import functools
+import multiprocessing
 import os
 import signal
 import subprocess
@@ -33,11 +33,6 @@ from tornado.iostream import PipeIOStream
 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:
index 5b3c9028762e0f395223403caab5877562736a18..24df4c39671a77faa0f1a3e115caa6f0c6d4d700 100644 (file)
@@ -17,19 +17,14 @@ import functools
 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:
index d4e0579a765aa014da2344c0be3a1dd34a7ea53b..02509fbca5efe8aee996519d3406b2921f6f9baa 100644 (file)
@@ -6,7 +6,6 @@ import base64
 import binascii
 from contextlib import closing
 import functools
-import re
 import sys
 
 from tornado.escape import utf8
index b16e4c6a8a8f9102c2cbbd9b661e59ca7253765b..b8fb87621dd9e693f1d1287102ef1bc35cc40106 100644 (file)
@@ -17,14 +17,10 @@ import datetime
 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):
@@ -142,7 +138,7 @@ class BadSSLOptionsTest(unittest.TestCase):
         })
 
         # This actually works because both files exist
-        server = HTTPServer(application, ssl_options={
+        HTTPServer(application, ssl_options={
            "certfile": existing_certificate,
            "keyfile": existing_certificate
         })
@@ -431,8 +427,6 @@ class KeepAliveTest(AsyncHTTPTestCase):
     connection reuse and closing.
     """
     def get_app(self):
-        test = self
-
         class HelloHandler(RequestHandler):
             def get(self):
                 self.finish('Hello world')
index da0930349c332abb5481ed3549a04bfa655c318a..a76e602191a1cb4d09ee901960b6d1181b308fc0 100644 (file)
@@ -12,13 +12,8 @@ import logging
 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")
 
index a69004c324379ccff2dc1555a383274c9c03f962..e39025663f0dd05ee13c2d6baee24bbbe4e14825 100644 (file)
@@ -5,7 +5,6 @@ import traceback
 
 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
 
index 428b8a1011db1f18ce5b2176da7cd38922a61a41..75f07093a8ac57811db3bd49365ab6698cc16be3 100644 (file)
@@ -1,7 +1,6 @@
 #!/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
 
index 0e3db883ac990b3e948e349aea16fa6884ee93e7..cc31e8c8f1b692754977cf96574d6170df02df88 100644 (file)
@@ -43,7 +43,6 @@ import re
 import signal
 import socket
 import sys
-import time
 
 try:
     from io import StringIO  # py3
index 5cfcedc3c9303b518c921b7f7396281154c9073c..6c3d6a8b8a8e4b25302098f00d39f2996dc60f20 100644 (file)
@@ -34,13 +34,12 @@ from __future__ import absolute_import, division, print_function, with_statement
 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: