]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
locale,netutil,process: Minor deprecation/py3 updates
authorBen Darnell <ben@bendarnell.com>
Sat, 7 Jul 2018 04:19:38 +0000 (00:19 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 14 Jul 2018 20:58:48 +0000 (16:58 -0400)
tornado/locale.py
tornado/netutil.py
tornado/process.py

index d45172f3b879ebb0b2e9ed3bf8d09b74f3a2c98a..2931010cedf775995bab478b17839fad24b73a0d 100644 (file)
@@ -44,14 +44,12 @@ from __future__ import absolute_import, division, print_function
 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
 
@@ -148,18 +146,9 @@ def load_translations(directory, encoding=None):
                 # 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:
index e63683ad7e27bea885d82f0e40fbc1decd188faa..c7682be3a8035318b3155619d89401f7b5df557a 100644 (file)
@@ -21,39 +21,25 @@ import errno
 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
@@ -241,7 +227,7 @@ def add_accept_handler(sock, callback):
         # 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
@@ -321,7 +307,7 @@ class Resolver(Configurable):
     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
@@ -339,9 +325,9 @@ class Resolver(Configurable):
         .. 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()
 
index 122fd7e14b47bf478ee8a93570f76c16c6e9f370..34dd2e0848c7e02bdfd7f9ed8fd09e43e4164015 100644 (file)
@@ -34,7 +34,7 @@ from tornado.iostream import PipeIOStream
 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
@@ -42,18 +42,8 @@ except ImportError:
     # 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():
@@ -80,7 +70,7 @@ def _reseed_random():
     # 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)