From 780c7b72a1ec58f54703927ab469e6dd88b15475 Mon Sep 17 00:00:00 2001 From: Prodesire Date: Tue, 5 Dec 2017 22:15:27 +0800 Subject: [PATCH] add doc for request.check_connect --- docs/request.rst | 35 +++++++++++++++++++++++------------ pydu/request.py | 4 ++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/docs/request.rst b/docs/request.rst index 52a0b91..82ce1ec 100644 --- a/docs/request.rst +++ b/docs/request.rst @@ -3,23 +3,34 @@ Request .. py:class:: pydu.request.Filename - Supply several methods to get filename. + Supply several methods to get filename. - .. py:staticmethod:: from_url(url): + .. py:staticmethod:: from_url(url): - Detected filename as unicode or None. + Detected filename as unicode or None. - .. py:staticmethod:: from_headers(headers): + .. py:staticmethod:: from_headers(headers): - Detect filename from Content-Disposition headers if present. - ``headers`` could be a dict, list or string. + 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. + 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' + >>> diff --git a/pydu/request.py b/pydu/request.py index 3e87cdf..5200eee 100644 --- a/pydu/request.py +++ b/pydu/request.py @@ -104,8 +104,8 @@ def download(url, dst=None): def check_connect(ip, port, retry=1, timeout=0.5): """ - Check whether given ip and port could connect or not. - It will retry and timeout on given. + Check whether given ``ip`` and ``port`` could connect or not. + It will ``retry`` and ``timeout`` on given. """ while retry: try: