[Python-checkins] r60135 - in python/trunk: Lib/urllib.py Misc/NEWS

georg.brandl python-checkins at python.org
Sun Jan 20 13:18:18 CET 2008


Author: georg.brandl
Date: Sun Jan 20 13:18:17 2008
New Revision: 60135
Modified:
 python/trunk/Lib/urllib.py
 python/trunk/Misc/NEWS
Log:
#1664522: in urllib, don't read non-existing directories in ftp mode,
returning a 0-byte file -- raise an IOError instead.
Original patch from Phil Knirsch.
Modified: python/trunk/Lib/urllib.py
==============================================================================
--- python/trunk/Lib/urllib.py	(original)
+++ python/trunk/Lib/urllib.py	Sun Jan 20 13:18:17 2008
@@ -872,9 +872,19 @@
 if not conn:
 # Set transfer mode to ASCII!
 self.ftp.voidcmd('TYPE A')
- # Try a directory listing
- if file: cmd = 'LIST ' + file
- else: cmd = 'LIST'
+ # Try a directory listing. Verify that directory exists.
+ if file:
+ pwd = self.ftp.pwd()
+ try:
+ try:
+ self.ftp.cwd(file)
+ except ftplib.error_perm, reason:
+ raise IOError, ('ftp error', reason), sys.exc_info()[2]
+ finally:
+ self.ftp.cwd(pwd)
+ cmd = 'LIST ' + file
+ else:
+ cmd = 'LIST'
 conn = self.ftp.ntransfercmd(cmd)
 self.busy = 1
 # Pass back both a suitably decorated object and a retrieval length
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Jan 20 13:18:17 2008
@@ -369,6 +369,9 @@
 Library
 -------
 
+- #1664522: in urllib, don't read non-existing directories in ftp mode,
+ returning a 0-byte file -- raise an IOError instead.
+
 - #856047: respect the ``no_proxy`` environment variable when using the
 ``http_proxy`` etc. environment variables in urllib.
 


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /