[Python-checkins] cpython (merge 3.2 -> default): issue10883 - Silence some ftp related ResourceWarnings in test_urllib2net.

senthil.kumaran python-checkins at python.org
Thu Mar 24 04:47:53 CET 2011


http://hg.python.org/cpython/rev/0937b3618b86
changeset:   68891:0937b3618b86
parent:      68889:f09f7ab40ce6
parent:      68890:2e5aff2a9e54
user:        Senthil Kumaran <orsenthil at gmail.com>
date:        Thu Mar 24 11:47:29 2011 +0800
summary:
  issue10883 - Silence some ftp related ResourceWarnings in test_urllib2net. Patch by Nadeem Vawda

files:
  Lib/urllib/request.py |  10 +++++++---
  1 files changed, 7 insertions(+), 3 deletions(-)


diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2136,7 +2136,7 @@
             # Try to retrieve as a file
             try:
                 cmd = 'RETR ' + file
-                conn = self.ftp.ntransfercmd(cmd)
+                conn, retrlen = self.ftp.ntransfercmd(cmd)
             except ftplib.error_perm as reason:
                 if str(reason)[:3] != '550':
                     raise URLError('ftp error', reason).with_traceback(
@@ -2157,10 +2157,14 @@
                 cmd = 'LIST ' + file
             else:
                 cmd = 'LIST'
-            conn = self.ftp.ntransfercmd(cmd)
+            conn, retrlen = self.ftp.ntransfercmd(cmd)
         self.busy = 1
+
+        ftpobj = addclosehook(conn.makefile('rb'), self.endtransfer)
+        conn.close()
         # Pass back both a suitably decorated object and a retrieval length
-        return (addclosehook(conn[0].makefile('rb'), self.endtransfer), conn[1])
+        return (ftpobj, retrlen)
+
     def endtransfer(self):
         if not self.busy:
             return

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list