<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def paginated(resource_name=None):
 """Decorator that handles pagination headers, params, and links. This accepts, parses, validates, and handles `limit` and `offset` optional query params according to common Rackspace APIs and passes them as kwargs to the decorated function. offset: The pagination offset. limit: The pagination limit (or page size). The response is paginated with a default limit of 100 and a maximum limit of 1000. Headers returned include: It adds Content-Range headers to the response according to RFC 7233 section 4.2 - https://tools.ietf.org/html/rfc7233#section-4.2. The resource name is supplied in the decorator call as resource_name or deduced from uripath if not supplied. It adds link headers based on RFC 5988 (by ex-Racker Mark Nottingham) - https://tools.ietf.org/html/rfc5988#section-5.5. Future changes to the RFCs or common API concepts, such as adding links to the response body, may be implemented here to consistently handle pagination across all projects using simpl pagination for their APIs. Opinionated assumptions: - body has data items under a `data` or `results` key. - the `len()` of that data represents the number of records being returned in this page. - body has a `collection-count` value with the total number of records in the underlying collection. - bottle is being used and this is decorating a route function. Responses: - paginated responses are returned as `206 Partial Content` unless all the data fits in one page, inwhich case the response is `200 OK`. Example response for **GET** `/widgets[&limit=2&offset=3]` > HTTP/1.0 206 Partial Content > Content-Range: widget 3-4/6 > Content-Length: 217 > Content-Type: application/json > Link: </widgets?limit=2&offset=1>; rel="previous"; title="Previous page" > Link: </widgets?limit=2>; rel="first"; title="First page" > Link: </widgets?offset=4>; rel="last"; title="Last page" ```json { "collection-count": 6, "data": [ { "id": 1, "name": "foo" }, { "id": 2, "name": "bar" } ] } ``` """

    def _paginated(fxn):
        """Add pagination (optional) and headers to response."""
        def _decorator(*args, **kwargs):
            """Internal function wrapped as a decorator."""
            try:
                validate_range_values(bottle.request, 'offset', kwargs)
                validate_range_values(bottle.request, 'limit', kwargs)
            except ValueError:
                bottle.response.status = 416
                bottle.response.set_header(
                    'Content-Range', '%s */*' %
                    resource_name or bottle.request.path.split('/')[-1])
                return

            data = fxn(*args, **kwargs)
            write_pagination_headers(
                data,
                int(kwargs.get('offset') or 0),
                int(kwargs.get('limit') or 100),
                bottle.response,
                bottle.request.path,
                resource_name)
            return data
        return functools.wraps(fxn)(_decorator)
    return _paginated