MCPcopy Index your code
hub / github.com/encode/django-rest-framework / decode_cursor

Method decode_cursor

rest_framework/pagination.py:781–804  ·  view source on GitHub ↗

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

(self, request)

Source from the content-addressed store, hash-verified

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 """

Callers 1

paginate_querysetMethod · 0.95

Calls 3

NotFoundClass · 0.90
_positive_intFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected