mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-29 18:44:43 +00:00
Code cleanup.
This commit is contained in:
parent
1e1370fbb4
commit
38dd63f055
3 changed files with 20 additions and 19 deletions
|
|
@ -27,6 +27,23 @@ from .. import strformat, url as urlutil, log, LOG_CHECK
|
|||
MAX_FILESIZE = 1024*1024*10 # 10MB
|
||||
|
||||
|
||||
def guess_url(url):
|
||||
"""Guess if URL is a http or ftp URL.
|
||||
@param url: the URL to check
|
||||
@ptype url: unicode
|
||||
@return: url with http:// or ftp:// prepended if it's detected as
|
||||
a http respective ftp URL.
|
||||
@rtype: unicode
|
||||
"""
|
||||
if url.lower().startswith("www."):
|
||||
# syntactic sugar
|
||||
return "http://%s" % url
|
||||
elif url.lower().startswith("ftp."):
|
||||
# syntactic sugar
|
||||
return "ftp://%s" % url
|
||||
return url
|
||||
|
||||
|
||||
def absolute_url (base_url, base_ref, parent_url):
|
||||
"""
|
||||
Search for the absolute url to detect the link type. This does not
|
||||
|
|
|
|||
|
|
@ -115,11 +115,6 @@ class LCOptionParser (optparse.OptionParser, object):
|
|||
def aggregate_url (aggregate, url, err_exit_code=2):
|
||||
"""Append given commandline URL to input queue."""
|
||||
get_url_from = checker.get_url_from
|
||||
if url.lower().startswith("www."):
|
||||
# syntactic sugar
|
||||
url = "http://%s" % url
|
||||
elif url.lower().startswith("ftp."):
|
||||
# syntactic sugar
|
||||
url = "ftp://%s" % url
|
||||
url = checker.guess_url(url)
|
||||
url_data = get_url_from(url, 0, aggregate, extern=(0, 0))
|
||||
aggregate.urlqueue.put(url_data)
|
||||
|
|
|
|||
|
|
@ -436,11 +436,8 @@ Version 2 or later.
|
|||
def get_url (self):
|
||||
"""Return URL to check from the urlinput widget."""
|
||||
url = strformat.stripurl(unicode(self.urlinput.text()))
|
||||
if url.startswith(u"www."):
|
||||
url = u"http://%s" % url
|
||||
elif url.startswith(u"ftp."):
|
||||
url = u"ftp://%s" % url
|
||||
elif url and u":" not in url:
|
||||
url = checker.guess_url(url)
|
||||
if url and u":" not in url:
|
||||
# Look for local file, else assume it's an HTTP URL.
|
||||
if not os.path.exists(url):
|
||||
url = u"http://%s" % url
|
||||
|
|
@ -459,14 +456,6 @@ Version 2 or later.
|
|||
return
|
||||
self.set_statusmsg(_("Checking '%s'.") % strformat.limit(url, 40))
|
||||
url_data = checker.get_url_from(url, 0, aggregate, extern=(0, 0))
|
||||
# XXX
|
||||
#try:
|
||||
# self.backup_config('internlinks')
|
||||
# add_intern_pattern(url_data, self.config)
|
||||
#except UnicodeError:
|
||||
# self.set_statusmsg(_("Error, invalid URL `%s'.") %
|
||||
# strformat.limit(url, 40))
|
||||
# return
|
||||
self.recent.add_document(url)
|
||||
aggregate.urlqueue.put(url_data)
|
||||
self.aggregate = aggregate
|
||||
|
|
|
|||
Loading…
Reference in a new issue