python3-discogs-client 2.8__tar.gz → 2.9__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.
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/PKG-INFO +3 -2
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/__init__.py +1 -1
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/client.py +11 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/models.py +33 -9
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_core.py +40 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/python3_discogs_client.egg-info/PKG-INFO +3 -2
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/setup.py +1 -1
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/LICENSE +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/MANIFEST.in +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/exceptions.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/fetchers.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/__init__.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/1/releases_per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/1/releases_per_page=50&page=2.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/2.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/3.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/database/search_artist=trash80&per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/database/search_artist=trash80&title=icarus&per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/database/search_q=trash%2080&per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/database/search_q=trash80&per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/labels/1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/labels/31405.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/lists/1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/marketplace/fee/20.5000/EUR.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/marketplace/listings/150899904.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/marketplace/stats/1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/masters/4242/versions_per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/masters/4242.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/oauth/identity.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/2.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/3.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/3329867.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/79.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/users/example/collection/folders/0/releases_page=1&per_page=50.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/users/example/collection/folders.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/users/example/collection/value.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/users/example/inventory_per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/users/example/wants_per_page=50&page=1.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/users/example.json +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_fetchers.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_models.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_utils.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/utils.py +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/python3_discogs_client.egg-info/SOURCES.txt +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/python3_discogs_client.egg-info/dependency_links.txt +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/python3_discogs_client.egg-info/requires.txt +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/python3_discogs_client.egg-info/top_level.txt +0 -0
- {python3_discogs_client-2.8 → python3_discogs_client-2.9}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python3-discogs-client
|
|
3
|
-
Version: 2.
|
|
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
|
|
@@ -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
|
|
@@ -354,18 +354,42 @@ class BasePaginatedResponse:
|
|
|
354
354
|
return item
|
|
355
355
|
|
|
356
356
|
def __getitem__(self, index):
|
|
357
|
-
|
|
358
|
-
offset = index % self.per_page
|
|
357
|
+
"""Retrieve an item by its index.
|
|
359
358
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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
|
|
@@ -111,6 +111,46 @@ class CoreTestCase(DiscogsClientTestCase):
|
|
|
111
111
|
results.per_page = 10
|
|
112
112
|
self.assertTrue(results._num_pages is None)
|
|
113
113
|
|
|
114
|
+
def test_pagination_index_without_trust_per_page_and_short_pages(self):
|
|
115
|
+
"""Without trust_per_page, sequential page walking handles under-filled pages correctly."""
|
|
116
|
+
client = Client('ua')
|
|
117
|
+
client.trust_per_page = False # opt into sequential walk
|
|
118
|
+
client._base_url = ''
|
|
119
|
+
client._trust_per_page = False
|
|
120
|
+
client._fetcher = MemoryFetcher({
|
|
121
|
+
'/artists/1': (
|
|
122
|
+
b'{"id": 1, "name": "Badger", "releases_url": "/artists/1/releases"}',
|
|
123
|
+
200,
|
|
124
|
+
),
|
|
125
|
+
'/artists/1/releases?page=1&per_page=50': (
|
|
126
|
+
b'{"pagination": {"per_page": 50, "pages": 3, "items": 5}, '
|
|
127
|
+
b'"releases": ['
|
|
128
|
+
b'{"id": 101, "type": "release", "title": "A"},'
|
|
129
|
+
b'{"id": 102, "type": "release", "title": "B"}'
|
|
130
|
+
b']}',
|
|
131
|
+
200,
|
|
132
|
+
),
|
|
133
|
+
'/artists/1/releases?page=2&per_page=50': (
|
|
134
|
+
b'{"pagination": {"per_page": 50, "pages": 3, "items": 5}, '
|
|
135
|
+
b'"releases": [{"id": 103, "type": "release", "title": "C"}]}',
|
|
136
|
+
200,
|
|
137
|
+
),
|
|
138
|
+
'/artists/1/releases?page=3&per_page=50': (
|
|
139
|
+
b'{"pagination": {"per_page": 50, "pages": 3, "items": 5}, '
|
|
140
|
+
b'"releases": ['
|
|
141
|
+
b'{"id": 104, "type": "release", "title": "D"},'
|
|
142
|
+
b'{"id": 105, "type": "release", "title": "E"}'
|
|
143
|
+
b']}',
|
|
144
|
+
200,
|
|
145
|
+
),
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
results = client.artist(1).releases
|
|
149
|
+
self.assertEqual(results[0].id, 101) # page 1
|
|
150
|
+
self.assertEqual(results[2].id, 103) # page 2, cross-page
|
|
151
|
+
self.assertEqual(results[4].id, 105) # page 3, last item
|
|
152
|
+
self.assertRaises(IndexError, lambda: results[5])
|
|
153
|
+
|
|
114
154
|
def test_timeout_defaults_to_none(self):
|
|
115
155
|
# Need to create client without LoggingDelegator here
|
|
116
156
|
# self.d would throw AttributeError trying to access timeout properties on LoggingDelegator
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/python3_discogs_client.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python3-discogs-client
|
|
3
|
-
Version: 2.
|
|
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
|
|
@@ -4,7 +4,7 @@ from setuptools import setup
|
|
|
4
4
|
|
|
5
5
|
setup(
|
|
6
6
|
name='python3-discogs-client',
|
|
7
|
-
version='2.
|
|
7
|
+
version='2.9',
|
|
8
8
|
description='Python API client for Discogs',
|
|
9
9
|
long_description='This is an active fork of the official "Discogs API client for Python", which was deprecated by discogs.com as of June 2020. We think it is a very useful Python module and decided to continue maintaining it. Please visit: https://github.com/joalla/discogs_client for more information.',
|
|
10
10
|
url='https://github.com/joalla/discogs_client',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/1.json
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/2.json
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/artists/3.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/labels/1.json
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/labels/31405.json
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/lists/1.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/masters/4242.json
RENAMED
|
File without changes
|
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/1.json
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/2.json
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/3.json
RENAMED
|
File without changes
|
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/res/releases/79.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_fetchers.py
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_models.py
RENAMED
|
File without changes
|
{python3_discogs_client-2.8 → python3_discogs_client-2.9}/discogs_client/tests/test_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|