SF patch# 1770008 by Christian Heimes (plus some extras).
Completely get rid of StringIO.py and cStringIO.c.

I had to fix a few tests and modules beyond what Christian did, and
invent a few conventions.  E.g. in elementtree, I chose to
write/return Unicode strings whe no encoding is given, but bytes when
an explicit encoding is given.  Also mimetools was made to always
assume binary files.
diff --git a/Lib/io.py b/Lib/io.py
index 43695be..1ee465a 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -303,6 +303,8 @@
 
         Returns False if we don't know.
         """
+        if self.closed:
+            raise ValueError("isatty() on closed file")
         return False
 
     ### Readline[s] and writelines ###
@@ -1239,8 +1241,11 @@
                                        encoding=encoding,
                                        newline=newline)
         if initial_value:
+            if not isinstance(initial_value, basestring):
+                initial_value = str(initial_value)
             self.write(initial_value)
             self.seek(0)
 
     def getvalue(self):
+        self.flush()
         return self.buffer.getvalue().decode(self._encoding)