mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
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).
This commit is contained in:
parent
6dab795351
commit
5abbf750a2
3 changed files with 83 additions and 29 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue