aioamazondevices 3.0.4__tar.gz → 3.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/PKG-INFO +1 -1
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/pyproject.toml +1 -1
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/__init__.py +1 -1
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/api.py +26 -4
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/LICENSE +0 -0
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/README.md +0 -0
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/const.py +0 -0
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/exceptions.py +0 -0
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/httpx.py +0 -0
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/py.typed +0 -0
- {aioamazondevices-3.0.4 → aioamazondevices-3.0.5}/src/aioamazondevices/sounds.py +0 -0
@@ -9,7 +9,7 @@ from dataclasses import dataclass
|
|
9
9
|
from datetime import UTC, datetime, timedelta
|
10
10
|
from enum import StrEnum
|
11
11
|
from http import HTTPStatus
|
12
|
-
from http.cookies import Morsel
|
12
|
+
from http.cookies import Morsel, SimpleCookie
|
13
13
|
from pathlib import Path
|
14
14
|
from typing import Any, cast
|
15
15
|
from urllib.parse import parse_qs, urlencode
|
@@ -19,7 +19,7 @@ from aiohttp import ClientResponse, ClientSession
|
|
19
19
|
from babel import Locale
|
20
20
|
from bs4 import BeautifulSoup, Tag
|
21
21
|
from httpx import URL as HTTPX_URL
|
22
|
-
from multidict import MultiDictProxy
|
22
|
+
from multidict import CIMultiDictProxy, MultiDictProxy
|
23
23
|
from yarl import URL as YARL_URL
|
24
24
|
|
25
25
|
from .const import (
|
@@ -50,7 +50,7 @@ from .exceptions import CannotAuthenticate, CannotRegisterDevice, WrongMethod
|
|
50
50
|
from .httpx import HttpxClientResponseWrapper, HttpxClientSession
|
51
51
|
|
52
52
|
# Values: "aiohttp", or "httpx"
|
53
|
-
LIBRARY = "
|
53
|
+
LIBRARY = "aiohttp"
|
54
54
|
|
55
55
|
|
56
56
|
@dataclass
|
@@ -262,6 +262,23 @@ class AmazonEchoApi:
|
|
262
262
|
cookies=self._cookies,
|
263
263
|
)
|
264
264
|
|
265
|
+
async def _parse_cookies_from_headers(
|
266
|
+
self, headers: CIMultiDictProxy[str]
|
267
|
+
) -> dict[str, str]:
|
268
|
+
"""Parse cookies with a value from headers."""
|
269
|
+
cookies_with_value: dict[str, str] = {}
|
270
|
+
|
271
|
+
for value in headers.getall("Set-Cookie", ()):
|
272
|
+
cookie = SimpleCookie()
|
273
|
+
cookie.load(value)
|
274
|
+
|
275
|
+
for name, morsel in cookie.items():
|
276
|
+
if morsel.value and morsel.value not in ("-", ""):
|
277
|
+
cookies_with_value[name] = morsel.value
|
278
|
+
|
279
|
+
_LOGGER.debug("Cookies from headers: %s", cookies_with_value)
|
280
|
+
return cookies_with_value
|
281
|
+
|
265
282
|
async def _session_request(
|
266
283
|
self,
|
267
284
|
method: str,
|
@@ -289,6 +306,9 @@ class AmazonEchoApi:
|
|
289
306
|
_LOGGER.debug("Adding %s to headers", json_header)
|
290
307
|
headers.update(json_header)
|
291
308
|
|
309
|
+
_cookies = (
|
310
|
+
self._load_website_cookies() if self._login_stored_data else self._cookies
|
311
|
+
)
|
292
312
|
_url: YARL_URL | str = url
|
293
313
|
if LIBRARY == "aiohttp":
|
294
314
|
_url = YARL_URL(url, encoded=True)
|
@@ -297,9 +317,11 @@ class AmazonEchoApi:
|
|
297
317
|
method,
|
298
318
|
_url,
|
299
319
|
data=input_data if not json_data else orjson.dumps(input_data),
|
300
|
-
cookies=
|
320
|
+
cookies=_cookies,
|
301
321
|
headers=headers,
|
302
322
|
)
|
323
|
+
self._cookies.update(**await self._parse_cookies_from_headers(resp.headers))
|
324
|
+
|
303
325
|
content_type: str = resp.headers.get("Content-Type", "")
|
304
326
|
_LOGGER.debug(
|
305
327
|
"Response %s for url %s with content type: %s",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|