reviewboard.hostingsvcs.utils.paginator¶
-
exception
InvalidPageError
[source]¶ Bases:
exceptions.Exception
An error representing an invalid page access.
-
class
BasePaginator
(start=None, per_page=None)[source]¶ Bases:
object
Base class for a paginator used in the hosting services code.
This provides the basic state and stubbed functions for a simple paginator. Subclasses can build upon this to offer more advanced functionality.
-
__init__
(start=None, per_page=None)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
has_prev
[source]¶ Returns whether there’s a previous page available.
Subclasses must override this to provide a meaningful return value.
-
has_next
[source]¶ Returns whether there’s a next page available.
Subclasses must override this to provide a meaningful return value.
-
-
class
APIPaginator
(client, url, query_params={}, *args, **kwargs)[source]¶ Bases:
reviewboard.hostingsvcs.utils.paginator.BasePaginator
Handles pagination for API requests to a hosting service.
Hosting services may provide subclasses of APIPaginator that can handle paginating their specific APIs. These make it easy to fetch pages of data from the API, and also works as a bridge for Review Board’s web API resources.
All APIPaginators are expected to take an instance of a HostingServiceClient subclass, and the starting URL (without any arguments for pagination).
Subclasses can access the HostingServiceClient through the
client
member of the paginator in order to perform requests against the HostingService.-
start_query_param
= None[source]¶ The optional query parameter name used to specify the start page in a request.
-
per_page_query_param
= None[source]¶ The optional query parameter name used to specify the requested number of results per page.
-
__init__
(client, url, query_params={}, *args, **kwargs)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
prev
()[source]¶ Fetches the previous page, returning the page data.
If there isn’t a next page available, this will raise InvalidPageError.
-
next
()[source]¶ Fetches the next page, returning the page data.
If there isn’t a next page available, this will raise InvalidPageError.
-
fetch_url
(url)[source]¶ Fetches the URL, returning information on the page.
This must be implemented by subclasses. It must return a dictionary with the following fields:
- data - The data from the page (generally as a list).
- headers - The headers from the page response.
- total_count - The optional total number of items across all pages.
- per_page - The optional limit on the number of items fetched
- on each page.
- prev_url - The optional URL to the previous page.
- next_url - The optional URL to the next page.
-
-
class
ProxyPaginator
(paginator, normalize_page_data_func=None)[source]¶ Bases:
reviewboard.hostingsvcs.utils.paginator.BasePaginator
A paginator that proxies to another paginator, transforming data.
This attaches to another paginator, forwarding all requests and proxying all data.
The ProxyPaginator can take the data returned from the other paginator and normalize it, transforming it into a new form.
This is useful when a HostingService wants to return a paginator to callers that represents data in a structured way, using an APIPaginator’s raw payloads as a backing.
-
__init__
(paginator, normalize_page_data_func=None)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
-
prev
()[source]¶ Fetches the previous page, returning the page data.
If there isn’t a next page available, this will raise InvalidPageError.
-
next
()[source]¶ Fetches the next page, returning the page data.
If there isn’t a next page available, this will raise InvalidPageError.
-
normalize_page_data
(data)[source]¶ Normalizes a page of data.
If
normalize_page_data_func
was passed on construction, this will call it, passing in the page data. That will then be returned.This can be overridden by subclasses that want to do more complex processing without requiring
normalize_page_data_func
to be passed in.
-