[Patches] [ python-Patches-454553 ] Content-Type header for ftp url
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 24 Aug 2001 06:17:45 -0700
Patches item #454553, was opened at 2001-08-23 05:59
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=454553&group_id=5470
Category: library
Group: None
Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Guido van Rossum (gvanrossum)
Summary: Content-Type header for ftp url
Initial Comment:
This patch changes urllib.URLOpener.open_ftp: A
Content-Type header is included when the MIME type can
be guessed via mimetypes.guess_type.
A patch to the documentation is included.
Example:
>>> import urllib
>>> urllib.urlopen
("ftp://ftp.python.org/pub/python/2.2/Python-
2.2a2.tgz").info().headers
['Content-Type: application/x-tar\n', 'Content-Length:
5980204\n']
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-24 06:17
Message:
Logged In: YES
user_id=6380
I meant "file:/tmp/diff.txt". Sorry for the confusion!!!
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-24 06:12
Message:
Logged In: YES
user_id=6380
Thanks for the second patch!
It seems urllib2 accepts these forms of file URLs:
"file:PLAN.txt", or "file://tmp/diff.txt". I am not sure
that "file://PLAN.txt" is supposed to work -- that would
suggest the hostname is "PLAN.txt".
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2001-08-24 05:58
Message:
Logged In: YES
user_id=89016
> Feel free to contribute a patch.
The new patch adds the same functionality to urllib2.
> (Does it do content-types for local files yet?)
I don't know. Local files don't seem work:
>>> import urllib2
>>> urllib2.urlopen("PLAN.txt").info
().headers
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.2/urllib2.py", line 134, in
urlopen
return _opener.open(url, data)
File "/usr/local/lib/python2.2/urllib2.py", line 316, in
open
type_ = req.get_type()
File "/usr/local/lib/python2.2/urllib2.py", line 220, in
get_type
raise ValueError, "unknown url type: %s" %
self.__original
ValueError: unknown url type: PLAN.txt
>>> urllib2.urlopen("file://PLAN.txt").info().headers
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.2/urllib2.py", line 134, in
urlopen
return _opener.open(url, data)
File "/usr/local/lib/python2.2/urllib2.py", line 318, in
open
'_open', req)
File "/usr/local/lib/python2.2/urllib2.py", line 297, in
_call_chain
result = func(*args)
File "/usr/local/lib/python2.2/urllib2.py", line 905, in
file_open
return self.open_local_file(req)
File "/usr/local/lib/python2.2/urllib2.py", line 924, in
open_local_file
if not host or \
socket.gaierror: (-2, 'Name or service not known')
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-23 07:33
Message:
Logged In: YES
user_id=6380
Feel free to contribute a patch. (Does it do content-types
for local files yet?)
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2001-08-23 07:01
Message:
Logged In: YES
user_id=89016
Equivalent changes should probably be made to
urllib2.FTPHandler.ftp_open too.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-23 06:38
Message:
Logged In: YES
user_id=6380
Thanks! Applied to CVS (with minimal changes).
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=454553&group_id=5470