Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f7cb5d

Browse files
committed
Patch [ 972332 ] urllib2 FTPHandler bugs / John J. Lee
Modified Files: urllib2.py test/test_urllib2.py
1 parent e246508 commit 3f7cb5d

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

Lib/test/test_urllib2.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,12 @@ def connect_ftp(self, user, passwd, host, port, dirs):
314314
("ftp://localhost/foo/bar/baz.html",
315315
"localhost", ftplib.FTP_PORT, "I",
316316
["foo", "bar"], "baz.html", "text/html"),
317-
# XXXX Bug: FTPHandler tries to gethostbyname "localhost:80", with the
318-
# port still there.
319-
## ("ftp://localhost:80/foo/bar/",
320-
## "localhost", 80, "D",
321-
## ["foo", "bar"], "", None),
322-
# XXXX bug: second use of splitattr() in FTPHandler should be splitvalue()
323-
## ("ftp://localhost/baz.gif;type=a",
324-
## "localhost", ftplib.FTP_PORT, "A",
325-
## [], "baz.gif", "image/gif"),
317+
("ftp://localhost:80/foo/bar/",
318+
"localhost", 80, "D",
319+
["foo", "bar"], "", None),
320+
("ftp://localhost/baz.gif;type=a",
321+
"localhost", ftplib.FTP_PORT, "A",
322+
[], "baz.gif", None), # XXX really this should guess image/gif
326323
]:
327324
r = h.ftp_open(Request(url))
328325
# ftp authentication not yet implemented by FTPHandler
@@ -333,7 +330,7 @@ def connect_ftp(self, user, passwd, host, port, dirs):
333330
self.assertEqual(h.ftpwrapper.filename, filename)
334331
self.assertEqual(h.ftpwrapper.filetype, type_)
335332
headers = r.info()
336-
self.assertEqual(headers["Content-type"], mimetype)
333+
self.assertEqual(headers.get("Content-type"), mimetype)
337334
self.assertEqual(int(headers["Content-length"]), len(data))
338335

339336
def test_file(self):

Lib/urllib2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
# not sure how many of these need to be gotten rid of
117117
from urllib import unwrap, unquote, splittype, splithost, \
118118
addinfourl, splitport, splitgophertype, splitquery, \
119-
splitattr, ftpwrapper, noheaders, splituser, splitpasswd
119+
splitattr, ftpwrapper, noheaders, splituser, splitpasswd, splitvalue
120120

121121
# support for FileHandler, proxies via environment variables
122122
from urllib import localhost, url2pathname, getproxies
@@ -1143,6 +1143,8 @@ def ftp_open(self, req):
11431143
host, port = splitport(host)
11441144
if port is None:
11451145
port = ftplib.FTP_PORT
1146+
else:
1147+
port = int(port)
11461148

11471149
# username/password handling
11481150
user, host = splituser(host)
@@ -1168,7 +1170,7 @@ def ftp_open(self, req):
11681170
fw = self.connect_ftp(user, passwd, host, port, dirs)
11691171
type = file and 'I' or 'D'
11701172
for attr in attrs:
1171-
attr, value = splitattr(attr)
1173+
attr, value = splitvalue(attr)
11721174
if attr.lower() == 'type' and \
11731175
value in ('a', 'A', 'i', 'I', 'd', 'D'):
11741176
type = value.upper()

0 commit comments

Comments
 (0)