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
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])