Refactor DisableRedirectHandler
This commit is contained in:
parent
47e42a46c1
commit
0baf1dc908
@ -28,7 +28,8 @@ import sys
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from configparser import RawConfigParser
|
from configparser import RawConfigParser
|
||||||
from typing import Callable, Dict, NoReturn, Optional, Tuple, cast
|
from http.client import HTTPMessage
|
||||||
|
from typing import IO, Callable, Dict, Optional, Tuple, cast
|
||||||
from urllib import request
|
from urllib import request
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
|
|
||||||
@ -40,26 +41,10 @@ from radicale.tests.helpers import configuration_to_dict, get_file_path
|
|||||||
|
|
||||||
|
|
||||||
class DisabledRedirectHandler(request.HTTPRedirectHandler):
|
class DisabledRedirectHandler(request.HTTPRedirectHandler):
|
||||||
|
def redirect_request(
|
||||||
# HACK: typeshed annotation are wrong for `fp` and `msg`
|
self, req: request.Request, fp: IO[bytes], code: int, msg: str,
|
||||||
# (https://github.com/python/typeshed/pull/5728)
|
headers: HTTPMessage, newurl: str) -> None:
|
||||||
# `headers` is incompatible with `http.client.HTTPMessage`
|
return None
|
||||||
# (https://github.com/python/typeshed/issues/5729)
|
|
||||||
def http_error_301(self, req: request.Request, fp, code: int,
|
|
||||||
msg, headers) -> NoReturn:
|
|
||||||
raise HTTPError(req.full_url, code, msg, headers, fp)
|
|
||||||
|
|
||||||
def http_error_302(self, req: request.Request, fp, code: int,
|
|
||||||
msg, headers) -> NoReturn:
|
|
||||||
raise HTTPError(req.full_url, code, msg, headers, fp)
|
|
||||||
|
|
||||||
def http_error_303(self, req: request.Request, fp, code: int,
|
|
||||||
msg, headers) -> NoReturn:
|
|
||||||
raise HTTPError(req.full_url, code, msg, headers, fp)
|
|
||||||
|
|
||||||
def http_error_307(self, req: request.Request, fp, code: int,
|
|
||||||
msg, headers) -> NoReturn:
|
|
||||||
raise HTTPError(req.full_url, code, msg, headers, fp)
|
|
||||||
|
|
||||||
|
|
||||||
class TestBaseServerRequests(BaseTest):
|
class TestBaseServerRequests(BaseTest):
|
||||||
|
Loading…
Reference in New Issue
Block a user