From 376fff2e4e6c640a616b5f4609b4162178e47f2a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 1 Jul 2024 10:32:30 -0500 Subject: [PATCH] Document `socket` property of Response objects --- adafruit_requests.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/adafruit_requests.py b/adafruit_requests.py index 6231185..4b90736 100644 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -88,6 +88,21 @@ class Response: # pylint: disable=too-many-instance-attributes encoding = None + socket: SocketType + """The underlying socket object (CircuitPython extension, not in standard requests) + + Under the following circumstances, calling code may directly access the underlying + socket object: + + * The request was made with ``stream=True`` + * The request headers included ``{'connection': 'close'}`` + * No methods or properties on the Response object that access the response content + may be used + + Methods and properties that access response headers may be accessed. + + It is still necessary to ``close`` the response object for correct management of + sockets, including doing so implicitly via ``with requests.get(...) as response``.""" def __init__(self, sock: SocketType, session: "Session") -> None: self.socket = sock