Given a request with a cursor, return a `Cursor` instance.
(self, request)
| 779 | return tuple(ordering) |
| 780 | |
| 781 | def decode_cursor(self, request): |
| 782 | """ |
| 783 | Given a request with a cursor, return a `Cursor` instance. |
| 784 | """ |
| 785 | # Determine if we have a cursor, and if so then decode it. |
| 786 | encoded = request.query_params.get(self.cursor_query_param) |
| 787 | if encoded is None: |
| 788 | return None |
| 789 | |
| 790 | try: |
| 791 | querystring = b64decode(encoded.encode('ascii')).decode('ascii') |
| 792 | tokens = parse.parse_qs(querystring, keep_blank_values=True) |
| 793 | |
| 794 | offset = tokens.get('o', ['0'])[0] |
| 795 | offset = _positive_int(offset, cutoff=self.offset_cutoff) |
| 796 | |
| 797 | reverse = tokens.get('r', ['0'])[0] |
| 798 | reverse = bool(int(reverse)) |
| 799 | |
| 800 | position = tokens.get('p', [None])[0] |
| 801 | except (TypeError, ValueError): |
| 802 | raise NotFound(self.invalid_cursor_message) |
| 803 | |
| 804 | return Cursor(offset=offset, reverse=reverse, position=position) |
| 805 | |
| 806 | def encode_cursor(self, cursor): |
| 807 | """ |
no test coverage detected