Better URL detection

This commit is contained in:
Florian Bruhin 2014-05-03 00:20:01 +02:00
parent a5c5910b25
commit f7fa315890
2 changed files with 13 additions and 5 deletions

1
TODO
View File

@ -46,7 +46,6 @@ catch import errors for PyQt and QtWebKit
elem = frame.findFirstElement('*:focus') elem = frame.findFirstElement('*:focus')
somehow unfocus elements (hide blinking cursor) when insert mode is left? somehow unfocus elements (hide blinking cursor) when insert mode is left?
tabs: some more padding? tabs: some more padding?
localhost:8080 opens searchresults
exec command for shell exec command for shell
custom stylesheet custom stylesheet
Alt+N to focus tab N Alt+N to focus tab N

View File

@ -70,9 +70,18 @@ def _is_url_naive(url):
True if the url really is an URL, False otherwise. True if the url really is an URL, False otherwise.
""" """
protocols = ['http://', 'https://'] protocols = ['http://', 'https://']
u = urlstring(url) if isinstance(url, QUrl):
return (any(u.startswith(proto) for proto in protocols) or '.' in u or u = url
u == 'localhost') else:
u = QUrl.fromUserInput(url)
if u.scheme() in protocols:
return True
elif '.' in u.host():
return True
elif u.host() == 'localhost':
return True
else:
return False
def _is_url_dns(url): def _is_url_dns(url):
@ -127,7 +136,7 @@ def fuzzy_url(url):
""" """
u = qurl(url) u = qurl(url)
urlstr = urlstring(url) urlstr = urlstring(url)
if is_url(u): if is_url(urlstr):
# probably an address # probably an address
logging.debug("url is a fuzzy address") logging.debug("url is a fuzzy address")
newurl = QUrl.fromUserInput(urlstr) newurl = QUrl.fromUserInput(urlstr)