from tornado.httputil import url_concat
from tornado.log import gen_log
from tornado.stack_context import ExceptionStackContext
-from tornado.util import unicode_type, ArgReplacer
-
-try:
- import urlparse # py2
-except ImportError:
- import urllib.parse as urlparse # py3
-
-try:
- import urllib.parse as urllib_parse # py3
-except ImportError:
- import urllib as urllib_parse # py2
+from tornado.util import unicode_type, ArgReplacer, PY3
+
+if PY3:
+ import urllib.parse as urlparse
+ import urllib.parse as urllib_parse
+ long = int
+else:
+ import urlparse
+ import urllib as urllib_parse
try:
long # py2
from tornado.escape import native_str, parse_qs_bytes, utf8
from tornado.log import gen_log
-from tornado.util import ObjectDict
+from tornado.util import ObjectDict, PY3
-try:
- import Cookie # py2
-except ImportError:
- import http.cookies as Cookie # py3
+if PY3:
+ import http.cookies as Cookie
+ from http.client import responses
+ from urllib.parse import urlencode
+else:
+ import Cookie
+ from httplib import responses
+ from urllib import urlencode
-try:
- from httplib import responses # py2
-except ImportError:
- from http.client import responses # py3
# responses is unused in this file, but we re-export it to other files.
# Reference it so pyflakes doesn't complain.
responses
-try:
- from urllib import urlencode # py2
-except ImportError:
- from urllib.parse import urlencode # py3
-
try:
from ssl import SSLError
except ImportError:
from tornado.log import gen_log
from tornado.platform.auto import set_close_exec
from tornado import stack_context
-from tornado.util import errno_from_exception
+from tornado.util import errno_from_exception, PY3
try:
import multiprocessing
# Multiprocessing is not available on Google App Engine.
multiprocessing = None
-try:
- long # py2
-except NameError:
- long = int # py3
-
+if PY3:
+ long = int
# Re-export this exception for convenience.
try:
from tornado.log import gen_log
from tornado import stack_context
from tornado.tcpclient import TCPClient
+from tornado.util import PY3
import base64
import collections
from io import BytesIO
-try:
- import urlparse # py2
-except ImportError:
- import urllib.parse as urlparse # py3
+if PY3:
+ import urllib.parse as urlparse
+else:
+ import urlparse
try:
import ssl
import sys
from tornado.options import OptionParser, Error
-from tornado.util import basestring_type
+from tornado.util import basestring_type, PY3
from tornado.test.util import unittest
-try:
- from cStringIO import StringIO # python 2
-except ImportError:
- from io import StringIO # python 3
+if PY3:
+ from io import StringIO
+else:
+ from cStringIO import StringIO
try:
from unittest import mock # python 3.3
import threading
import warnings
+from tornado.util import PY3
+
try:
import fcntl
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue
except ImportError:
have_twisted_web = False
-try:
- import thread # py2
-except ImportError:
- import _thread as thread # py3
+if PY3:
+ import _thread as thread
+else:
+ import thread
from tornado.escape import utf8
from tornado import gen
from tornado.template import DictLoader
from tornado.testing import AsyncHTTPTestCase, AsyncTestCase, ExpectLog, gen_test
from tornado.test.util import unittest, skipBefore35, exec_test
-from tornado.util import ObjectDict, unicode_type, timedelta_to_seconds
+from tornado.util import ObjectDict, unicode_type, timedelta_to_seconds, PY3
from tornado.web import RequestHandler, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature_v1, create_signed_value, decode_signed_value, ErrorHandler, UIModule, MissingArgumentError, stream_request_body, Finish, removeslash, addslash, RedirectHandler as WebRedirectHandler, get_signature_key_version, GZipContentEncoding
import binascii
import re
import socket
-try:
+if PY3:
import urllib.parse as urllib_parse # py3
-except ImportError:
+else:
import urllib as urllib_parse # py2
wsgi_safe_tests = []
Subprocess = None
from tornado.log import gen_log, app_log
from tornado.stack_context import ExceptionStackContext
-from tornado.util import raise_exc_info, basestring_type
+from tornado.util import raise_exc_info, basestring_type, PY3
import functools
import inspect
import logging
import socket
import sys
-try:
- from cStringIO import StringIO # py2
-except ImportError:
- from io import StringIO # py3
+if PY3:
+ from io import StringIO
+else:
+ from cStringIO import StringIO
try:
from collections.abc import Generator as GeneratorType # py35+
# (either py27+ or unittest2) so tornado.test.util enforces
# this requirement, but for other users of tornado.testing we want
# to allow the older version if unitest2 is not available.
-if sys.version_info >= (3,):
+if PY3:
# On python 3, mixing unittest2 and unittest (including doctest)
# doesn't seem to work, so always use unittest.
import unittest
from tornado import template
from tornado.escape import utf8, _unicode
from tornado.util import (import_object, ObjectDict, raise_exc_info,
- unicode_type, _websocket_mask, re_unescape)
+ unicode_type, _websocket_mask, re_unescape, PY3)
from tornado.httputil import split_host_and_port
-
-try:
- import Cookie # py2
-except ImportError:
- import http.cookies as Cookie # py3
-
-try:
- import urlparse # py2
-except ImportError:
- import urllib.parse as urlparse # py3
-
-try:
- from urllib import urlencode # py2
-except ImportError:
- from urllib.parse import urlencode # py3
+if PY3:
+ import http.cookies as Cookie
+ import urllib.parse as urlparse
+ from urllib.parse import urlencode
+else:
+ import Cookie
+ import urlparse
+ from urllib import urlencode
MIN_SUPPORTED_SIGNED_VALUE_VERSION = 1
from tornado.log import gen_log, app_log
from tornado import simple_httpclient
from tornado.tcpclient import TCPClient
-from tornado.util import _websocket_mask
+from tornado.util import _websocket_mask, PY3
-try:
+if PY3:
from urllib.parse import urlparse # py2
-except ImportError:
+ xrange = range
+else:
from urlparse import urlparse # py3
-try:
- xrange # py2
-except NameError:
- xrange = range # py3
-
class WebSocketError(Exception):
pass
from tornado.log import access_log
from tornado import web
from tornado.escape import native_str
-from tornado.util import unicode_type
+from tornado.util import unicode_type, PY3
-try:
+if PY3:
import urllib.parse as urllib_parse # py3
-except ImportError:
+else:
import urllib as urllib_parse
# PEP 3333 specifies that WSGI on python 3 generally deals with byte strings