'Given a request with a cursor, return a `Cursor` instance.'

def decode_cursor(self, request):

    encoded = request.query_params.get(self.cursor_query_param)
    if (encoded is None):
        return None
    try:
        querystring = b64decode(encoded.encode(u'ascii')).decode(u'ascii')
        tokens = urlparse.parse_qs(querystring, keep_blank_values=True)
        offset = tokens.get(u'o', [u'0'])[0]
        offset = _positive_int(offset, cutoff=self.offset_cutoff)
        reverse = tokens.get(u'r', [u'0'])[0]
        reverse = bool(int(reverse))
        position = tokens.get(u'p', [None])[0]
    except (TypeError, ValueError):
        raise NotFound(self.invalid_cursor_message)
    return Cursor(offset=offset, reverse=reverse, position=position)
