diff options
author | Senthil Kumaran <orsenthil@gmail.com> | 2011-03-24 03:46:19 (GMT) |
---|---|---|
committer | Senthil Kumaran <orsenthil@gmail.com> | 2011-03-24 03:46:19 (GMT) |
commit | 2024acd36ffa0b39229425843bfae572b50ef6e3 (patch) | |
tree | 5d670e7934739ab1ed7a260409f03a6f74f23bba | |
parent | e44b1258eabf62034818034c070a7581ff23606c (diff) | |
download | cpython-2024acd36ffa0b39229425843bfae572b50ef6e3.zip cpython-2024acd36ffa0b39229425843bfae572b50ef6e3.tar.gz cpython-2024acd36ffa0b39229425843bfae572b50ef6e3.tar.bz2 |
issue10883 - Silence some ftp related ResourceWarnings in test_urllib2net. Patch by Nadeem Vawda.
-rw-r--r-- | Lib/urllib/request.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py index 4d3648d..53e8107 100644 --- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -2136,7 +2136,7 @@ class ftpwrapper: # 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 @@ class ftpwrapper: 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 |