The Grande 'sendall()' patch, copied from release21-maint. Fixes #516715.

Replaces calls to socket.send() (which isn't guaranteed to send all data)
with the new socket.sendall() method.
This commit is contained in:
Martin v. Löwis 2002-02-16 23:06:19 +00:00
parent 976ade691c
commit e12454f44a
9 changed files with 15 additions and 24 deletions

View File

@ -168,7 +168,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):
@ -231,7 +231,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
@ -417,7 +417,7 @@ class FTP:
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.send(buf)
conn.sendall(buf)
conn.close()
return self.voidresp()
@ -431,7 +431,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()

View File

@ -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')

View File

@ -403,7 +403,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()

View File

@ -222,14 +222,7 @@ class IMAP4:
def send(self, data):
"""Send data to remote."""
bytes = len(data)
while bytes > 0:
sent = self.sock.send(data)
if sent == bytes:
break # avoid copy
data = data[sent:]
bytes = bytes - sent
self.sock.sendall(data)
def shutdown(self):
"""Close I/O established in "open"."""

View File

@ -179,7 +179,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())."""

View File

@ -97,7 +97,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())

View File

@ -290,9 +290,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:
self.close()
raise SMTPServerDisconnected('Server not connected')

View File

@ -185,7 +185,7 @@ class _fileobject:
def flush(self):
if self._wbuf:
self._sock.send(self._wbuf)
self._sock.sendall(self._wbuf)
self._wbuf = ""
def fileno(self):
@ -201,7 +201,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):

View File

@ -269,7 +269,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.
@ -411,7 +411,7 @@ class Telnet:
if self.option_callback:
self.option_callback(self.sock, c, opt)
else:
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',
@ -419,7 +419,7 @@ class Telnet:
if self.option_callback:
self.option_callback(self.sock, c, opt)
else:
self.sock.send(IAC + DONT + opt)
self.sock.sendall(IAC + DONT + opt)
else:
self.msg('IAC %d not recognized' % ord(opt))
except EOFError: # raised by self.rawq_getchar()