import codecs
import csv
import datetime
-from io import BytesIO
import numbers
import os
import re
from tornado import escape
from tornado.log import gen_log
-from tornado.util import PY3
from tornado._locale_data import LOCALE_NAMES
# in most cases but is common with CSV files because Excel
# cannot read utf-8 files without a BOM.
encoding = 'utf-8-sig'
- if PY3:
- # python 3: csv.reader requires a file open in text mode.
- # Force utf8 to avoid dependence on $LANG environment variable.
- f = open(full_path, "r", encoding=encoding)
- else:
- # python 2: csv can only handle byte strings (in ascii-compatible
- # encodings), which we decode below. Transcode everything into
- # utf8 before passing it to csv.reader.
- f = BytesIO()
- with codecs.open(full_path, "r", encoding=encoding) as infile:
- f.write(escape.utf8(infile.read()))
- f.seek(0)
+ # python 3: csv.reader requires a file open in text mode.
+ # Specify an encoding to avoid dependence on $LANG environment variable.
+ f = open(full_path, "r", encoding=encoding)
_translations[locale] = {}
for i, row in enumerate(csv.reader(f)):
if not row or len(row) < 2:
import os
import sys
import socket
+import ssl
import stat
from tornado.concurrent import dummy_executor, run_on_executor
from tornado import gen
from tornado.ioloop import IOLoop
from tornado.platform.auto import set_close_exec
-from tornado.util import PY3, Configurable, errno_from_exception
-
-try:
- import ssl
-except ImportError:
- # ssl is not available on Google App Engine
- ssl = None
-
-if PY3:
- xrange = range
-
-if ssl is not None:
- # Note that the naming of ssl.Purpose is confusing; the purpose
- # of a context is to authentiate the opposite side of the connection.
- _client_ssl_defaults = ssl.create_default_context(
- ssl.Purpose.SERVER_AUTH)
- _server_ssl_defaults = ssl.create_default_context(
- ssl.Purpose.CLIENT_AUTH)
- if hasattr(ssl, 'OP_NO_COMPRESSION'):
- # See netutil.ssl_options_to_context
- _client_ssl_defaults.options |= ssl.OP_NO_COMPRESSION
- _server_ssl_defaults.options |= ssl.OP_NO_COMPRESSION
-else:
- # Google App Engine
- _client_ssl_defaults = dict(cert_reqs=None,
- ca_certs=None)
- _server_ssl_defaults = {}
+from tornado.util import Configurable, errno_from_exception
+
+# Note that the naming of ssl.Purpose is confusing; the purpose
+# of a context is to authentiate the opposite side of the connection.
+_client_ssl_defaults = ssl.create_default_context(
+ ssl.Purpose.SERVER_AUTH)
+_server_ssl_defaults = ssl.create_default_context(
+ ssl.Purpose.CLIENT_AUTH)
+if hasattr(ssl, 'OP_NO_COMPRESSION'):
+ # See netutil.ssl_options_to_context
+ _client_ssl_defaults.options |= ssl.OP_NO_COMPRESSION
+ _server_ssl_defaults.options |= ssl.OP_NO_COMPRESSION
# ThreadedResolver runs getaddrinfo on a thread. If the hostname is unicode,
# getaddrinfo attempts to import encodings.idna. If this is done at
# Instead, we use the (default) listen backlog as a rough
# heuristic for the number of connections we can reasonably
# accept at once.
- for i in xrange(_DEFAULT_BACKLOG):
+ for i in range(_DEFAULT_BACKLOG):
if removed[0]:
# The socket was probably closed
return
def configurable_default(cls):
return DefaultExecutorResolver
- def resolve(self, host, port, family=socket.AF_UNSPEC, callback=None):
+ def resolve(self, host, port, family=socket.AF_UNSPEC):
"""Resolves an address.
The ``host`` argument is a string which may be a hostname or a
.. versionchanged:: 4.4
Standardized all implementations to raise `IOError`.
- .. deprecated:: 5.1
- The ``callback`` argument is deprecated and will be removed in 6.0.
+ .. versionchanged:: 6.0 The ``callback`` argument was removed.
Use the returned awaitable object instead.
+
"""
raise NotImplementedError()
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, PY3
+from tornado.util import errno_from_exception
try:
import multiprocessing
# Multiprocessing is not available on Google App Engine.
multiprocessing = None
-if PY3:
- long = int
-
# Re-export this exception for convenience.
-try:
- CalledProcessError = subprocess.CalledProcessError
-except AttributeError:
- # The subprocess module exists in Google App Engine, but is empty.
- # This module isn't very useful in that case, but it should
- # at least be importable.
- if 'APPENGINE_RUNTIME' not in os.environ:
- raise
+CalledProcessError = subprocess.CalledProcessError
def cpu_count():
# random.seed (at least as of python 2.6). If os.urandom is not
# available, we mix in the pid in addition to a timestamp.
try:
- seed = long(hexlify(os.urandom(16)), 16)
+ seed = int(hexlify(os.urandom(16)), 16)
except NotImplementedError:
seed = int(time.time() * 1000) ^ os.getpid()
random.seed(seed)