]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Read config file in binary mode instead of try/except TypeError.
authorBen Darnell <ben@bendarnell.com>
Wed, 16 Jul 2014 04:29:27 +0000 (00:29 -0400)
committerBen Darnell <ben@bendarnell.com>
Wed, 16 Jul 2014 04:29:27 +0000 (00:29 -0400)
tornado/options.py

index 12d2c8017dcbcdf817e7e4eda375b90bbf53ab76..5e23e2910408c8d0483dec4d52fde503a96388a2 100644 (file)
@@ -79,7 +79,7 @@ import sys
 import os
 import textwrap
 
-from tornado.escape import _unicode
+from tornado.escape import _unicode, native_str
 from tornado.log import define_logging_options
 from tornado import stack_context
 from tornado.util import basestring_type, exec_in
@@ -271,16 +271,14 @@ class OptionParser(object):
         If ``final`` is ``False``, parse callbacks will not be run.
         This is useful for applications that wish to combine configurations
         from multiple sources.
+
+        .. versionchanged:: 4.1
+           Config files are now always interpreted as utf-8 instead of
+           the system default encoding.
         """
         config = {}
-        try:
-            # python 3
-            with open(path, encoding="utf-8") as f:
-                exec_in(f.read(), config, config)
-        except TypeError:
-            # python 2
-            with open(path) as f:
-                exec_in(f.read(), config, config)
+        with open(path, 'rb') as f:
+            exec_in(native_str(f.read()), config, config)
         for name in config:
             if name in self._options:
                 self._options[name].set(config[name])