diff options
author | Guido van Rossum <guido@python.org> | 2007-08-27 17:39:33 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-08-27 17:39:33 (GMT) |
commit | 5abbf750a2b7af030ef53880f428e507bde74b62 (patch) | |
tree | 9b44c2a0e16d651f81060a0e798aab1f749871a7 /Lib/socket.py | |
parent | 6dab79535139a36d7e845c1c5f399d7a59d5d630 (diff) | |
download | cpython-5abbf750a2b7af030ef53880f428e507bde74b62.zip cpython-5abbf750a2b7af030ef53880f428e507bde74b62.tar.gz cpython-5abbf750a2b7af030ef53880f428e507bde74b62.tar.bz2 |
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).
Diffstat (limited to 'Lib/socket.py')
-rw-r--r-- | Lib/socket.py | 13 |
1 files changed, 10 insertions, 3 deletions
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 @@ class SocketIO(io.RawIOBase): # 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() |