Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion freesound.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

try: # python 3
from urllib.request import urlopen, FancyUrlOpener, Request # noqa
from urllib.parse import urlencode, quote
from urllib.parse import urlparse, urlencode, quote
from urllib.error import HTTPError
except ImportError: # python 2.7
from urllib import urlencode, FancyURLopener, quote
Expand Down Expand Up @@ -281,6 +281,26 @@ def previous_page(self):
Get a Pager with the previous results page.
"""
return FSRequest.request(self.previous, {}, self.client, Pager)
def get_page(self, n):
url = self.next
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail if self.next is None (which could happen if there are no other pages)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Mon, 29 Aug 2016 08:07:56 -0700
Frederic Font [email protected] wrote:

@@ -281,6 +281,23 @@ def previous_page(self):
Get a Pager with the previous results page.
"""
return FSRequest.request(self.previous, {}, self.client, Pager)

  • def get_page(self, n):
  •    url = self.next
    

This will fail if self.next is None (which could happen if there are no other
pages)

True, but it's not going to fail because I do check the boundaries and this is
not called

Salvatore


if (url):
uri = urlparse(url)
for index,item in enumerate(uri):
if ('query' in item):
urid=index

query = uri[urid].split("&")

for index,item in enumerate(query):
if ("page" in item):
query[index] = 'page=' + str(n)

url = uri[0] + '://' + uri[1] + uri[2] + '?' + "&".join(query)
return FSRequest.request(url, {}, self.client, Pager)
else:
return None



class GenericPager(Pager):
Expand Down