mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-05-19 12:01:07 +00:00
Support maxrequestspersecond less than one
This commit is contained in:
parent
e88cf49c8f
commit
0c5db040c8
4 changed files with 23 additions and 2 deletions
|
|
@ -90,7 +90,8 @@ checking
|
|||
**maxrequestspersecond=**\ *NUMBER*
|
||||
Limit the maximum number of HTTP requests per second to one host.
|
||||
The average number of requests per second is approximately one third of the
|
||||
maximum. To use values greater than 10, the HTTP server must return a
|
||||
maximum. Values less than 1 and at least 0.001 can be used.
|
||||
To use values greater than 10, the HTTP server must return a
|
||||
"LinkChecker" response header.
|
||||
The default is 10.
|
||||
Command line option: none
|
||||
|
|
|
|||
|
|
@ -86,6 +86,24 @@ class LCConfigParser(RawConfigParser):
|
|||
if self.has_option(section, option):
|
||||
self.config[option] = self.getboolean(section, option)
|
||||
|
||||
def read_float_option(self, section, option, key=None, min=None, max=None):
|
||||
"""Read a float option."""
|
||||
if self.has_option(section, option):
|
||||
num = self.getfloat(section, option)
|
||||
if min is not None and num < min:
|
||||
raise LinkCheckerError(
|
||||
_("invalid value for %s: %d must not be less than %d")
|
||||
% (option, num, min)
|
||||
)
|
||||
if max is not None and num < max:
|
||||
raise LinkCheckerError(
|
||||
_("invalid value for %s: %d must not be greater than %d")
|
||||
% (option, num, max)
|
||||
)
|
||||
if key is None:
|
||||
key = option
|
||||
self.config[key] = num
|
||||
|
||||
def read_int_option(self, section, option, key=None, min=None, max=None):
|
||||
"""Read an integer option."""
|
||||
if self.has_option(section, option):
|
||||
|
|
@ -178,7 +196,7 @@ class LCConfigParser(RawConfigParser):
|
|||
self.read_int_option(section, "recursionlevel", min=-1)
|
||||
self.read_string_option(section, "nntpserver")
|
||||
self.read_string_option(section, "useragent")
|
||||
self.read_int_option(section, "maxrequestspersecond", min=1)
|
||||
self.read_float_option(section, "maxrequestspersecond", min=0.001)
|
||||
self.read_int_option(section, "maxnumurls", min=0)
|
||||
self.read_int_option(section, "maxfilesizeparse", min=1)
|
||||
self.read_int_option(section, "maxfilesizedownload", min=1)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ debugmemory=1
|
|||
localwebroot=foo
|
||||
sslverify=/path/to/cacerts.crt
|
||||
maxnumurls=1000
|
||||
maxrequestspersecond=0.1
|
||||
maxrunseconds=1
|
||||
maxfilesizeparse=100
|
||||
maxfilesizedownload=100
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class TestConfig(unittest.TestCase):
|
|||
self.assertEqual(config["localwebroot"], "foo")
|
||||
self.assertEqual(config["sslverify"], "/path/to/cacerts.crt")
|
||||
self.assertEqual(config["maxnumurls"], 1000)
|
||||
self.assertEqual(config["maxrequestspersecond"], 0.1)
|
||||
self.assertEqual(config["maxrunseconds"], 1)
|
||||
self.assertEqual(config["maxfilesizeparse"], 100)
|
||||
self.assertEqual(config["maxfilesizedownload"], 100)
|
||||
|
|
|
|||
Loading…
Reference in a new issue