summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-15 09:32:45 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-15 09:32:45 (GMT)
commit5aa0d1056047ffbca76e8c2a1d27dcefd3716aeb (patch)
tree55d004f27a5e8121e1259c9a90c0853fb249203a /Lib
parent872b79d02f97d7560d8a0c57d3665cdbefb98f5a (diff)
downloadcpython-5aa0d1056047ffbca76e8c2a1d27dcefd3716aeb.zip
cpython-5aa0d1056047ffbca76e8c2a1d27dcefd3716aeb.tar.gz
cpython-5aa0d1056047ffbca76e8c2a1d27dcefd3716aeb.tar.bz2
Improve docs for socket.makefile() and SocketIO
Diffstat (limited to 'Lib')
-rw-r--r--Lib/socket.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 2861e0d..0d7a94c 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -54,6 +54,8 @@ except ImportError:
errno = None
EBADF = getattr(errno, 'EBADF', 9)
EINTR = getattr(errno, 'EINTR', 4)
+EAGAIN = getattr(errno, 'EAGAIN', 11)
+EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', 11)
__all__ = ["getfqdn", "create_connection"]
__all__.extend(os._get_exports_list(_socket))
@@ -249,6 +251,13 @@ class SocketIO(io.RawIOBase):
self._writing = "w" in mode
def readinto(self, b):
+ """Read up to len(b) bytes into the writable buffer *b* and return
+ the number of bytes read. If the socket is non-blocking and no bytes
+ are available, None is returned.
+
+ If *b* is non-empty, a 0 return value indicates that the connection
+ was shutdown at the other end.
+ """
self._checkClosed()
self._checkReadable()
while True:
@@ -260,17 +269,28 @@ class SocketIO(io.RawIOBase):
raise
def write(self, b):
+ """Write the given bytes or bytearray object *b* to the socket
+ and return the number of bytes written. This can be less than
+ len(b) if not all data could be written. If the socket is
+ non-blocking and no bytes could be written None is returned.
+ """
self._checkClosed()
self._checkWritable()
return self._sock.send(b)
def readable(self):
+ """True if the SocketIO is open for reading.
+ """
return self._reading and not self.closed
def writable(self):
+ """True if the SocketIO is open for writing.
+ """
return self._writing and not self.closed
def fileno(self):
+ """Return the file descriptor of the underlying socket.
+ """
self._checkClosed()
return self._sock.fileno()
@@ -283,6 +303,9 @@ class SocketIO(io.RawIOBase):
return self._mode
def close(self):
+ """Close the SocketIO object. This doesn't close the underlying
+ socket, except if all references to it have disappeared.
+ """
if self.closed:
return
io.RawIOBase.close(self)