Skip to content

Commit dd388bf

Browse files
committed
Fix options.parse_config_file on Python 3.
Add a test for this function. Closes tornadoweb#702.
1 parent e48cf35 commit dd388bf

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

MANIFEST.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
recursive-include demos *.py *.yaml *.html *.css *.js *.xml *.sql README
22
include tornado/ca-certificates.crt
33
include tornado/test/README
4-
include tornado/test/test.crt
5-
include tornado/test/test.key
64
include tornado/test/csv_translations/fr_FR.csv
75
include tornado/test/gettext_translations/fr_FR/LC_MESSAGES/tornado_test.mo
86
include tornado/test/gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po
7+
include tornado/test/options_test.cfg
98
include tornado/test/static/robots.txt
109
include tornado/test/templates/utf8.html
10+
include tornado/test/test.crt
11+
include tornado/test/test.key
1112
include runtests.sh
1213
global-exclude _auto2to3*

setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
# in the sdist tarball)
3939
"tornado.test": [
4040
"README",
41-
"test.crt",
42-
"test.key",
43-
"static/robots.txt",
44-
"templates/utf8.html",
4541
"csv_translations/fr_FR.csv",
4642
"gettext_translations/fr_FR/LC_MESSAGES/tornado_test.mo",
4743
"gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po",
44+
"options_test.cfg",
45+
"static/robots.txt",
46+
"templates/utf8.html",
47+
"test.crt",
48+
"test.key",
4849
],
4950
},
5051
author="Facebook",

tornado/options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def connect():
6969
from tornado.escape import _unicode
7070
from tornado.log import define_logging_options
7171
from tornado import stack_context
72-
from tornado.util import basestring_type
72+
from tornado.util import basestring_type, exec_in
7373

7474

7575
class Error(Exception):
@@ -211,7 +211,8 @@ def parse_config_file(self, path, final=True):
211211
from multiple sources.
212212
"""
213213
config = {}
214-
execfile(path, config, config)
214+
with open(path) as f:
215+
exec_in(f.read(), config, config)
215216
for name in config:
216217
if name in self._options:
217218
self._options[name].set(config[name])

tornado/test/options_test.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
port=443
2+
port=443

tornado/test/options_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import absolute_import, division, print_function, with_statement
22

3+
import os
34
import sys
45

56
from tornado.options import OptionParser, Error
@@ -26,6 +27,13 @@ def test_parse_command_line(self):
2627
options.parse_command_line(["main.py", "--port=443"])
2728
self.assertEqual(options.port, 443)
2829

30+
def test_parse_config_file(self):
31+
options = OptionParser()
32+
options.define("port", default=80)
33+
options.parse_config_file(os.path.join(os.path.dirname(__file__),
34+
"options_test.cfg"))
35+
self.assertEquals(options.port, 443)
36+
2937
def test_parse_callbacks(self):
3038
options = OptionParser()
3139
self.called = False

0 commit comments

Comments
 (0)