|
| 1 | +from typing import Any, Dict, List, Optional # noqa |
| 2 | + |
| 3 | +from .typedefs import LooseHeaders, StrOrURL |
1 | 4 | from .web_response import Response |
2 | 5 |
|
3 | 6 |
|
@@ -76,16 +79,20 @@ class HTTPException(Response, Exception): |
76 | 79 |
|
77 | 80 | __http_exception__ = True |
78 | 81 |
|
79 | | - def __init__(self, *, headers=None, reason=None, |
80 | | - body=None, text=None, content_type=None): |
| 82 | + def __init__(self, *, |
| 83 | + headers: Optional[LooseHeaders]=None, |
| 84 | + reason: Optional[str]=None, |
| 85 | + body: Any=None, |
| 86 | + text: Optional[str]=None, |
| 87 | + content_type: Optional[str]=None) -> None: |
81 | 88 | Response.__init__(self, status=self.status_code, |
82 | 89 | headers=headers, reason=reason, |
83 | 90 | body=body, text=text, content_type=content_type) |
84 | 91 | Exception.__init__(self, self.reason) |
85 | 92 | if self.body is None and not self.empty_body: |
86 | 93 | self.text = "{}: {}".format(self.status, self.reason) |
87 | 94 |
|
88 | | - def __bool__(self): |
| 95 | + def __bool__(self) -> bool: |
89 | 96 | return True |
90 | 97 |
|
91 | 98 |
|
@@ -138,8 +145,14 @@ class HTTPPartialContent(HTTPSuccessful): |
138 | 145 |
|
139 | 146 | class _HTTPMove(HTTPRedirection): |
140 | 147 |
|
141 | | - def __init__(self, location, *, headers=None, reason=None, |
142 | | - body=None, text=None, content_type=None): |
| 148 | + def __init__(self, |
| 149 | + location: StrOrURL, |
| 150 | + *, |
| 151 | + headers: Optional[LooseHeaders]=None, |
| 152 | + reason: Optional[str]=None, |
| 153 | + body: Any=None, |
| 154 | + text: Optional[str]=None, |
| 155 | + content_type: Optional[str]=None) -> None: |
143 | 156 | if not location: |
144 | 157 | raise ValueError("HTTP redirects need a location to redirect to.") |
145 | 158 | super().__init__(headers=headers, reason=reason, |
@@ -217,8 +230,15 @@ class HTTPNotFound(HTTPClientError): |
217 | 230 | class HTTPMethodNotAllowed(HTTPClientError): |
218 | 231 | status_code = 405 |
219 | 232 |
|
220 | | - def __init__(self, method, allowed_methods, *, headers=None, reason=None, |
221 | | - body=None, text=None, content_type=None): |
| 233 | + def __init__(self, |
| 234 | + method: str, |
| 235 | + allowed_methods: List[str], |
| 236 | + *, |
| 237 | + headers: Optional[LooseHeaders]=None, |
| 238 | + reason: Optional[str]=None, |
| 239 | + body: Any=None, |
| 240 | + text: Optional[str]=None, |
| 241 | + content_type: Optional[str]=None) -> None: |
222 | 242 | allow = ','.join(sorted(allowed_methods)) |
223 | 243 | super().__init__(headers=headers, reason=reason, |
224 | 244 | body=body, text=text, content_type=content_type) |
@@ -258,7 +278,10 @@ class HTTPPreconditionFailed(HTTPClientError): |
258 | 278 | class HTTPRequestEntityTooLarge(HTTPClientError): |
259 | 279 | status_code = 413 |
260 | 280 |
|
261 | | - def __init__(self, max_size, actual_size, **kwargs): |
| 281 | + def __init__(self, |
| 282 | + max_size: float, |
| 283 | + actual_size: float, |
| 284 | + **kwargs: Any) -> None: |
262 | 285 | kwargs.setdefault( |
263 | 286 | 'text', |
264 | 287 | 'Maximum request body size {} exceeded, ' |
@@ -314,8 +337,14 @@ class HTTPRequestHeaderFieldsTooLarge(HTTPClientError): |
314 | 337 | class HTTPUnavailableForLegalReasons(HTTPClientError): |
315 | 338 | status_code = 451 |
316 | 339 |
|
317 | | - def __init__(self, link, *, headers=None, reason=None, |
318 | | - body=None, text=None, content_type=None): |
| 340 | + def __init__(self, |
| 341 | + link: str, |
| 342 | + *, |
| 343 | + headers: Optional[LooseHeaders]=None, |
| 344 | + reason: Optional[str]=None, |
| 345 | + body: Any=None, |
| 346 | + text: Optional[str]=None, |
| 347 | + content_type: Optional[str]=None) -> None: |
319 | 348 | super().__init__(headers=headers, reason=reason, |
320 | 349 | body=body, text=text, content_type=content_type) |
321 | 350 | self.headers['Link'] = '<%s>; rel="blocked-by"' % link |
|
0 commit comments