From 05ec8df728820deaa7ec7b60cefcf429ab21e5e3 Mon Sep 17 00:00:00 2001 From: Colin Leitner Date: Fri, 18 Apr 2014 16:39:54 +0200 Subject: [PATCH] Added optional filename key to the URL fetcher result --- weasyprint/urls.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/weasyprint/urls.py b/weasyprint/urls.py index 44b7bb7b9..130c30774 100644 --- a/weasyprint/urls.py +++ b/weasyprint/urls.py @@ -250,6 +250,9 @@ def default_url_fetcher(url): *charset* parameter in a *Content-Type* header * Optionally: ``redirected_url``, the actual URL of the ressource in case there were eg. HTTP redirects. + * Optionally: ``filename``, the filename of the resource. Usually + derived from the *filename* parameter in a *Content-Disposition* + header If a ``file_obj`` key is given, it is the caller’s responsability to call ``file_obj.close()``. @@ -261,8 +264,9 @@ def default_url_fetcher(url): url = iri_to_uri(url) result, mime_type, charset = urlopen_contenttype(Request( url, headers={'User-Agent': VERSION_STRING})) + filename = result.info().get_filename() return dict(file_obj=result, redirected_url=result.geturl(), - mime_type=mime_type, encoding=charset) + mime_type=mime_type, encoding=charset, filename=filename) else: raise ValueError('Not an absolute URI: %r' % url)