Skip to content

Commit b88bfa5

Browse files
committed
Changes in repr of multiple classes
1 parent f7d20b5 commit b88bfa5

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

adafruit_httpserver/interfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def __contains__(self, key: str) -> bool:
121121
return key in self._storage
122122

123123
def __repr__(self) -> str:
124-
return f"{self.__class__.__name__}({repr(self._storage)})"
124+
return f"<{self.__class__.__name__} {repr(self._storage)}>"
125125

126126

127127
def _encode_html_entities(value: Union[str, None]) -> Union[str, None]:

adafruit_httpserver/request.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ def size(self) -> int:
125125

126126
def __repr__(self) -> str:
127127
filename, content_type, size = (
128-
repr(self.filename),
129-
repr(self.content_type),
130-
repr(self.size),
128+
self.filename,
129+
self.content_type,
130+
self.size,
131131
)
132-
return f"{self.__class__.__name__}({filename=}, {content_type=}, {size=})"
132+
return f"<{self.__class__.__name__} {filename=}, {content_type=}, {size=}>"
133133

134134

135135
class Files(_IFieldStorage):
@@ -258,7 +258,9 @@ def get_list(self, field_name: str, *, safe=True) -> List[Union[str, bytes]]:
258258

259259
def __repr__(self) -> str:
260260
class_name = self.__class__.__name__
261-
return f"{class_name}({repr(self._storage)}, files={repr(self.files._storage)})"
261+
return (
262+
f"<{class_name} {repr(self._storage)}, files={repr(self.files._storage)}>"
263+
)
262264

263265

264266
class Request: # pylint: disable=too-many-instance-attributes
@@ -479,6 +481,10 @@ def _parse_request_header(
479481

480482
return method, path, query_params, http_version, headers
481483

484+
def __repr__(self) -> str:
485+
path = self.path + (f"?{self.query_params}" if self.query_params else "")
486+
return f'<{self.__class__.__name__} "{self.method} {path}">'
487+
482488

483489
def _debug_unsupported_form_content_type(content_type: str) -> None:
484490
"""Warns when an unsupported form content type is used."""

adafruit_httpserver/route.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ def matches(
136136
return True, dict(zip(self.parameters_names, url_parameters_values))
137137

138138
def __repr__(self) -> str:
139-
path = repr(self.path)
140-
methods = repr(self.methods)
141-
handler = repr(self.handler)
139+
path = self.path
140+
methods = self.methods
141+
handler = self.handler
142142

143-
return f"Route({path=}, {methods=}, {handler=})"
143+
return f"<Route {path=}, {methods=}, {handler=}>"
144144

145145

146146
def as_route(

adafruit_httpserver/server.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,13 @@ def socket_timeout(self, value: int) -> None:
528528
else:
529529
raise ValueError("Server.socket_timeout must be a positive numeric value.")
530530

531+
def __repr__(self) -> str:
532+
host = self.host
533+
port = self.port
534+
root_path = self.root_path
535+
536+
return f"<Server {host=}, {port=}, {root_path=}>"
537+
531538

532539
def _debug_warning_exposed_files(root_path: str):
533540
"""Warns about exposing all files on the device."""

adafruit_httpserver/status.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ def __init__(self, code: int, text: str):
2121
self.code = code
2222
self.text = text
2323

24-
def __repr__(self):
25-
return f'Status({self.code}, "{self.text}")'
24+
def __eq__(self, other: "Status"):
25+
return self.code == other.code and self.text == other.text
2626

2727
def __str__(self):
2828
return f"{self.code} {self.text}"
2929

30-
def __eq__(self, other: "Status"):
31-
return self.code == other.code and self.text == other.text
30+
def __repr__(self):
31+
code = self.code
32+
text = self.text
33+
34+
return f'<Status {code}, "{text}">'
3235

3336

3437
SWITCHING_PROTOCOLS_101 = Status(101, "Switching Protocols")

0 commit comments

Comments
 (0)