]> granicus.if.org Git - python/commitdiff
The Grande 'sendall()' patch, copied from release21-maint. Fixes #516715.
authorMartin v. Löwis <martin@v.loewis.de>
Sat, 16 Feb 2002 23:06:19 +0000 (23:06 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sat, 16 Feb 2002 23:06:19 +0000 (23:06 +0000)
Replaces calls to socket.send() (which isn't guaranteed to send all data)
with the new socket.sendall() method.

Lib/ftplib.py
Lib/gopherlib.py
Lib/httplib.py
Lib/imaplib.py
Lib/nntplib.py
Lib/poplib.py
Lib/smtplib.py
Lib/socket.py
Lib/telnetlib.py

index 6234f7f21eb643901034779e8b70a1c47b2809b1..cad7a5b90db45a57b5b9a70ce00f088bd5bea59f 100644 (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()
 
index 8dea5660e696a282468f46954bb5eb3d247ccd3b..03d12ecbb3972590f2f2b3bea58b8b22ed96402d 100644 (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')
 
index cd0bdb97d0a6a10dea6083284e8cf47f7c56a7bf..04cfca6dc15602e6bbb50ab91385319db9ea1191 100644 (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()
index 04d4d87bb92fa73edbc81b3a148792d412d4a68d..03513a36b204aab36c6e5bdf47d13c580dfb1817 100644 (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"."""
index fad6b08c6e9b64c72241449f571155bef06d1783..21faab1aa36aa16370a1ce0cf024dcf7a0d968fe 100644 (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())."""
index 23c0b46b346531d7810afb6a99786a241b647f1e..052504302e7f4bdf5b4e7e749b1a87a32841e6e5 100644 (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())
index cb15de202f077a9c0dfaf8730a83d0c4cd296c3a..f024bffc1f56224dad5bd5235a3ed0eb3bbeb555 100755 (executable)
@@ -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')
index c460c5fb56a52eb45fd55b23cd5dcdf0072dcb28..45131ce840cb7c8128574b1ebb2b59273510b412 100644 (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):
index 15721c6e6f44b3c940d312e190a3f0877d11de93..cdbbd9f5cc744e4da86bbcd697d5fddcd6325c3a 100644 (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()