Skip to content

Commit 4a1a3a1

Browse files
committed
Added option to pass status to HTTPResponse as tuple, overwrited eq method on HTTPStatus
1 parent 85d1c3c commit 4a1a3a1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

adafruit_httpserver/response.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99

1010
try:
11-
from typing import Optional, Dict, Union
11+
from typing import Optional, Dict, Union, Tuple
1212
from socket import socket
1313
from socketpool import SocketPool
1414
except ImportError:
@@ -37,7 +37,7 @@ class HTTPResponse:
3737

3838
def __init__( # pylint: disable=too-many-arguments
3939
self,
40-
status: HTTPStatus = CommonHTTPStatus.OK_200,
40+
status: Union[HTTPStatus, Tuple[int, str]] = CommonHTTPStatus.OK_200,
4141
body: str = "",
4242
headers: Dict[str, str] = None,
4343
content_type: str = MIMEType.TYPE_TXT,
@@ -50,8 +50,7 @@ def __init__( # pylint: disable=too-many-arguments
5050
5151
Returns ``body`` if ``filename`` is ``None``, otherwise returns contents of ``filename``.
5252
"""
53-
54-
self.status = status
53+
self.status = status if isinstance(status, HTTPStatus) else HTTPStatus(*status)
5554
self.body = body
5655
self.headers = headers or {}
5756
self.content_type = content_type

adafruit_httpserver/status.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def __repr__(self):
2626
def __str__(self):
2727
return f"{self.code} {self.text}"
2828

29+
def __eq__(self, other: "HTTPStatus"):
30+
return self.code == other.code and self.text == other.text
31+
2932

3033
class CommonHTTPStatus(HTTPStatus): # pylint: disable=too-few-public-methods
3134
"""Common HTTP status codes."""

0 commit comments

Comments
 (0)