From: Anthony Baxter Date: Sun, 23 Dec 2001 01:47:10 +0000 (+0000) Subject: The Grande 'sendall()' patch. I believe that I've picked up everything X-Git-Tag: v2.1.2c1~28 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cdf6bfe3ec94d37a11ba68265c441339149aa874;p=thirdparty%2FPython%2Fcpython.git The Grande 'sendall()' patch. I believe that I've picked up everything in the std lib that should be using sendall(), rather than send() - I've tried to check each of the patches. Replaces calls to socket.send() (which isn't guaranteed to send all data) with the new socket.sendall() method. --- diff --git a/Lib/ftplib.py b/Lib/ftplib.py index c08ad45cb563..f2e90dc2c57d 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -155,7 +155,7 @@ class FTP: def putline(self, line): line = line + CRLF if self.debugging > 1: print '*put*', self.sanitize(line) - self.sock.send(line) + self.sock.sendall(line) # Internal: send one command to the server (through putline()) def putcmd(self, line): @@ -218,7 +218,7 @@ class FTP: tried. Instead, just send the ABOR command as OOB data.''' line = 'ABOR' + CRLF if self.debugging > 1: print '*put urgent*', self.sanitize(line) - self.sock.send(line, MSG_OOB) + self.sock.sendall(line, MSG_OOB) resp = self.getmultiline() if resp[:3] not in ('426', '226'): raise error_proto, resp @@ -372,7 +372,7 @@ class FTP: while 1: buf = fp.read(blocksize) if not buf: break - conn.send(buf) + conn.sendall(buf) conn.close() return self.voidresp() @@ -386,7 +386,7 @@ class FTP: if buf[-2:] != CRLF: if buf[-1] in CRLF: buf = buf[:-1] buf = buf + CRLF - conn.send(buf) + conn.sendall(buf) conn.close() return self.voidresp() diff --git a/Lib/gopherlib.py b/Lib/gopherlib.py index f5bbca52b741..7d188982f7ce 100644 --- a/Lib/gopherlib.py +++ b/Lib/gopherlib.py @@ -66,7 +66,7 @@ def send_selector(selector, host, port = 0): port = int(port) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) - s.send(selector + CRLF) + s.sendall(selector + CRLF) s.shutdown(1) return s.makefile('rb') diff --git a/Lib/httplib.py b/Lib/httplib.py index 1e08539e2fec..0ca65db324d8 100644 --- a/Lib/httplib.py +++ b/Lib/httplib.py @@ -388,7 +388,7 @@ class HTTPConnection: if self.debuglevel > 0: print "send:", repr(str) try: - self.sock.send(str) + self.sock.sendall(str) except socket.error, v: if v[0] == 32: # Broken pipe self.close() diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 26faa9eba10d..7186114b7c58 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -633,7 +633,7 @@ class IMAP4: _log('> %s' % data) try: - self.sock.send('%s%s' % (data, CRLF)) + self.sock.sendall('%s%s' % (data, CRLF)) except socket.error, val: raise self.abort('socket error: %s' % val) @@ -657,8 +657,8 @@ class IMAP4: _mesg('write literal size %s' % len(literal)) try: - self.sock.send(literal) - self.sock.send(CRLF) + self.sock.sendall(literal) + self.sock.sendall(CRLF) except socket.error, val: raise self.abort('socket error: %s' % val) diff --git a/Lib/nntplib.py b/Lib/nntplib.py index d97813fed4b1..a2344f619f45 100644 --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -178,7 +178,7 @@ class NNTP: """Internal: send one line to the server, appending CRLF.""" line = line + CRLF if self.debugging > 1: print '*put*', `line` - self.sock.send(line) + self.sock.sendall(line) def putcmd(self, line): """Internal: send one command to the server (through putline()).""" diff --git a/Lib/poplib.py b/Lib/poplib.py index fb24a0f9c5b8..da20f6667fe4 100644 --- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -84,7 +84,7 @@ class POP3: def _putline(self, line): #if self._debugging > 1: print '*put*', `line` - self.sock.send('%s%s' % (line, CRLF)) + self.sock.sendall('%s%s' % (line, CRLF)) # Internal: send one command to the server (through _putline()) diff --git a/Lib/smtplib.py b/Lib/smtplib.py index f1e4a27ff3bf..d01641662f2d 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -232,9 +232,7 @@ class SMTP: if self.debuglevel > 0: print 'send:', `str` if self.sock: try: - sendptr = 0 - while sendptr < len(str): - sendptr = sendptr + self.sock.send(str[sendptr:]) + self.sock.sendall(str) except socket.error: raise SMTPServerDisconnected('Server not connected') else: diff --git a/Lib/socket.py b/Lib/socket.py index 54b4b8710f47..7cb24e808386 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -176,7 +176,7 @@ class _fileobject: def flush(self): if self._wbuf: - self._sock.send(self._wbuf) + self._sock.sendall(self._wbuf) self._wbuf = "" def fileno(self): @@ -192,7 +192,7 @@ class _fileobject: self.flush() def writelines(self, list): - filter(self._sock.send, list) + filter(self._sock.sendall, list) self.flush() def read(self, n=-1): diff --git a/Lib/telnetlib.py b/Lib/telnetlib.py index 6b249e8db416..70026f049008 100644 --- a/Lib/telnetlib.py +++ b/Lib/telnetlib.py @@ -190,7 +190,7 @@ class Telnet: if IAC in buffer: buffer = buffer.replace(IAC, IAC+IAC) self.msg("send %s", `buffer`) - self.sock.send(buffer) + self.sock.sendall(buffer) def read_until(self, match, timeout=None): """Read until a given string is encountered or until timeout. @@ -325,12 +325,12 @@ class Telnet: elif c in (DO, DONT): opt = self.rawq_getchar() self.msg('IAC %s %d', c == DO and 'DO' or 'DONT', ord(c)) - self.sock.send(IAC + WONT + opt) + self.sock.sendall(IAC + WONT + opt) elif c in (WILL, WONT): opt = self.rawq_getchar() self.msg('IAC %s %d', c == WILL and 'WILL' or 'WONT', ord(c)) - self.sock.send(IAC + DONT + opt) + self.sock.sendall(IAC + DONT + opt) else: self.msg('IAC %s not recognized' % `c`) except EOFError: # raised by self.rawq_getchar()