pydu/docs/request.rst

41 lines
1.2 KiB
ReStructuredText
Raw Normal View History

2017-11-12 18:20:47 +00:00
Request
-------
.. py:class:: pydu.request.Filename
2017-12-05 14:15:27 +00:00
Supply several methods to get filename.
2017-11-12 18:20:47 +00:00
2017-12-05 14:15:27 +00:00
.. py:staticmethod:: from_url(url):
2017-11-12 18:20:47 +00:00
2017-12-05 14:15:27 +00:00
Detected filename as unicode or None.
2017-11-12 18:20:47 +00:00
2017-12-05 14:15:27 +00:00
.. py:staticmethod:: from_headers(headers):
2017-11-12 18:20:47 +00:00
2017-12-05 14:15:27 +00:00
Detect filename from Content-Disposition headers if present.
``headers`` could be a dict, list or string.
2017-11-12 18:20:47 +00:00
2017-12-14 12:32:47 +00:00
.. py:staticmethod:: from_any(dst=None, headers=None, url=None):
Detect filename from dst or headers or url.
2017-11-12 18:20:47 +00:00
.. py:function:: pydu.request.download(url, dst=None)
2017-12-05 14:15:27 +00:00
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.
.. py:function:: pydu.request.check_connect(p, port, retry=1, timeout=0.5)
Check whether given ``ip`` and ``port`` could connect or not.
It will ``retry`` and ``timeout`` on given.
>>> from pydu.request import check_connect
>>> check_connect('http://www.baidu.com', 80)
'192.168.3.8'
>>>