mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
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:
parent
976ade691c
commit
e12454f44a
9 changed files with 15 additions and 24 deletions
|
@ -168,7 +168,7 @@ class FTP:
|
||||||
def putline(self, line):
|
def putline(self, line):
|
||||||
line = line + CRLF
|
line = line + CRLF
|
||||||
if self.debugging > 1: print '*put*', self.sanitize(line)
|
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())
|
# Internal: send one command to the server (through putline())
|
||||||
def putcmd(self, line):
|
def putcmd(self, line):
|
||||||
|
@ -231,7 +231,7 @@ class FTP:
|
||||||
tried. Instead, just send the ABOR command as OOB data.'''
|
tried. Instead, just send the ABOR command as OOB data.'''
|
||||||
line = 'ABOR' + CRLF
|
line = 'ABOR' + CRLF
|
||||||
if self.debugging > 1: print '*put urgent*', self.sanitize(line)
|
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()
|
resp = self.getmultiline()
|
||||||
if resp[:3] not in ('426', '226'):
|
if resp[:3] not in ('426', '226'):
|
||||||
raise error_proto, resp
|
raise error_proto, resp
|
||||||
|
@ -417,7 +417,7 @@ class FTP:
|
||||||
while 1:
|
while 1:
|
||||||
buf = fp.read(blocksize)
|
buf = fp.read(blocksize)
|
||||||
if not buf: break
|
if not buf: break
|
||||||
conn.send(buf)
|
conn.sendall(buf)
|
||||||
conn.close()
|
conn.close()
|
||||||
return self.voidresp()
|
return self.voidresp()
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ class FTP:
|
||||||
if buf[-2:] != CRLF:
|
if buf[-2:] != CRLF:
|
||||||
if buf[-1] in CRLF: buf = buf[:-1]
|
if buf[-1] in CRLF: buf = buf[:-1]
|
||||||
buf = buf + CRLF
|
buf = buf + CRLF
|
||||||
conn.send(buf)
|
conn.sendall(buf)
|
||||||
conn.close()
|
conn.close()
|
||||||
return self.voidresp()
|
return self.voidresp()
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ def send_selector(selector, host, port = 0):
|
||||||
port = int(port)
|
port = int(port)
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.connect((host, port))
|
s.connect((host, port))
|
||||||
s.send(selector + CRLF)
|
s.sendall(selector + CRLF)
|
||||||
s.shutdown(1)
|
s.shutdown(1)
|
||||||
return s.makefile('rb')
|
return s.makefile('rb')
|
||||||
|
|
||||||
|
|
|
@ -403,7 +403,7 @@ class HTTPConnection:
|
||||||
if self.debuglevel > 0:
|
if self.debuglevel > 0:
|
||||||
print "send:", repr(str)
|
print "send:", repr(str)
|
||||||
try:
|
try:
|
||||||
self.sock.send(str)
|
self.sock.sendall(str)
|
||||||
except socket.error, v:
|
except socket.error, v:
|
||||||
if v[0] == 32: # Broken pipe
|
if v[0] == 32: # Broken pipe
|
||||||
self.close()
|
self.close()
|
||||||
|
|
|
@ -222,14 +222,7 @@ class IMAP4:
|
||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
"""Send data to remote."""
|
"""Send data to remote."""
|
||||||
bytes = len(data)
|
self.sock.sendall(data)
|
||||||
while bytes > 0:
|
|
||||||
sent = self.sock.send(data)
|
|
||||||
if sent == bytes:
|
|
||||||
break # avoid copy
|
|
||||||
data = data[sent:]
|
|
||||||
bytes = bytes - sent
|
|
||||||
|
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
"""Close I/O established in "open"."""
|
"""Close I/O established in "open"."""
|
||||||
|
|
|
@ -179,7 +179,7 @@ class NNTP:
|
||||||
"""Internal: send one line to the server, appending CRLF."""
|
"""Internal: send one line to the server, appending CRLF."""
|
||||||
line = line + CRLF
|
line = line + CRLF
|
||||||
if self.debugging > 1: print '*put*', `line`
|
if self.debugging > 1: print '*put*', `line`
|
||||||
self.sock.send(line)
|
self.sock.sendall(line)
|
||||||
|
|
||||||
def putcmd(self, line):
|
def putcmd(self, line):
|
||||||
"""Internal: send one command to the server (through putline())."""
|
"""Internal: send one command to the server (through putline())."""
|
||||||
|
|
|
@ -97,7 +97,7 @@ class POP3:
|
||||||
|
|
||||||
def _putline(self, line):
|
def _putline(self, line):
|
||||||
if self._debugging > 1: print '*put*', `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())
|
# Internal: send one command to the server (through _putline())
|
||||||
|
|
|
@ -290,9 +290,7 @@ class SMTP:
|
||||||
if self.debuglevel > 0: print 'send:', `str`
|
if self.debuglevel > 0: print 'send:', `str`
|
||||||
if self.sock:
|
if self.sock:
|
||||||
try:
|
try:
|
||||||
sendptr = 0
|
self.sock.sendall(str)
|
||||||
while sendptr < len(str):
|
|
||||||
sendptr = sendptr + self.sock.send(str[sendptr:])
|
|
||||||
except socket.error:
|
except socket.error:
|
||||||
self.close()
|
self.close()
|
||||||
raise SMTPServerDisconnected('Server not connected')
|
raise SMTPServerDisconnected('Server not connected')
|
||||||
|
|
|
@ -185,7 +185,7 @@ class _fileobject:
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
if self._wbuf:
|
if self._wbuf:
|
||||||
self._sock.send(self._wbuf)
|
self._sock.sendall(self._wbuf)
|
||||||
self._wbuf = ""
|
self._wbuf = ""
|
||||||
|
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
|
@ -201,7 +201,7 @@ class _fileobject:
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def writelines(self, list):
|
def writelines(self, list):
|
||||||
filter(self._sock.send, list)
|
filter(self._sock.sendall, list)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
def read(self, n=-1):
|
def read(self, n=-1):
|
||||||
|
|
|
@ -269,7 +269,7 @@ class Telnet:
|
||||||
if IAC in buffer:
|
if IAC in buffer:
|
||||||
buffer = buffer.replace(IAC, IAC+IAC)
|
buffer = buffer.replace(IAC, IAC+IAC)
|
||||||
self.msg("send %s", `buffer`)
|
self.msg("send %s", `buffer`)
|
||||||
self.sock.send(buffer)
|
self.sock.sendall(buffer)
|
||||||
|
|
||||||
def read_until(self, match, timeout=None):
|
def read_until(self, match, timeout=None):
|
||||||
"""Read until a given string is encountered or until timeout.
|
"""Read until a given string is encountered or until timeout.
|
||||||
|
@ -411,7 +411,7 @@ class Telnet:
|
||||||
if self.option_callback:
|
if self.option_callback:
|
||||||
self.option_callback(self.sock, c, opt)
|
self.option_callback(self.sock, c, opt)
|
||||||
else:
|
else:
|
||||||
self.sock.send(IAC + WONT + opt)
|
self.sock.sendall(IAC + WONT + opt)
|
||||||
elif c in (WILL, WONT):
|
elif c in (WILL, WONT):
|
||||||
opt = self.rawq_getchar()
|
opt = self.rawq_getchar()
|
||||||
self.msg('IAC %s %d',
|
self.msg('IAC %s %d',
|
||||||
|
@ -419,7 +419,7 @@ class Telnet:
|
||||||
if self.option_callback:
|
if self.option_callback:
|
||||||
self.option_callback(self.sock, c, opt)
|
self.option_callback(self.sock, c, opt)
|
||||||
else:
|
else:
|
||||||
self.sock.send(IAC + DONT + opt)
|
self.sock.sendall(IAC + DONT + opt)
|
||||||
else:
|
else:
|
||||||
self.msg('IAC %d not recognized' % ord(opt))
|
self.msg('IAC %d not recognized' % ord(opt))
|
||||||
except EOFError: # raised by self.rawq_getchar()
|
except EOFError: # raised by self.rawq_getchar()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue