Skip to content

Commit 347a527

Browse files
authored
Merge pull request #199 from adafruit/document-socket-property
Document socket property of Response objects
2 parents 4b55319 + 376fff2 commit 347a527

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

adafruit_requests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ class Response:
8888
# pylint: disable=too-many-instance-attributes
8989

9090
encoding = None
91+
socket: SocketType
92+
"""The underlying socket object (CircuitPython extension, not in standard requests)
93+
94+
Under the following circumstances, calling code may directly access the underlying
95+
socket object:
96+
97+
* The request was made with ``stream=True``
98+
* The request headers included ``{'connection': 'close'}``
99+
* No methods or properties on the Response object that access the response content
100+
may be used
101+
102+
Methods and properties that access response headers may be accessed.
103+
104+
It is still necessary to ``close`` the response object for correct management of
105+
sockets, including doing so implicitly via ``with requests.get(...) as response``."""
91106

92107
def __init__(self, sock: SocketType, session: "Session") -> None:
93108
self.socket = sock

0 commit comments

Comments
 (0)