Code cleanup.

This commit is contained in:
Bastian Kleineidam 2012-09-23 16:19:42 +02:00
parent 1e1370fbb4
commit 38dd63f055
3 changed files with 20 additions and 19 deletions

View file

@ -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

View file

@ -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)

View file

@ -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