Changes to io.py and socket.py by Christian Heimes.
- Replace all asserts by ValuleErrors or TypeErrors as appropriate.
- Add _checkReadable, _checkWritable methods; these check self.closed too.
- Add a test that everything exported by io.py exists, and is either
  an exception or an IOBase instance (except for the open function).
- Default buffering to 1 if isatty() (I had to tweak this to enforce
  the *default* bit -- GvR).
diff --git a/Lib/socket.py b/Lib/socket.py
index 1b3920a..bffea15 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -253,24 +253,31 @@
     # XXX More docs
 
     def __init__(self, sock, mode, closer):
-        assert mode in ("r", "w", "rw")
+        if mode not in ("r", "w", "rw"):
+            raise ValueError("invalid mode: %r" % mode)
         io.RawIOBase.__init__(self)
         self._sock = sock
         self._mode = mode
         self._closer = closer
+        self._reading = "r" in mode
+        self._writing = "w" in mode
         closer.makefile_open()
 
     def readinto(self, b):
+        self._checkClosed()
+        self._checkReadable()
         return self._sock.recv_into(b)
 
     def write(self, b):
+        self._checkClosed()
+        self._checkWritable()
         return self._sock.send(b)
 
     def readable(self):
-        return "r" in self._mode
+        return self._reading and not self.closed
 
     def writable(self):
-        return "w" in self._mode
+        return self._writing and not self.closed
 
     def fileno(self):
         return self._sock.fileno()