python3-discogs-client 2.8__py3-none-any.whl → 2.9__py3-none-any.whl

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.
@@ -1,4 +1,4 @@
1
- __version__ = '2.8'
1
+ __version__ = '2.9'
2
2
  __version_info__ = tuple(int(i) for i in __version__.split('.') if i.isdigit())
3
3
 
4
4
  from discogs_client.client import Client
discogs_client/client.py CHANGED
@@ -19,6 +19,7 @@ class Client:
19
19
  self.user_agent = user_agent
20
20
  self.verbose = False
21
21
  self._fetcher = RequestsFetcher()
22
+ self._trust_per_page = True # Default: True
22
23
 
23
24
  if consumer_key and consumer_secret:
24
25
  self.set_consumer_key(consumer_key, consumer_secret)
@@ -219,3 +220,13 @@ class Client:
219
220
  """
220
221
  self._fetcher.connect_timeout = connect
221
222
  self._fetcher.read_timeout = read
223
+
224
+ @property
225
+ def trust_per_page(self) -> bool:
226
+ return self._trust_per_page
227
+
228
+ @trust_per_page.setter
229
+ def trust_per_page(self, value: bool) -> None:
230
+ if not isinstance(value, bool):
231
+ raise ValueError("trust_per_page must be a bool")
232
+ self._trust_per_page = value
discogs_client/models.py CHANGED
@@ -354,18 +354,42 @@ class BasePaginatedResponse:
354
354
  return item
355
355
 
356
356
  def __getitem__(self, index):
357
- page_index = index // self.per_page + 1
358
- offset = index % self.per_page
357
+ """Retrieve an item by its index.
359
358
 
360
- try:
361
- page = self.page(page_index)
362
- except HTTPError as e:
363
- if e.status_code == 404:
364
- raise IndexError(e.msg)
365
- else:
359
+ By default, uses the API's ``per_page`` value to calculate the page
360
+ containing the item directly. If the API returns fewer items per page
361
+ than reported, this may yield incorrect results — set
362
+ ``client.trust_per_page = False`` to fall back to a sequential page
363
+ walk at the cost of performance.
364
+ """
365
+ if self.client._trust_per_page:
366
+ page_index = index // self.per_page + 1
367
+ offset = index % self.per_page
368
+
369
+ try:
370
+ page = self.page(page_index)
371
+ except HTTPError as e:
372
+ if e.status_code == 404:
373
+ raise IndexError(e.msg) from e
374
+ raise
375
+
376
+ return page[offset]
377
+
378
+ # Fallback to sequential page loading if we're not trusting the per_page parameter
379
+ current = 0
380
+ page_index = 1
381
+ while True:
382
+ try:
383
+ page = self.page(page_index)
384
+ except HTTPError as e:
385
+ if e.status_code == 404:
386
+ raise IndexError(e.msg) from e
366
387
  raise
388
+ if current + len(page) > index:
389
+ return page[index - current]
390
+ current += len(page)
391
+ page_index += 1
367
392
 
368
- return page[offset]
369
393
 
370
394
  def __len__(self):
371
395
  return self.count
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: python3-discogs-client
3
- Version: 2.8
3
+ Version: 2.9
4
4
  Summary: Python API client for Discogs
5
5
  Home-page: https://github.com/joalla/discogs_client
6
6
  Author: joalla
@@ -26,6 +26,7 @@ Dynamic: author-email
26
26
  Dynamic: classifier
27
27
  Dynamic: description
28
28
  Dynamic: home-page
29
+ Dynamic: license-file
29
30
  Dynamic: provides-extra
30
31
  Dynamic: requires-dist
31
32
  Dynamic: summary
@@ -0,0 +1,11 @@
1
+ discogs_client/__init__.py,sha256=9Giuys_-iyNRMOCDQGMjw69NXHC79Ky-CozAeJx7dBE,445
2
+ discogs_client/client.py,sha256=2iSw-t7R0uo_Wc3nYOTs8ELgRjtytpO1L33l4KN3Fyk,7991
3
+ discogs_client/exceptions.py,sha256=7kHj2wbpfT0gLE7uqm6c4aS28Wkr58f6u9jfpcT_NSM,1323
4
+ discogs_client/fetchers.py,sha256=D8npYWt9FILSRIhVsUdA6N0pzRCEUFh5hqQbnBu4IUg,11964
5
+ discogs_client/models.py,sha256=aG0hswHJWP3nrA-j5bSUiyFx5-tih2jtHQDRF8GP1l8,33532
6
+ discogs_client/utils.py,sha256=r0Hh8JHu8T3XZciEg0mAVV_fN7aZhUZIB08CBY5jJMM,3515
7
+ python3_discogs_client-2.9.dist-info/licenses/LICENSE,sha256=GvYq7dzLVxNCGN29xn0Ec1JMpzZwPXzOAdtZsuB9pUI,1455
8
+ python3_discogs_client-2.9.dist-info/METADATA,sha256=MLp4-CLimlOVBUEfsh4FjOMu6my0vCjr8Tt3dgen9rg,1267
9
+ python3_discogs_client-2.9.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
10
+ python3_discogs_client-2.9.dist-info/top_level.txt,sha256=jgqsRXqG3dJuCOSykXhXN68DMNu77XYQuqgqlPSSv1E,15
11
+ python3_discogs_client-2.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (83.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- discogs_client/__init__.py,sha256=C9ullFtCV-fYGz8NEWw3eGx5RgPJfApsDo3YdqG3q-c,445
2
- discogs_client/client.py,sha256=AqQmwJd54DrAFTnTb4zi1jCefjC6sbISh43FZuYsQ0g,7632
3
- discogs_client/exceptions.py,sha256=7kHj2wbpfT0gLE7uqm6c4aS28Wkr58f6u9jfpcT_NSM,1323
4
- discogs_client/fetchers.py,sha256=D8npYWt9FILSRIhVsUdA6N0pzRCEUFh5hqQbnBu4IUg,11964
5
- discogs_client/models.py,sha256=bjonpqmZ_homR51vQnOe7xiAJrrl0T6F8QfthhiskvQ,32564
6
- discogs_client/utils.py,sha256=r0Hh8JHu8T3XZciEg0mAVV_fN7aZhUZIB08CBY5jJMM,3515
7
- python3_discogs_client-2.8.dist-info/LICENSE,sha256=GvYq7dzLVxNCGN29xn0Ec1JMpzZwPXzOAdtZsuB9pUI,1455
8
- python3_discogs_client-2.8.dist-info/METADATA,sha256=Gh5aPbAZqHMpuaVmmmsXW1A3J-Jr4YRvMpsIz84gJ1I,1245
9
- python3_discogs_client-2.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
10
- python3_discogs_client-2.8.dist-info/top_level.txt,sha256=jgqsRXqG3dJuCOSykXhXN68DMNu77XYQuqgqlPSSv1E,15
11
- python3_discogs_client-2.8.dist-info/RECORD,,