summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-03-10 18:45:14 +0100
committerGeorg Brandl <georg@python.org>2012-03-10 18:45:14 +0100
commitb08df4970be64fce06b9d69a219bdca522ed37e3 (patch)
treebd8aab9db34725948e28568ebe641f2edc130535
parentba6614741b77974ab457455ee173c77d2c0fe6f4 (diff)
downloadsphinx-b08df4970be64fce06b9d69a219bdca522ed37e3.tar.gz
Fixes #875 and #876: use the right file mode to successfully read config files under 2.x and 3.x.
-rw-r--r--sphinx/config.py5
-rw-r--r--tests/test_quickstart.py4
2 files changed, 5 insertions, 4 deletions
diff --git a/sphinx/config.py b/sphinx/config.py
index 4bcf1b2c..f119ab00 100644
--- a/sphinx/config.py
+++ b/sphinx/config.py
@@ -194,8 +194,9 @@ class Config(object):
# we promise to have the config dir as current dir while the
# config file is executed
os.chdir(dirname)
- # get config source
- f = open(config_file, 'rU')
+ # get config source -- 'b' is a no-op under 2.x, while 'U' is
+ # ignored under 3.x (but 3.x compile() accepts \r\n newlines)
+ f = open(config_file, 'rbU')
try:
source = f.read()
finally:
diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py
index 26064117..dba888dd 100644
--- a/tests/test_quickstart.py
+++ b/tests/test_quickstart.py
@@ -91,7 +91,7 @@ def test_quickstart_defaults(tempdir):
conffile = tempdir / 'conf.py'
assert conffile.isfile()
ns = {}
- f = open(conffile, 'U')
+ f = open(conffile, 'rbU')
try:
code = compile(f.read(), conffile, 'exec')
finally:
@@ -151,7 +151,7 @@ def test_quickstart_all_answers(tempdir):
conffile = tempdir / 'source' / 'conf.py'
assert conffile.isfile()
ns = {}
- f = open(conffile, 'U')
+ f = open(conffile, 'rbU')
try:
code = compile(f.read(), conffile, 'exec')
finally: