summaryrefslogtreecommitdiff
path: root/qutebrowser/extensions
diff options
context:
space:
mode:
authorJay Kamat <jaygkamat@gmail.com>2019-04-03 22:22:29 -0700
committerJay Kamat <jaygkamat@gmail.com>2019-04-21 12:02:40 -0700
commit82f1e3e0dd6309ec4169e6019ba008a7145786a4 (patch)
treee2bee9c254bb53acb1ccea1a00185cc21e6b19b3 /qutebrowser/extensions
parent9b69a9315fa79e925128cd7b981cabf42bda18a1 (diff)
downloadqutebrowser-82f1e3e0dd6309ec4169e6019ba008a7145786a4.tar.gz
qutebrowser-82f1e3e0dd6309ec4169e6019ba008a7145786a4.zip
Refactor redirection methods to use class overrides
Diffstat (limited to 'qutebrowser/extensions')
-rw-r--r--qutebrowser/extensions/interceptors.py34
1 files changed, 18 insertions, 16 deletions
diff --git a/qutebrowser/extensions/interceptors.py b/qutebrowser/extensions/interceptors.py
index fa47970ae..c2a657381 100644
--- a/qutebrowser/extensions/interceptors.py
+++ b/qutebrowser/extensions/interceptors.py
@@ -55,6 +55,18 @@ class ResourceType(enum.Enum):
unknown = 255
+class RedirectException(Exception):
+ """Raised when there was an error with redirection."""
+
+
+class RedirectFailedException(RedirectException):
+ """Raised when the request was invalid, or a request was already made."""
+
+
+class RedirectUnsupportedException(RedirectException):
+ """Raised when redirection is currently unsupported."""
+
+
@attr.s
class Request:
@@ -71,35 +83,25 @@ class Request:
#: The resource type of the request. None if not supported on this backend.
resource_type = attr.ib(None) # type: typing.Optional[ResourceType]
- #: Private attribute to a method which implements redirection
- _redirect_method = attr.ib(
- default=None, type=typing.Optional[typing.Callable[[QUrl], bool]])
-
def block(self) -> None:
"""Block this request."""
self.is_blocked = True
- def redirect(self, url: QUrl) -> bool:
+ def redirect(self, url: QUrl) -> None:
"""Redirect this request.
Only some types of requests can be successfully redirected.
Improper use of this method can result in redirect loops.
+ This method will throw a RedirectFailedException if the request was not
+ possible.
+
Args:
url: The QUrl to try to redirect to.
- Return:
- False if the redirection was known to be unsupported, else True.
- A True return value does not guarantee success.
"""
- if self._redirect_method is None:
- return False
- # pylint: disable=not-callable
- retval = self._redirect_method(url)
- # pylint: enable=not-callable
- # Once firing a redirect, refuse any other attempt
- self._redirect_method = None
- return retval
+ # Will be overridden if the backend supports redirection
+ raise RedirectUnsupportedException("Unsupported backend.")
#: Type annotation for an interceptor function.