[Patches] [ python-Patches-454553 ] Content-Type header for ftp url
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 27 Aug 2001 13:19:01 -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: Jeremy Hylton (jhylton)
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: Jeremy Hylton (jhylton)
Date: 2001-08-27 13:19
Message:
Logged In: YES
user_id=31392
third patch applied (with explantion of rfc822.formatdate()
change in its doc string
rfc822.py: rev 1.60
urllib.py: rev 1.133
urllib2.py: rev 1.21
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-24 09:51
Message:
Logged In: YES
user_id=6380
Jeremy, can you apply the 3rd patch? I'm running out of time
-- still gotta pack for my trip...
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2001-08-24 09:42
Message:
Logged In: YES
user_id=89016
This third patch adds the headers Content-Length and Last-
Modified to local files for urllib2 too (patch #420753 did
it for urllib.py). (Content-Type already works for local
files)
The formatting of the Last-Modified header is now done with
rfc822.formatdate and rfc822.formatdate has been fixed to
even work with a modified locale. (RFC1123 requires english
day of week and month names, but rfc822.formatdate
used time.strftime("%a %b") which returns locale aware
names.)
----------------------------------------------------------------------
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