amazon-auth 0.2.0__tar.gz → 0.2.1__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.
Files changed (35) hide show
  1. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/PKG-INFO +1 -1
  2. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazon_auth.egg-info/PKG-INFO +1 -1
  3. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/__init__.py +1 -1
  4. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/conf.py +35 -6
  5. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/browser/playwright.py +1 -1
  6. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/tests/test_conf.py +53 -0
  7. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/LICENSE +0 -0
  8. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/README.md +0 -0
  9. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazon_auth.egg-info/SOURCES.txt +0 -0
  10. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazon_auth.egg-info/dependency_links.txt +0 -0
  11. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazon_auth.egg-info/requires.txt +0 -0
  12. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazon_auth.egg-info/top_level.txt +0 -0
  13. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/cli.py +0 -0
  14. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/constants.py +0 -0
  15. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/__init__.py +0 -0
  16. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/browser/__init__.py +0 -0
  17. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/waf/__init__.py +0 -0
  18. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/waf/anticaptcha.py +0 -0
  19. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/waf/base.py +0 -0
  20. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/waf/capsolver.py +0 -0
  21. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/contrib/waf/twocaptcha.py +0 -0
  22. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/exception.py +0 -0
  23. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/forms.py +0 -0
  24. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/py.typed +0 -0
  25. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/region_data.py +0 -0
  26. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/selectors.py +0 -0
  27. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/session.py +0 -0
  28. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/amazonauth/util.py +0 -0
  29. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/pyproject.toml +0 -0
  30. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/setup.cfg +0 -0
  31. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/tests/test_cli.py +0 -0
  32. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/tests/test_constants.py +0 -0
  33. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/tests/test_package.py +0 -0
  34. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/tests/test_session.py +0 -0
  35. {amazon_auth-0.2.0 → amazon_auth-0.2.1}/tests/test_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-auth
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Sign in to Amazon's consumer website and reuse the session from Python.
5
5
  Author-email: Alex Laird <contact@alexlaird.com>
6
6
  Maintainer-email: Alex Laird <contact@alexlaird.com>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amazon-auth
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Sign in to Amazon's consumer website and reuse the session from Python.
5
5
  Author-email: Alex Laird <contact@alexlaird.com>
6
6
  Maintainer-email: Alex Laird <contact@alexlaird.com>
@@ -1,4 +1,4 @@
1
1
  __copyright__ = "Copyright (c) 2026 Alex Laird"
2
2
  __license__ = "MIT"
3
- __version__ = "0.2.0"
3
+ __version__ = "0.2.1"
4
4
  __muppets__ = "no strings attached"
@@ -5,7 +5,7 @@ import inspect
5
5
  import logging
6
6
  import os
7
7
  import threading
8
- from typing import Any, Dict, Optional, Union
8
+ from typing import Any, Dict, Optional, Set, Union
9
9
  from urllib.parse import urlparse
10
10
 
11
11
  import yaml
@@ -67,6 +67,7 @@ class AmazonAuthConfig:
67
67
  self._environment: Dict[str, Any] = self.read_environment()
68
68
  self._resolved_classes: Dict[str, Any] = {}
69
69
  self._assigned_classes: Dict[str, Any] = {}
70
+ self._unavailable_class_paths: Set[str] = set()
70
71
 
71
72
  with config_file_lock:
72
73
  if os.path.exists(self.config_path):
@@ -174,10 +175,35 @@ class AmazonAuthConfig:
174
175
  Instantiate the constants and selectors, which the auth layer itself uses and so are always
175
176
  needed. The entity, output, and Transactions page classes resolve on first use instead.
176
177
  """
177
- selectors_class_split = self._class_path("selectors_class").split(".")
178
-
179
178
  self.constants = self._instantiate_constants()
180
- self.selectors = util.load_class(selectors_class_split[:-1], selectors_class_split[-1])()
179
+ self.selectors = self._load_configured_class("selectors_class")()
180
+
181
+ def _load_configured_class(self,
182
+ key: str) -> Any:
183
+ """
184
+ Load the class the given config key names. The config file can be shared with other packages built on this
185
+ one, which save their own class paths to it, so a class whose package isn't installed here falls back to the
186
+ default, with a warning. Any other failure to load it is raised.
187
+
188
+ :param key: The config key naming the class.
189
+ :return: The class.
190
+ """
191
+ class_path = self._class_path(key)
192
+ module_path, class_name = class_path.rsplit(".", 1)
193
+ try:
194
+ return util.load_class(module_path.split("."), class_name)
195
+ except ModuleNotFoundError as e:
196
+ default_class_path = self._default_data()[key]
197
+ if (class_path == default_class_path or not e.name or
198
+ not (module_path == e.name or module_path.startswith(f"{e.name}."))):
199
+ raise
200
+
201
+ if class_path not in self._unavailable_class_paths:
202
+ self._unavailable_class_paths.add(class_path)
203
+ logger.warning(f"Configured {key} '{class_path}' is unavailable, since '{e.name}' isn't installed; "
204
+ f"using the default '{default_class_path}'.")
205
+ default_module_path, default_class_name = default_class_path.rsplit(".", 1)
206
+ return util.load_class(default_module_path.split("."), default_class_name)
181
207
 
182
208
  def _validate_class_paths(self) -> None:
183
209
  """
@@ -209,8 +235,7 @@ class AmazonAuthConfig:
209
235
  source["bs4_parser"] = "html.parser"
210
236
 
211
237
  def _instantiate_constants(self) -> Any:
212
- constants_class_split = self._class_path("constants_class").split(".")
213
- constants_cls = util.load_class(constants_class_split[:-1], constants_class_split[-1])
238
+ constants_cls = self._load_configured_class("constants_class")
214
239
  # Pass ``self`` only when the constants class accepts a config arg, to keep backward
215
240
  # compatibility with existing zero-arg ``constants_class`` subclasses.
216
241
  init_params = inspect.signature(constants_cls.__init__).parameters
@@ -283,6 +308,7 @@ class AmazonAuthConfig:
283
308
  self.__dict__.update(state)
284
309
  self.__dict__.setdefault("_environment", {})
285
310
  self._resolved_classes = {}
311
+ self._unavailable_class_paths = set()
286
312
  self._load_classes()
287
313
 
288
314
  def update_config(self,
@@ -302,6 +328,9 @@ class AmazonAuthConfig:
302
328
  try:
303
329
  self._validate_bs4_parser()
304
330
  self._validate_class_paths()
331
+ if key in ("constants_class", "selectors_class"):
332
+ module_path, class_name = self._class_path(key).rsplit(".", 1)
333
+ util.load_class(module_path.split("."), class_name)
305
334
  self._load_classes()
306
335
  except (AmazonAuthError, AttributeError, ImportError):
307
336
  self._data = previous_data
@@ -979,7 +979,7 @@ class PlaywrightBrowserLogin:
979
979
 
980
980
  def _verify_session(self) -> None:
981
981
  try:
982
- response = self.amazon_session.get(self.config.constants.ORDER_HISTORY_URL, persist_cookies=True)
982
+ response = self.amazon_session.get(self.config.constants.SESSION_CHECK_URL, persist_cookies=True)
983
983
  self.amazon_session.check_response(response)
984
984
  except AmazonAuthRedirectError as e:
985
985
  self.amazon_session.logout()
@@ -9,7 +9,9 @@ import yaml
9
9
 
10
10
  from amazonauth import conf
11
11
  from amazonauth.conf import AmazonAuthConfig
12
+ from amazonauth.constants import AuthConstants
12
13
  from amazonauth.exception import AmazonAuthError
14
+ from amazonauth.selectors import AuthSelectors
13
15
  from tests.unittestcase import UnitTestCase
14
16
 
15
17
 
@@ -119,6 +121,57 @@ some_custom_config: {custom_config}
119
121
  self.assertEqual("html.parser", config.bs4_parser)
120
122
  self.assertTrue(any("this-parser-does-not-exist" in m for m in logs.output))
121
123
 
124
+ def test_class_whose_package_is_not_installed_falls_back_to_default(self):
125
+ # GIVEN
126
+ config_path = self.given_config_file("constants_class: some_uninstalled_package.constants.Constants\n"
127
+ "selectors_class: some_uninstalled_package.selectors.Selectors\n")
128
+
129
+ # WHEN
130
+ with self.assertLogs("amazonauth.conf", level="WARNING") as logs:
131
+ config = AmazonAuthConfig(config_path=config_path)
132
+ config.set_domain("amazon.de")
133
+
134
+ # THEN
135
+ self.assertIs(AuthConstants, type(config.constants))
136
+ self.assertIs(AuthSelectors, type(config.selectors))
137
+ self.assertEqual(2, len(logs.output))
138
+ self.assertIn("constants_class 'some_uninstalled_package.constants.Constants' is unavailable", logs.output[0])
139
+ self.assertIn("selectors_class 'some_uninstalled_package.selectors.Selectors' is unavailable", logs.output[1])
140
+ self.assertEqual("some_uninstalled_package.constants.Constants", config.constants_class)
141
+ self.assertIs(AuthConstants, type(pickle.loads(pickle.dumps(config)).constants))
142
+
143
+ def test_class_missing_from_installed_module_raises(self):
144
+ # GIVEN
145
+ config_path = self.given_config_file("constants_class: amazonauth.constants.NoSuchConstants\n")
146
+
147
+ # WHEN / THEN
148
+ with self.assertRaises(AttributeError):
149
+ AmazonAuthConfig(config_path=config_path)
150
+
151
+ def test_class_whose_own_import_fails_raises(self):
152
+ # GIVEN
153
+ config_path = self.given_config_file("constants_class: constants_needing_uninstalled_package.Constants\n")
154
+ dependency_error = ModuleNotFoundError("No module named 'some_uninstalled_dependency'",
155
+ name="some_uninstalled_dependency")
156
+
157
+ # WHEN / THEN
158
+ with patch("amazonauth.util.importlib.import_module", side_effect=dependency_error), \
159
+ self.assertRaises(ModuleNotFoundError) as cm:
160
+ AmazonAuthConfig(config_path=config_path)
161
+ self.assertEqual("some_uninstalled_dependency", cm.exception.name)
162
+
163
+ def test_update_config_with_class_whose_package_is_not_installed_raises(self):
164
+ # GIVEN
165
+ config = AmazonAuthConfig()
166
+
167
+ # WHEN
168
+ with self.assertRaises(ModuleNotFoundError):
169
+ config.update_config("constants_class", "some_uninstalled_package.constants.Constants")
170
+
171
+ # THEN
172
+ self.assertEqual("amazonauth.constants.AuthConstants", config.constants_class)
173
+ self.assertIs(AuthConstants, type(config.constants))
174
+
122
175
  def test_update_config(self):
123
176
  # GIVEN
124
177
  config = AmazonAuthConfig(data={
File without changes
File without changes
File without changes
File without changes