summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-01-20 12:18:17 (GMT)
committerGeorg Brandl <georg@python.org>2008-01-20 12:18:17 (GMT)
commitd5e6cf2b152061cdae0164cef2382086c7638bbc (patch)
treeca57cc2750f1654fc6646eb706ecb056455ae790 /Lib
parent2235011d49bc543ced855804ac9b87c0e98a7b19 (diff)
downloadcpython-d5e6cf2b152061cdae0164cef2382086c7638bbc.zip
cpython-d5e6cf2b152061cdae0164cef2382086c7638bbc.tar.gz
cpython-d5e6cf2b152061cdae0164cef2382086c7638bbc.tar.bz2
#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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 2e720ac..6608abc 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -872,9 +872,19 @@ class ftpwrapper:
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