mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-11 01:50:59 +00:00
Use sys.stdout wrapper for CGI output.
This commit is contained in:
parent
73a9b1ad13
commit
77f207b69a
3 changed files with 20 additions and 16 deletions
|
|
@ -11,6 +11,8 @@ Fixes:
|
|||
- checking: Work around a Python 2.7 regression in parsing certain
|
||||
URLs with paths starting with a digit.
|
||||
- cmdline: Fix filename completion if path starts with ~
|
||||
- cgi: Prevent encoding errors printing to sys.stdout using an
|
||||
encoding wrapper.
|
||||
|
||||
Changes:
|
||||
- checking: Use HTTP GET requests to work around buggy IIS servers
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import re
|
|||
import time
|
||||
import urlparse
|
||||
import types
|
||||
from . import configuration, strformat, checker, director
|
||||
from . import configuration, strformat, checker, director, logger
|
||||
from . import add_intern_pattern, get_link_pat, init_i18n
|
||||
from . import url as urlutil
|
||||
|
||||
|
|
@ -45,16 +45,20 @@ class LCFormError (StandardError):
|
|||
pass
|
||||
|
||||
|
||||
def startoutput (out=sys.stdout):
|
||||
def startoutput (out=None):
|
||||
"""Print leading HTML headers to given output stream."""
|
||||
if out is None:
|
||||
out = logger.get_stdout_writer()
|
||||
out.write("Content-type: text/html\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"\r\n")
|
||||
|
||||
|
||||
def checklink (out=sys.stdout, form=None, env=os.environ):
|
||||
def checklink (out=None, form=None, env=os.environ):
|
||||
"""Main cgi function, check the given links and print out the result."""
|
||||
if out is None:
|
||||
out = logger.get_stdout_writer()
|
||||
if form is None:
|
||||
form = {}
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -39,18 +39,14 @@ class TestCgi (unittest.TestCase):
|
|||
"""
|
||||
|
||||
def test_form_valid_url (self):
|
||||
"""
|
||||
Check url validity.
|
||||
"""
|
||||
# Check url validity.
|
||||
form = {"url": Store("http://www.heise.de/"),
|
||||
"level": Store("0"),
|
||||
"level": Store("1"),
|
||||
}
|
||||
linkcheck.lc_cgi.checkform(form)
|
||||
|
||||
def test_form_empty_url (self):
|
||||
"""
|
||||
Check with empty url.
|
||||
"""
|
||||
# Check with empty url.
|
||||
form = {"url": Store(""),
|
||||
"level": Store("0"),
|
||||
}
|
||||
|
|
@ -58,9 +54,7 @@ class TestCgi (unittest.TestCase):
|
|||
linkcheck.lc_cgi.checkform, form)
|
||||
|
||||
def test_form_default_url (self):
|
||||
"""
|
||||
Check with default url.
|
||||
"""
|
||||
# Check with default url.
|
||||
form = {"url": Store("http://"),
|
||||
"level": Store("0"),
|
||||
}
|
||||
|
|
@ -68,11 +62,15 @@ class TestCgi (unittest.TestCase):
|
|||
linkcheck.lc_cgi.checkform, form)
|
||||
|
||||
def test_form_invalid_url (self):
|
||||
"""
|
||||
Check url (in)validity.
|
||||
"""
|
||||
# Check url (in)validity.
|
||||
form = {"url": Store("http://www.foo bar/"),
|
||||
"level": Store("0"),
|
||||
}
|
||||
self.assertRaises(linkcheck.lc_cgi.LCFormError,
|
||||
linkcheck.lc_cgi.checkform, form)
|
||||
|
||||
def test_checklink (self):
|
||||
form = {"url": Store("http://www.heise.de/"),
|
||||
"level": Store("0"),
|
||||
}
|
||||
linkcheck.lc_cgi.checklink(form=form)
|
||||
|
|
|
|||
Loading…
Reference in a new issue