MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / Response

Class Response

mpython/lib/optional/urequests.py:3–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import usocket
2
3class Response:
4 def __init__(self, f):
5 self.raw = f
6 self.encoding = "utf-8"
7 self._cached = None
8
9 def close(self):
10 if self.raw:
11 self.raw.close()
12 self.raw = None
13 self._cached = None
14
15 @property
16 def content(self):
17 if self._cached is None:
18 try:
19 self._cached = self.raw.read()
20 finally:
21 self.raw.close()
22 self.raw = None
23 return self._cached
24
25 @property
26 def text(self):
27 return str(self.content, self.encoding)
28
29 def json(self):
30 import ujson
31
32 return ujson.loads(self.content)
33
34
35def request(

Callers 1

requestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected