diff options
author | Guido van Rossum <guido@python.org> | 2001-08-23 13:38:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-23 13:38:15 (GMT) |
commit | 88e0b5bee0e69b628a9358c987bf49ac885d1c21 (patch) | |
tree | 09091cc535519f0c779926aea190f392f7794264 /Lib/urllib.py | |
parent | be92af0e2ae1fe7c677f62361da4b45183603b09 (diff) | |
download | cpython-88e0b5bee0e69b628a9358c987bf49ac885d1c21.zip cpython-88e0b5bee0e69b628a9358c987bf49ac885d1c21.tar.gz cpython-88e0b5bee0e69b628a9358c987bf49ac885d1c21.tar.bz2 |
SF patch #454553 by Walter Dörwald: auto-guess content-type header for
ftp urls.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r-- | Lib/urllib.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index f60a841..a255956 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -440,6 +440,7 @@ class URLopener: def open_ftp(self, url): """Use FTP protocol.""" + import mimetypes, mimetools, StringIO host, path = splithost(url) if not host: raise IOError, ('ftp error', 'no host given') host, port = splitport(host) @@ -482,12 +483,13 @@ class URLopener: value in ('a', 'A', 'i', 'I', 'd', 'D'): type = value.upper() (fp, retrlen) = self.ftpcache[key].retrfile(file, type) + mtype = mimetypes.guess_type("ftp:" + url)[0] + headers = "" + if mtype: + headers += "Content-Type: %s\n" % mtype if retrlen is not None and retrlen >= 0: - import mimetools, StringIO - headers = mimetools.Message(StringIO.StringIO( - 'Content-Length: %d\n' % retrlen)) - else: - headers = noheaders() + headers += "Content-Length: %d\n" % retrlen + headers = mimetools.Message(StringIO.StringIO(headers)) return addinfourl(fp, headers, "ftp:" + url) except ftperrors(), msg: raise IOError, ('ftp error', msg), sys.exc_info()[2] |