From: Ben Darnell Date: Wed, 16 Jul 2014 04:29:27 +0000 (-0400) Subject: Read config file in binary mode instead of try/except TypeError. X-Git-Tag: v4.1.0b1~139 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=446d2e686a493aad9a857d2e4d2c69960a080064;p=thirdparty%2Ftornado.git Read config file in binary mode instead of try/except TypeError. --- diff --git a/tornado/options.py b/tornado/options.py index 12d2c8017..5e23e2910 100644 --- a/tornado/options.py +++ b/tornado/options.py @@ -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])