Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e12454f

Browse files
committed
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.
1 parent 976ade6 commit e12454f

9 files changed

Lines changed: 15 additions & 24 deletions

File tree

Lib/ftplib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def sanitize(self, s):
168168
def putline(self, line):
169169
line = line + CRLF
170170
if self.debugging > 1: print '*put*', self.sanitize(line)
171-
self.sock.send(line)
171+
self.sock.sendall(line)
172172

173173
# Internal: send one command to the server (through putline())
174174
def putcmd(self, line):
@@ -231,7 +231,7 @@ def abort(self):
231231
tried. Instead, just send the ABOR command as OOB data.'''
232232
line = 'ABOR' + CRLF
233233
if self.debugging > 1: print '*put urgent*', self.sanitize(line)
234-
self.sock.send(line, MSG_OOB)
234+
self.sock.sendall(line, MSG_OOB)
235235
resp = self.getmultiline()
236236
if resp[:3] not in ('426', '226'):
237237
raise error_proto, resp
@@ -417,7 +417,7 @@ def storbinary(self, cmd, fp, blocksize=8192):
417417
while 1:
418418
buf = fp.read(blocksize)
419419
if not buf: break
420-
conn.send(buf)
420+
conn.sendall(buf)
421421
conn.close()
422422
return self.voidresp()
423423

@@ -431,7 +431,7 @@ def storlines(self, cmd, fp):
431431
if buf[-2:] != CRLF:
432432
if buf[-1] in CRLF: buf = buf[:-1]
433433
buf = buf + CRLF
434-
conn.send(buf)
434+
conn.sendall(buf)
435435
conn.close()
436436
return self.voidresp()
437437

Lib/gopherlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def send_selector(selector, host, port = 0):
6666
port = int(port)
6767
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6868
s.connect((host, port))
69-
s.send(selector + CRLF)
69+
s.sendall(selector + CRLF)
7070
s.shutdown(1)
7171
return s.makefile('rb')
7272

Lib/httplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def send(self, str):
403403
if self.debuglevel > 0:
404404
print "send:", repr(str)
405405
try:
406-
self.sock.send(str)
406+
self.sock.sendall(str)
407407
except socket.error, v:
408408
if v[0] == 32: # Broken pipe
409409
self.close()

Lib/imaplib.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,7 @@ def readline(self):
222222

223223
def send(self, data):
224224
"""Send data to remote."""
225-
bytes = len(data)
226-
while bytes > 0:
227-
sent = self.sock.send(data)
228-
if sent == bytes:
229-
break # avoid copy
230-
data = data[sent:]
231-
bytes = bytes - sent
232-
225+
self.sock.sendall(data)
233226

234227
def shutdown(self):
235228
"""Close I/O established in "open"."""

Lib/nntplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def putline(self, line):
179179
"""Internal: send one line to the server, appending CRLF."""
180180
line = line + CRLF
181181
if self.debugging > 1: print '*put*', `line`
182-
self.sock.send(line)
182+
self.sock.sendall(line)
183183

184184
def putcmd(self, line):
185185
"""Internal: send one command to the server (through putline())."""

Lib/poplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(self, host, port = POP3_PORT):
9797

9898
def _putline(self, line):
9999
if self._debugging > 1: print '*put*', `line`
100-
self.sock.send('%s%s' % (line, CRLF))
100+
self.sock.sendall('%s%s' % (line, CRLF))
101101

102102

103103
# Internal: send one command to the server (through _putline())

Lib/smtplib.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ def send(self, str):
290290
if self.debuglevel > 0: print 'send:', `str`
291291
if self.sock:
292292
try:
293-
sendptr = 0
294-
while sendptr < len(str):
295-
sendptr = sendptr + self.sock.send(str[sendptr:])
293+
self.sock.sendall(str)
296294
except socket.error:
297295
self.close()
298296
raise SMTPServerDisconnected('Server not connected')

Lib/socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def __del__(self):
185185

186186
def flush(self):
187187
if self._wbuf:
188-
self._sock.send(self._wbuf)
188+
self._sock.sendall(self._wbuf)
189189
self._wbuf = ""
190190

191191
def fileno(self):
@@ -201,7 +201,7 @@ def write(self, data):
201201
self.flush()
202202

203203
def writelines(self, list):
204-
filter(self._sock.send, list)
204+
filter(self._sock.sendall, list)
205205
self.flush()
206206

207207
def read(self, n=-1):

Lib/telnetlib.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def write(self, buffer):
269269
if IAC in buffer:
270270
buffer = buffer.replace(IAC, IAC+IAC)
271271
self.msg("send %s", `buffer`)
272-
self.sock.send(buffer)
272+
self.sock.sendall(buffer)
273273

274274
def read_until(self, match, timeout=None):
275275
"""Read until a given string is encountered or until timeout.
@@ -411,15 +411,15 @@ def process_rawq(self):
411411
if self.option_callback:
412412
self.option_callback(self.sock, c, opt)
413413
else:
414-
self.sock.send(IAC + WONT + opt)
414+
self.sock.sendall(IAC + WONT + opt)
415415
elif c in (WILL, WONT):
416416
opt = self.rawq_getchar()
417417
self.msg('IAC %s %d',
418418
c == WILL and 'WILL' or 'WONT', ord(opt))
419419
if self.option_callback:
420420
self.option_callback(self.sock, c, opt)
421421
else:
422-
self.sock.send(IAC + DONT + opt)
422+
self.sock.sendall(IAC + DONT + opt)
423423
else:
424424
self.msg('IAC %d not recognized' % ord(opt))
425425
except EOFError: # raised by self.rawq_getchar()

0 commit comments

Comments
 (0)