[#8356] NamedTemporaryFile defaults to binary, but we write text here
diff --git a/Allura/allura/lib/multifactor.py b/Allura/allura/lib/multifactor.py
index e39ac28..ead22f3 100644
--- a/Allura/allura/lib/multifactor.py
+++ b/Allura/allura/lib/multifactor.py
@@ -285,7 +285,8 @@
# using a tmp file and rename is atomic, and how PAM module does it
# see `write_file_contents` in libpam/src/pam_google_authenticator.c
# 377 umask gives 400 permissions, which matches how the PAM module does it (600 would be fine too)
- with umask(0o377), tempfile.NamedTemporaryFile(dir=os.path.dirname(conf_file),
+ with umask(0o377), tempfile.NamedTemporaryFile('w',
+ dir=os.path.dirname(conf_file),
prefix='tmp-allura-gauth-',
delete=False) as f:
f.write(gaf.dump())
diff --git a/Allura/allura/tests/unit/spam/test_stopforumspam.py b/Allura/allura/tests/unit/spam/test_stopforumspam.py
index 30f5202..bfa15c9 100644
--- a/Allura/allura/tests/unit/spam/test_stopforumspam.py
+++ b/Allura/allura/tests/unit/spam/test_stopforumspam.py
@@ -37,7 +37,7 @@
self.artifact.project_id = ObjectId()
self.artifact.ref = None
- with tempfile.NamedTemporaryFile() as f:
+ with tempfile.NamedTemporaryFile('w') as f:
f.write('''"1.1.1.1","2","2018-01-22 10:56:29"
"1.2.3.4","42","2017-09-24 18:33:00"
"4.3.2.1","1","2017-09-28 14:03:53"''')
diff --git a/AlluraTest/alluratest/validation.py b/AlluraTest/alluratest/validation.py
index ed68b7f..bb8f4fc 100644
--- a/AlluraTest/alluratest/validation.py
+++ b/AlluraTest/alluratest/validation.py
@@ -90,7 +90,7 @@
def dump_to_file(prefix, contents, suffix=''):
- f = tempfile.NamedTemporaryFile(prefix=prefix, delete=False, suffix=suffix)
+ f = tempfile.NamedTemporaryFile('w', prefix=prefix, delete=False, suffix=suffix)
f.write(contents)
f.close()
return f.name
@@ -137,10 +137,10 @@
resp = requests.post('http://html5.validator.nu/nu/?out=text', # could do out=json
data=html,
headers={'Content-Type': str('text/html; charset=utf-8')},
- timeout=3)
+ timeout=5)
resp = resp.text
break
- except Exception:
+ except IOError:
resp = "Couldn't connect to validation service to check the HTML"
count -= 1
if count == 0: