Patch # 1033 by Adam Hupp:
 1) tempfile.TemporaryFile, NamedTemporaryFile, and SpooledTemporaryFile
    now pass newline and encoding to the underlying io.open call.
 2) test_tempfile is updated
 3) test_csv is updated to use the new arguments.
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 07f32e8..3e4f803 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -746,6 +746,18 @@
         f.seek(0)
         self.assertEqual(f.read(), "abc\ndef\nxyzzy\n")
 
+    def test_text_newline_and_encoding(self):
+        f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,
+                                          newline='', encoding='utf-8')
+        f.write("\u039B\r\n")
+        f.seek(0)
+        self.assertEqual(f.read(), "\u039B\r\n")
+        self.failIf(f._rolled)
+
+        f.write("\u039B" * 20 + "\r\n")
+        f.seek(0)
+        self.assertEqual(f.read(), "\u039B\r\n" + ("\u039B" * 20) + "\r\n")
+        self.failUnless(f._rolled)
 
 test_classes.append(test_SpooledTemporaryFile)
 
@@ -790,6 +802,18 @@
             self.failOnException("close")
 
     # How to test the mode and bufsize parameters?
+    def test_mode_and_encoding(self):
+
+        def roundtrip(input, *args, **kwargs):
+            with tempfile.TemporaryFile(*args, **kwargs) as fileobj:
+                fileobj.write(input)
+                fileobj.seek(0)
+                self.assertEquals(input, fileobj.read())
+
+        roundtrip(b"1234", "w+b")
+        roundtrip("abdc\n", "w+")
+        roundtrip("\u039B", "w+", encoding="utf-16")
+        roundtrip("foo\r\n", "w+", newline="")
 
 
 if tempfile.NamedTemporaryFile is not tempfile.TemporaryFile: