pep8-ify the source a little more

This commit is contained in:
Bastian Kleineidam 2010-03-13 08:47:12 +01:00
parent c83a79c0ef
commit c4c098bd83
40 changed files with 109 additions and 93 deletions

View file

@ -17,7 +17,8 @@ DEB_ORIG_TARGET:=$(BUILDDIR)/linkchecker_$(VERSION).orig.tar.gz
# original dnspython repository module
DNSPYTHON:=$(HOME)/src/dnspython-git/dns
# options to run the pep8 utility
PEP8OPTS:=--repeat --ignore=E211,E501 --exclude=dns
PEP8OPTS:=--repeat --ignore=E211,E501,E225,E301,E302,E241 \
--exclude="dns,gzip2.py,httplib2.py,robotparser2.py,reindent.py"
.PHONY: all
@ -83,6 +84,7 @@ release: distclean releasecheck dist-stamp sign_distfiles upload
$(MAKE) -C ~/public_html/linkchecker.sf.net update upload
@echo "Register at Python Package Index..."
$(PYTHON) setup.py register
wget http://pypants.org/projects/linkchecker/update/
.PHONY: chmod
chmod:

View file

@ -40,4 +40,3 @@ def getaddrinfo (host, port):
if isinstance(value, Exception):
raise value
return value

View file

@ -160,7 +160,6 @@ HTML_MIMETYPES = (
# if file extension lookup was unsuccessful, look at the content
PARSE_CONTENTS = {
"html": re.compile(r'^(?i)<(!DOCTYPE html|html|head|title)'),
"opera" : re.compile(r'^Opera Hotlist'),
"text" : re.compile(r'(?i)^# LinkChecker URL list'),
"opera": re.compile(r'^Opera Hotlist'),
"text": re.compile(r'(?i)^# LinkChecker URL list'),
}

View file

@ -77,7 +77,7 @@ def is_absolute_path (path):
with a drive letter. On all other systems absolute paths start with
a slash."""
if os.name == 'nt':
return re.search(r"^[a-zA-Z]:", path)
return re.search(r"^[a-zA-Z]:", path)
return path.startswith("/")

View file

@ -328,7 +328,7 @@ class MailtoUrl (urlbase.UrlBase):
self.add_info(_("Verified address %(mail)s: %(info)s.") % d)
# check for 25x status code which means that the address
# could not be verified, but is sent anyway
elif 250 < status < 260:
elif 250 < status < 260:
self.add_info(_("Unverified but presumably valid"
" address %(mail)s: %(info)s.") % d)
else:

View file

@ -31,7 +31,7 @@ from . import confparse
Version = configdata.version
AppName = configdata.appname
App = AppName+u" "+Version
Author = configdata.author
Author = configdata.author
HtmlAuthor = Author.replace(u' ', u'&nbsp;')
Copyright = u"Copyright (C) 2000-2010 "+Author
HtmlCopyright = u"Copyright &copy; 2000-2010 "+HtmlAuthor

View file

@ -126,7 +126,7 @@ class LCConfigParser (ConfigParser.RawConfigParser, object):
if val:
self.config["warningregex"] = re.compile(val)
if self.has_option(section, "warnsizebytes"):
val = self.get(section,"warnsizebytes")
val = self.get(section, "warnsizebytes")
self.config["warnsizebytes"] = int(val)
if self.has_option(section, "nntpserver"):
self.config["nntpserver"] = self.get(section, "nntpserver")
@ -134,14 +134,14 @@ class LCConfigParser (ConfigParser.RawConfigParser, object):
def read_check_options (self, section):
"""Read check* options."""
if self.has_option(section,"checkhtml"):
if self.has_option(section, "checkhtml"):
self.config["checkhtml"] = self.getboolean(section, "checkhtml")
if self.has_option(section,"checkcss"):
if self.has_option(section, "checkcss"):
self.config["checkcss"] = self.getboolean(section, "checkcss")
if self.has_option(section,"checkhtmlw3"):
if self.has_option(section, "checkhtmlw3"):
val = self.getboolean(section, "checkhtmlw3")
self.config["checkhtmlw3"] = val
if self.has_option(section,"checkcssw3"):
if self.has_option(section, "checkcssw3"):
self.config["checkcssw3"] = self.getboolean(section, "checkcssw3")
if self.has_option(section, "scanvirus"):
self.config["scanvirus"] = self.getboolean(section, "scanvirus")

View file

@ -49,7 +49,7 @@ has_embedded_dot = re.compile(r"[a-zA-Z0-9]\.[a-zA-Z]").search
# Pattern for finding cookie snatched from Pythons Cookie.py
# Modification: allow whitespace in values.
LegalChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
LegalChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
CookiePattern = re.compile(r"""
(?P<key> # Start of group 'key'
[%(legalchars)s]+? # Any word of at least one letter, nongreedy

View file

@ -87,7 +87,7 @@ def print_app_info (out=stderr):
print >> out, configuration.App
print >> out, _("Python %(version)s on %(platform)s") % \
{"version": sys.version, "platform": sys.platform}
for key in ("LC_ALL", "LC_MESSAGES", "http_proxy", "ftp_proxy", "no_proxy"):
for key in ("LC_ALL", "LC_MESSAGES", "http_proxy", "ftp_proxy", "no_proxy"):
value = os.getenv(key)
if value is not None:
print >> out, key, "=", repr(value)

View file

@ -81,7 +81,8 @@ FCGI_OVERLOADED = 2 # New request rejected; too busy
FCGI_UNKNOWN_ROLE = 3 # Role value not known
error = 'fcgi.error'
class error(StandardError):
pass
# The following function is used during debugging; it isn't called
@ -160,14 +161,14 @@ class Record (object):
e_len = (c_len + 7) & (0xFFFF - 7) # align to an 8-byte boundary
pad_len = e_len - c_len
hdr = [ self.version,
self.rec_type,
self.req_id >> 8,
self.req_id & 255,
c_len >> 8,
c_len & 255,
pad_len,
0]
hdr = [self.version,
self.rec_type,
self.req_id >> 8,
self.req_id & 255,
c_len >> 8,
c_len & 255,
pad_len,
0]
hdr = ''.join(chr(x) for x in hdr)
sock.send(hdr + content + pad_len*'\000')
@ -186,8 +187,8 @@ def read_pair (s, pos):
b = [ord(x) for x in s[pos:pos+3]]
pos += 3
value_len = ((value_len&127)<<24) + (b[0]<<16) + (b[1]<<8) + b[2]
return ( s[pos:pos+name_len], s[pos+name_len:pos+name_len+value_len],
pos+name_len+value_len )
return (s[pos:pos+name_len], s[pos+name_len:pos+name_len+value_len],
pos+name_len+value_len)
def write_pair (name, value):
@ -210,8 +211,8 @@ def HandleManTypes (r, conn):
if r.rec_type == FCGI_GET_VALUES:
r.rec_type = FCGI_GET_VALUES_RESULT
v = {}
_vars = {'FCGI_MAX_CONNS' : FCGI_MAX_CONNS,
'FCGI_MAX_REQS' : FCGI_MAX_REQS,
_vars = {'FCGI_MAX_CONNS': FCGI_MAX_CONNS,
'FCGI_MAX_REQS': FCGI_MAX_REQS,
'FCGI_MPXS_CONNS': FCGI_MPXS_CONNS}
for i in r.values.keys():
if i in _vars:
@ -240,42 +241,42 @@ class FastCGIWriter (object):
def isatty (self):
"""Returns False."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
return False
def seek (self, pos, mode=0):
"""Does nothing."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
def tell (self):
"""Return zero."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
return 0
def read (self, n=-1):
"""Return empty string."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
return ""
def readline (self, length=None):
"""Return empty string."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
return ""
def readlines (self):
"""Return empty list."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
return []
def write (self, s):
"""Write data in record for record to connection."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
while s:
chunk, s = self.get_next_chunk(s)
self.record.content = chunk
@ -294,7 +295,7 @@ class FastCGIWriter (object):
def flush (self):
"""Raises ValueError if called with closed file."""
if self.closed:
raise ValueError, "I/O operation on closed file"
raise ValueError("I/O operation on closed file")
_isFCGI = 1 # assume it is until we find out for sure
@ -363,14 +364,14 @@ class FCGI (object):
if 'FCGI_WEB_SERVER_ADDRS' in os.environ:
addrs = os.environ['FCGI_WEB_SERVER_ADDRS'].split(',')
good_addrs = [ addr.strip() for addr in addrs ]
good_addrs = [addr.strip() for addr in addrs]
else:
good_addrs = None
self.conn, addr = _sock.accept()
# Check if the connection is from a legal address
if good_addrs is not None and addr not in good_addrs:
raise error, 'Connection from invalid server!'
raise error('Connection from invalid server!')
stdin = data = ""
self.env = {}
@ -429,7 +430,7 @@ class FCGI (object):
data += r.content
# end of while remaining:
self.stdin = sys.stdin = StringIO(stdin)
self.stdin = sys.stdin = StringIO(stdin)
self.data = StringIO(data)
r = Record()
r.rec_type = FCGI_STDERR

View file

@ -20,7 +20,8 @@ Python implementation of a part of Dan Bernstein's ftpparse library.
See also http://cr.yp.to/ftpparse.html
"""
months = ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
months = ("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep",
"oct", "nov", "dec")
def ismonth (txt):
"""Check if given text is a month name."""
return txt.lower() in months

View file

@ -26,6 +26,7 @@ imgtag_re = re.compile(r"(?i)\s+alt\s*=\s*"+\
r"""(?P<name>("[^"\n]*"|'[^'\n]*'|[^\s>]+))""")
img_re = re.compile(r"""(?i)<\s*img\s+("[^"\n]*"|'[^'\n]*'|[^>])+>""")
def endtag_re (tag):
"""Return matcher for given end tag"""
return re.compile(r"(?i)</%s\s*>" % tag)
@ -33,6 +34,7 @@ def endtag_re (tag):
a_end_search = endtag_re("a").search
title_end_search = endtag_re("title").search
def _unquote (txt):
"""Resolve entities and remove markup from txt."""
return HtmlParser.resolve_entities(strformat.remove_markup(txt))
@ -67,4 +69,3 @@ def title_name (txt):
return name
name = txt[:endtag.start()]
return _unquote(name)

View file

@ -67,6 +67,7 @@ css_url_re = re.compile(ur"url\(\s*(?P<url>%s)\s*\)" % _quoted_pat)
swf_url_re = re.compile("(?i)%s" % urlutil.safe_url_pattern)
c_comment_re = re.compile(ur"/\*.*?\*/", re.DOTALL)
def strip_c_comments (text):
"""Remove C/CSS-style comments from text. Note that this method also
deliberately removes comments inside of strings."""

View file

@ -113,4 +113,3 @@ def encode_multipart_formdata(fields, files=None):
def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'

View file

@ -43,6 +43,7 @@ Fields = dict(
)
del _
class Logger (object):
"""
Base class for logging of checked urls. It defines the public API

View file

@ -49,6 +49,7 @@ HTML_HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<body bgcolor="%(body)s" link="%(link)s" vlink="%(vlink)s" alink="%(alink)s">
"""
class HtmlLogger (Logger):
"""
Logger with HTML output.

View file

@ -105,7 +105,7 @@ class XMLLogger (Logger):
for name, value in attrs.items():
args = (xmlquote(name), xmlquoteattr(value))
self.write(u' %s="%s"' % args)
self.writeln(u">");
self.writeln(u">")
self.level += 1
def xml_endtag (self, name):

View file

@ -26,17 +26,17 @@ from .. import log, LOG_DNS
# IP Adress regular expressions
_ipv4_num = r"\d{1,3}"
_ipv4_num_4 = r"%s\.%s\.%s\.%s" % ((_ipv4_num,)*4)
_ipv4_num_4 = r"%s\.%s\.%s\.%s" % ((_ipv4_num,) * 4)
_ipv4_re = re.compile(r"^%s$" % _ipv4_num_4)
# see rfc2373
_ipv6_num = r"[\da-f]{1,4}"
_ipv6_re = re.compile(r"^%s:%s:%s:%s:%s:%s:%s:%s$" % ((_ipv6_num,)*8))
_ipv6_ipv4_re = re.compile(r"^%s:%s:%s:%s:%s:%s:" % ((_ipv6_num,)*6) + \
_ipv6_re = re.compile(r"^%s:%s:%s:%s:%s:%s:%s:%s$" % ((_ipv6_num,) * 8))
_ipv6_ipv4_re = re.compile(r"^%s:%s:%s:%s:%s:%s:" % ((_ipv6_num,) * 6) + \
r"%s$" % _ipv4_num_4)
_ipv6_abbr_re = re.compile(r"^((%s:){0,6}%s)?::((%s:){0,6}%s)?$" % \
((_ipv6_num,)*4))
((_ipv6_num,) * 4))
_ipv6_ipv4_abbr_re = re.compile(r"^((%s:){0,4}%s)?::((%s:){0,5})?" % \
((_ipv6_num,)*3) + \
((_ipv6_num,) * 3) + \
"%s$" % _ipv4_num_4)
# netmask regex
_host_netmask_re = re.compile(r"^%s/%s$" % (_ipv4_num_4, _ipv4_num_4))
@ -51,18 +51,18 @@ def expand_ipv6 (ip, num):
"""
i = ip.find("::")
prefix = ip[:i]
suffix = ip[i+2:]
suffix = ip[i + 2:]
count = prefix.count(":") + suffix.count(":")
if prefix:
count += 1
prefix = prefix+":"
prefix = prefix + ":"
if suffix:
count += 1
suffix = ":"+suffix
suffix = ":" + suffix
if count >= num:
raise ValueError("invalid ipv6 number: %s" % ip)
fill = (num-count-1)*"0:" + "0"
return prefix+fill+suffix
fill = (num - count - 1) * "0:" + "0"
return prefix + fill + suffix
def expand_ip (ip):
@ -137,7 +137,7 @@ def cidr2mask (n):
"""
Return a mask where the n left-most of 32 bits are set.
"""
return ((1L << n) - 1) << (32-n)
return ((1L << n) - 1) << (32 - n)
def netmask2mask (ip):
@ -146,12 +146,14 @@ def netmask2mask (ip):
"""
return dq2num(ip)
def mask2netmask (mask):
"""
Return dotted quad string as netmask.
"""
return num2dq(mask)
def dq2net (ip, mask):
"""
Return a tuple (network ip, network mask) for given ip and mask.

View file

@ -94,4 +94,3 @@ def trace_on (full=False):
def trace_off ():
"""Stop tracing of the current thread (and the current thread only)."""
sys.settrace(None)

View file

@ -41,9 +41,9 @@ PORT = 2
DOCUMENT = 3
default_ports = {
'http' : 80,
'https' : 443,
'nntps' : 563,
'http': 80,
'https': 443,
'nntps': 563,
}
# adapted from David Wheelers "Secure Programming for Linux and Unix HOWTO"

View file

@ -44,7 +44,6 @@ def _init ():
_init()
_has_app_cache = {}
def has_word ():
"""Determine if Word is available on the current system."""

View file

@ -75,6 +75,7 @@ py2exe_options = dict(
optimize=2,
)
def normpath (path):
"""Norm a path name to platform specific notation."""
return os.path.normpath(path)
@ -87,7 +88,7 @@ def cnormpath (path):
# replace slashes with backslashes
path = path.replace("/", "\\")
if not os.path.isabs(path):
path= normpath(os.path.join(sys.prefix, path))
path = normpath(os.path.join(sys.prefix, path))
return path
@ -182,7 +183,6 @@ class MyDistribution (Distribution, object):
"icon_resources": [(1, "doc/html/favicon.ico")],
}]
def run_commands (self):
"""Generate config file and run commands."""
cwd = os.getcwd()
@ -221,7 +221,7 @@ class MyDistribution (Distribution, object):
# write the config file
data.append('appname = "LinkChecker"')
util.execute(write_file, (filename, data),
"creating %s" % filename, self.verbose>=1, self.dry_run)
"creating %s" % filename, self.verbose >= 1, self.dry_run)
def cc_run (args):
@ -303,7 +303,7 @@ def check_manifest ():
if err:
n = len(manifest)
print '\n*** SOURCE WARNING: There are files missing (%d/%d found)!'%(
n-len(err), n)
n - len(err), n)
print 'Missing:', '\nMissing: '.join(err)
@ -398,10 +398,11 @@ if os.name == 'posix':
['config/linkchecker-completion',
'doc/examples/check_blacklist.sh',
'doc/examples/check_for_x_errors.sh',
'doc/examples/check_urls.sh',]))
'doc/examples/check_urls.sh']))
class InnoScript:
def __init__(self, lib_dir, dist_dir, windows_exe_files=[],
console_exe_files=[], service_exe_files=[],
comserver_files=[], lib_files=[]):
@ -456,10 +457,11 @@ class InnoScript:
res = ctypes.windll.shell32.ShellExecuteA(0, "compile",
self.pathname, None, None, 0)
if res < 32:
raise RuntimeError, "ShellExecute failed, error %d" % res
raise RuntimeError("ShellExecute failed, error %d" % res)
try:
from py2exe.build_exe import py2exe as py2exe_build
class MyPy2exe (py2exe_build):
"""First builds the exe file(s), then creates a Windows installer.
You need InnoSetup for it."""
@ -485,7 +487,8 @@ try:
print "*** compiling the inno setup script***"
script.compile()
except ImportError:
class MyPy2exe: pass
class MyPy2exe:
pass
class MyRegister (register, object):
@ -557,7 +560,7 @@ o a (Fast)CGI web interface (requires HTTP server)
include_dirs = include_dirs + [normpath("linkcheck/HtmlParser")],
),
Extension("linkcheck.network._network",
sources = ["linkcheck/network/_network.c",],
sources = ["linkcheck/network/_network.c"],
extra_compile_args = extra_compile_args,
library_dirs = library_dirs,
libraries = libraries,

View file

@ -183,6 +183,7 @@ def has_pyqt ():
need_pyqt = _need_func(has_pyqt, "PyQT")
@contextmanager
def _limit_time (seconds):
"""Raises LinkCheckerInterrupt if given number of seconds have passed."""

View file

@ -32,6 +32,7 @@ import linkcheck.i18n
# helper alias
get_url_from = linkcheck.checker.get_url_from
class TestLogger (linkcheck.logger.Logger):
"""
Output logger for automatic regression tests.

View file

@ -57,6 +57,7 @@ class FtpServerTest (LinkCheckTest):
def start_server (host, port):
def line_logger(msg):
if "kill" in msg:
sys.exit(0)

View file

@ -5,9 +5,9 @@ Test container routines.
import unittest
import os
import linkcheck.fcgi
class TestFcgi (unittest.TestCase):
"""
Test FastCGI request parsing routines.

View file

@ -73,7 +73,7 @@ class TestFile (LinkCheckTest):
return
dirname = get_file("dir")
if not os.path.isdir(dirname):
unzip(dirname+".zip", os.path.dirname(dirname))
unzip(dirname + ".zip", os.path.dirname(dirname))
self.file_test("dir")
def test_unicode_filename (self):

View file

@ -178,6 +178,7 @@ class CookieRedirectHttpRequestHandler (NoQueryHttpRequestHandler):
else:
super(CookieRedirectHttpRequestHandler, self).do_HEAD()
class RedirectHttpsRequestHandler (CookieRedirectHttpRequestHandler):
def redirect (self):

View file

@ -21,7 +21,6 @@ from tests import need_network
from . import LinkCheckTest
class TestMail (LinkCheckTest):
"""
Test mailto: link checking.

View file

@ -51,9 +51,9 @@ class TestConfig (unittest.TestCase):
for prefix1 in ("ignore_", "nofollow_"):
for prefix2 in ("", "old"):
for suffix in ("1", "2"):
key = "%s%simadoofus%s" % (prefix1, prefix2, suffix)
key = "%s%simadoofus%s" % (prefix1, prefix2, suffix)
self.assertTrue(key in patterns)
for key in ("url-unnormed","url-unicode-domain","anchor-not-found"):
for key in ("url-unnormed", "url-unicode-domain", "anchor-not-found"):
self.assertTrue(key in config["ignorewarnings"])
# authentication section
patterns = [x["pattern"].pattern for x in config["authentication"]]

View file

@ -24,11 +24,11 @@ class TestCsvLogger (unittest.TestCase):
def test_parts (self):
args = dict(
filename = os.path.join(os.path.dirname(__file__), "testlog.csv"),
parts = ["realurl"],
fileoutput = 1,
separator = ";",
quotechar = '"',
filename=os.path.join(os.path.dirname(__file__), "testlog.csv"),
parts=["realurl"],
fileoutput=1,
separator=";",
quotechar='"',
)
logger = CSVLogger(**args)
try:

View file

@ -33,7 +33,7 @@ class TestClamav (unittest.TestCase):
@need_clamav
def testInfected (self):
data = '<object data="&#109;s-its:mhtml:file://'+ \
data = '<object data="&#109;s-its:mhtml:file://' + \
'C:\\foo.mht!${PATH}/' + \
'EXPLOIT.CHM::' + \
'/exploit.htm">'

View file

@ -78,6 +78,7 @@ patterns = (
("", None),
)
class TestFtpparse (unittest.TestCase):
"""
Test FTP LIST line parsing.

View file

@ -18,6 +18,7 @@ import unittest
import sys
from tests import need_pyqt
class TestGui (unittest.TestCase):
"""Test OMT GUI client."""

View file

@ -267,11 +267,14 @@ class TestParser (unittest.TestCase):
def test_peek (self):
# Test peek() parser function
data = '<a href="test.html">name</a>'
class NamePeeker (object):
def start_element (self_handler, tag, attrs):
# use self reference of TestParser instance
self.assertRaises(TypeError, self.htmlparser.peek, -1)
self.assertEqual(self.htmlparser.peek(0), "")
self.assertEqual(self.htmlparser.peek(4), "name")
self.htmlparser.handler = NamePeeker()
self.htmlparser.feed(data)

View file

@ -26,6 +26,7 @@ from tests import need_msgfmt, need_posix
pofiles = None
def get_pofiles ():
"""Find all .po files in this source."""
global pofiles
@ -35,6 +36,7 @@ def get_pofiles ():
pofiles.extend(glob.glob("doc/*.po"))
return pofiles
class TestPo (unittest.TestCase):
"""Test .po file syntax."""

View file

@ -166,8 +166,8 @@ class TestRobotsTxt (unittest.TestCase):
]
self.rp.parse(lines)
self.assertEqual(str(self.rp), "\n".join(lines2))
good = ['/','/test.html']
bad = ['/cyberworld/map/index.html','/tmp/xxx','/foo.html']
good = ['/', '/test.html']
bad = ['/cyberworld/map/index.html', '/tmp/xxx', '/foo.html']
self.check_urls(good, bad)
def test_access2 (self):
@ -191,7 +191,7 @@ class TestRobotsTxt (unittest.TestCase):
]
self.rp.parse(lines)
self.assertEqual(str(self.rp), "\n".join(lines2))
good = ['/','/test.html',('cybermapper','/cyberworld/map/index.html')]
good = ['/', '/test.html', ('cybermapper', '/cyberworld/map/index.html')]
bad = ['/cyberworld/map/index.html']
self.check_urls(good, bad)
@ -208,7 +208,7 @@ class TestRobotsTxt (unittest.TestCase):
self.rp.parse(lines)
self.assertEqual(str(self.rp), "\n".join(lines2))
good = []
bad = ['/cyberworld/map/index.html','/','/tmp/']
bad = ['/cyberworld/map/index.html', '/', '/tmp/']
self.check_urls(good, bad)
def test_access4 (self):
@ -229,8 +229,8 @@ class TestRobotsTxt (unittest.TestCase):
self.rp.parse(lines)
self.assertEqual(str(self.rp), "\n".join(lines2))
good = []
bad = ['/tmp','/tmp.html','/tmp/a.html',
'/a%3cd.html','/a%3Cd.html','/a%2fb.html',
bad = ['/tmp', '/tmp.html', '/tmp/a.html',
'/a%3cd.html', '/a%3Cd.html', '/a%2fb.html',
'/~joe/index.html', '/a/b.html',
]
self.check_urls(good, bad, 'figtree')
@ -253,9 +253,9 @@ class TestRobotsTxt (unittest.TestCase):
]
self.rp.parse(lines)
self.assertEqual(str(self.rp), "\n".join(lines2))
good = ['/tmp',] # XFAIL: '/a%2fb.html'
bad = ['/tmp/','/tmp/a.html',
'/a%3cd.html','/a%3Cd.html',"/a/b.html",
good = ['/tmp'] # XFAIL: '/a%2fb.html'
bad = ['/tmp/', '/tmp/a.html',
'/a%3cd.html', '/a%3Cd.html', "/a/b.html",
'/%7Ejoe/index.html']
self.check_urls(good, bad)
@ -290,4 +290,3 @@ class TestRobotsTxt (unittest.TestCase):
self.check_url("spam", "/cgi-bin/foo/bar", False)
self.check_url("spam", "/cgi-bin?a=1", False)
self.check_url("spam", "/", True)

View file

@ -72,7 +72,6 @@ class TestStrFormat (unittest.TestCase):
self.assertEqual(wrap(None, 10), None)
self.assertFalse(linkcheck.strformat.get_paragraphs(None))
def test_remove_markup (self):
# Test markup removing.
self.assertEqual(linkcheck.strformat.remove_markup("<a>"), "")

View file

@ -94,7 +94,6 @@ class TestUrl (unittest.TestCase):
url2 = "bcd?a=b"
self.assertEqual(url_quote(url), url2)
def test_norm_quote (self):
# Test url norm quoting.
url = "http://groups.google.com/groups?hl=en&lr&ie=UTF-8&"\
@ -129,10 +128,10 @@ class TestUrl (unittest.TestCase):
nurl = "http://example.com/#a%20b"
self.urlnormtest(url, nurl)
url = "http://example.com/?u=http://example2.com?b=c "
nurl ="http://example.com/?u=http://example2.com?b=c%20"
nurl = "http://example.com/?u=http://example2.com?b=c%20"
self.urlnormtest(url, nurl)
url = "http://example.com/?u=http://example2.com?b="
nurl ="http://example.com/?u=http://example2.com?b="
nurl = "http://example.com/?u=http://example2.com?b="
self.urlnormtest(url, nurl)
url = "http://localhost:8001/?quoted=ü"
nurl = "http://localhost:8001/?quoted=%FC"
@ -480,7 +479,7 @@ class TestUrl (unittest.TestCase):
def test_idn_encoding (self):
# Test idna encoding.
url = u'www.öko.de'
idna_encode =linkcheck.url.idna_encode
idna_encode = linkcheck.url.idna_encode
encurl, is_idn = idna_encode(url)
self.assertTrue(is_idn)
self.assertTrue(encurl)

View file

@ -23,6 +23,7 @@ import linkcheck.configuration
import linkcheck.director
import linkcheck.checker.httpurl
def get_test_aggregate ():
"""
Initialize a test configuration object.