We also provide no exception handling for failed reads here...
Suggestions
Adding some sort of NamedTuple that contains the response content along with its headers, encoding, etc.
class FileResponse(NamedTuple):
content: bytes
encoding: Optional[str] # easier access than through header
content_type: Optional[str] # easier access than through header
headers: Dict[str, Any]
def __bytes__(self) -> bytes:
return self.contents
This will break the API of methods currently using get_file(). However, with the __bytes__ method implemented on the class, passing the tuple to bytes() will return only the file contents. Thus existing invocations will either have to explicitly access resp.content or do bytes(resp).
In addition to the response body, we should probably return the headers from the response, so clients know how to process the data if they want to.
https://github.com/pederhan/harborapi/blob/1b1a25089b6040dca1057fa1fcd57f02bfc4e8dd/harborapi/client.py#L4516-L4520
We also provide no exception handling for failed reads here...
Suggestions
Adding some sort of NamedTuple that contains the response content along with its headers, encoding, etc.
This will break the API of methods currently using
get_file()
. However, with the__bytes__
method implemented on the class, passing the tuple tobytes()
will return only the file contents. Thus existing invocations will either have to explicitly accessresp.content
or dobytes(resp)
.