add doc for request

This commit is contained in:
Prodesire 2017-11-13 02:20:47 +08:00
parent f79009ce16
commit 74dd3ffe1b
3 changed files with 28 additions and 4 deletions

View File

@ -26,5 +26,6 @@ Content
console
dict
misc
request
set
string

25
docs/request.rst Normal file
View File

@ -0,0 +1,25 @@
Request
-------
.. py:class:: pydu.request.Filename
Supply several methods to get filename.
.. py:staticmethod:: from_url(url):
Detected filename as unicode or None.
.. py:staticmethod:: from_headers(headers):
Detect filename from Content-Disposition headers if present.
``headers`` could be a dict, list or string.
.. py:function:: pydu.request.download(url, dst=None)
High level function, which downloads URL into tmp file in current
directory and then renames it to filename autodetected from either URL
or HTTP headers.
``url`` indicates which url to download.
``dst`` is the filename or directory of destination. ``None`` as default, means
download to current directory.

View File

@ -30,7 +30,6 @@ class FileName(object):
Detect filename from Content-Disposition headers if present.
headers: as dict, list or string
filename: from content-disposition header or None
"""
if not headers:
return None
@ -73,9 +72,8 @@ def download(url, dst=None):
directory and then renames it to filename autodetected from either URL
or HTTP headers.
bar: function to track download progress (visualize etc.)
out: output filename or directory
filename: where URL is downloaded to
url: which url to download
dst: filename or directory of destination
"""
# detect of dst is a directory
dst_ = None