Generate AES KeyPair lazily (#687)

* Generate AES KeyPair lazily

* Fix coverage

* Update post-review

* Fix pragma

* Make json dumps consistent between python and orjson

* Add comment

* Add comments re json parameter in HttpClient
This commit is contained in:
Steven B
2024-01-23 15:29:27 +00:00
committed by GitHub
parent 718983c401
commit e233e377ad
4 changed files with 58 additions and 24 deletions

View File

@@ -41,14 +41,25 @@ class HttpClient:
*,
params: Optional[Dict[str, Any]] = None,
data: Optional[bytes] = None,
json: Optional[Dict] = None,
json: Optional[Union[Dict, Any]] = None,
headers: Optional[Dict[str, str]] = None,
cookies_dict: Optional[Dict[str, str]] = None,
) -> Tuple[int, Optional[Union[Dict, bytes]]]:
"""Send an http post request to the device."""
"""Send an http post request to the device.
If the request is provided via the json parameter json will be returned.
"""
response_data = None
self._last_url = url
self.client.cookie_jar.clear()
return_json = bool(json)
# If json is not a dict send as data.
# This allows the json parameter to be used to pass other
# types of data such as async_generator and still have json
# returned.
if json and not isinstance(json, Dict):
data = json
json = None
try:
resp = await self.client.post(
url,
@@ -62,7 +73,7 @@ class HttpClient:
async with resp:
if resp.status == 200:
response_data = await resp.read()
if json:
if return_json:
response_data = json_loads(response_data.decode())
except (aiohttp.ServerDisconnectedError, aiohttp.ClientOSError) as ex: