Skip to content

Commit

Permalink
Export HTTPMove (#6594)
Browse files Browse the repository at this point in the history
Nitpick: If you catch `HTTPRedirection` then mypy complains that it
doesn't have a `location` attribute (this is used in
aiohttp-debugtoolbar, for example).

Proposal to export `HTTPMove`, in order to catch any exceptions with
location.

(cherry picked from commit a5d6418)
  • Loading branch information
Dreamsorcerer committed May 14, 2023
1 parent 44b8fd4 commit 9e2b658
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES/6594.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Exported ``HTTPMove`` which can be used to catch any redirection request
that has a location -- :user:`dreamsorcerer`.
2 changes: 2 additions & 0 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
HTTPLengthRequired as HTTPLengthRequired,
HTTPMethodNotAllowed as HTTPMethodNotAllowed,
HTTPMisdirectedRequest as HTTPMisdirectedRequest,
HTTPMove as HTTPMove,
HTTPMovedPermanently as HTTPMovedPermanently,
HTTPMultipleChoices as HTTPMultipleChoices,
HTTPNetworkAuthenticationRequired as HTTPNetworkAuthenticationRequired,
Expand Down Expand Up @@ -177,6 +178,7 @@
"HTTPLengthRequired",
"HTTPMethodNotAllowed",
"HTTPMisdirectedRequest",
"HTTPMove",
"HTTPMovedPermanently",
"HTTPMultipleChoices",
"HTTPNetworkAuthenticationRequired",
Expand Down
17 changes: 9 additions & 8 deletions aiohttp/web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"HTTPNoContent",
"HTTPResetContent",
"HTTPPartialContent",
"HTTPMove",
"HTTPMultipleChoices",
"HTTPMovedPermanently",
"HTTPFound",
Expand Down Expand Up @@ -160,7 +161,7 @@ class HTTPPartialContent(HTTPSuccessful):
############################################################


class _HTTPMove(HTTPRedirection):
class HTTPMove(HTTPRedirection):
def __init__(
self,
location: StrOrURL,
Expand All @@ -184,21 +185,21 @@ def __init__(
self.location = location


class HTTPMultipleChoices(_HTTPMove):
class HTTPMultipleChoices(HTTPMove):
status_code = 300


class HTTPMovedPermanently(_HTTPMove):
class HTTPMovedPermanently(HTTPMove):
status_code = 301


class HTTPFound(_HTTPMove):
class HTTPFound(HTTPMove):
status_code = 302


# This one is safe after a POST (the redirected location will be
# retrieved with GET):
class HTTPSeeOther(_HTTPMove):
class HTTPSeeOther(HTTPMove):
status_code = 303


Expand All @@ -208,16 +209,16 @@ class HTTPNotModified(HTTPRedirection):
empty_body = True


class HTTPUseProxy(_HTTPMove):
class HTTPUseProxy(HTTPMove):
# Not a move, but looks a little like one
status_code = 305


class HTTPTemporaryRedirect(_HTTPMove):
class HTTPTemporaryRedirect(HTTPMove):
status_code = 307


class HTTPPermanentRedirect(_HTTPMove):
class HTTPPermanentRedirect(HTTPMove):
status_code = 308


Expand Down

0 comments on commit 9e2b658

Please sign in to comment.