qutebrowser: Fix bare redirect exception
This commit is contained in:
parent
a16e0eead7
commit
337b250aba
1 changed files with 6 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
from qutebrowser.api import interceptor
|
from qutebrowser.api import interceptor
|
||||||
|
from qutebrowser.extensions.interceptors import RedirectException
|
||||||
|
|
||||||
redirects = {
|
redirects = {
|
||||||
"youtube": {
|
"youtube": {
|
||||||
|
@ -184,6 +185,7 @@ redirects = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def rewrite(request: interceptor.Request):
|
def rewrite(request: interceptor.Request):
|
||||||
if (
|
if (
|
||||||
request.resource_type != interceptor.ResourceType.main_frame
|
request.resource_type != interceptor.ResourceType.main_frame
|
||||||
|
@ -194,17 +196,17 @@ def rewrite(request: interceptor.Request):
|
||||||
url = request.request_url
|
url = request.request_url
|
||||||
|
|
||||||
for service in redirects.values():
|
for service in redirects.values():
|
||||||
matched=False
|
matched = False
|
||||||
for source in service["source"]:
|
for source in service["source"]:
|
||||||
if re.search(source, url.host()):
|
if re.search(source, url.host()):
|
||||||
matched=True
|
matched = True
|
||||||
|
|
||||||
if matched:
|
if matched:
|
||||||
target = service["target"][random.randint(0, len(service["target"])-1)]
|
target = service["target"][random.randint(0, len(service["target"]) - 1)]
|
||||||
if target is not None and url.setHost(target) is not False:
|
if target is not None and url.setHost(target) is not False:
|
||||||
try:
|
try:
|
||||||
request.redirect(url)
|
request.redirect(url)
|
||||||
except:
|
except RedirectException:
|
||||||
pass
|
pass
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue