old_contents: # -*- coding: utf-8 -*-
  
  from urllib.parse import urlencode
  from math import ceil
  from copy import copy
  
  from jsonapi_utils.constants import DEFAULT_PAGE_SIZE
  
  
  def paginate_result(data, item_count, querystring, base_url):
      """Add pagination links to result
  
      :param dict data: the result of the view
      :param int item_count: number of main item in result
      :param QueryStringManager querystring: the managed querystring fields and values
      :param str base_url: the base url for pagination
      """
      links = {}
      all_qs_args = copy(querystring.querystring)
  
      links['self'] = links['first'] = links['last'] = base_url
  
      # compute self link
      if all_qs_args:
          links['self'] += '?' + urlencode(all_qs_args)
  
      try:
          del all_qs_args['page[number]']
      except KeyError:
          pass
  
      # compute first link
      if all_qs_args:
          links['first'] += '?' + urlencode(all_qs_args)
  
      # compute last link
      page_size = int(querystring.pagination.get('size', 0)) or DEFAULT_PAGE_SIZE
      last_page = int(ceil(item_count / page_size))
      all_qs_args.update({'page[number]': last_page})
      links['last'] += '?' + urlencode(all_qs_args)
  
      # compute previous and next link
      current_page = int(querystring.pagination.get('number', 0)) or 1
      if current_page > 1:
          all_qs_args.update({'page[number]': current_page - 1})
          links['prev'] = '?'.join((base_url, urlencode(all_qs_args)))
      if current_page < last_page:
          all_qs_args.update({'page[number]': current_page + 1})
          links['next'] = '?'.join((base_url, urlencode(all_qs_args)))
  
      data['links'] = links
  
new_contents: # -*- coding: utf-8 -*-
  
  from six.moves.urllib.parse import urlencode
  from math import ceil
  from copy import copy
  
  from jsonapi_utils.constants import DEFAULT_PAGE_SIZE
  
  
  def paginate_result(data, item_count, querystring, base_url):
      """Add pagination links to result
  
      :param dict data: the result of the view
      :param int item_count: number of main item in result
      :param QueryStringManager querystring: the managed querystring fields and values
      :param str base_url: the base url for pagination
      """
      links = {}
      all_qs_args = copy(querystring.querystring)
  
      links['self'] = links['first'] = links['last'] = base_url
  
      # compute self link
      if all_qs_args:
          links['self'] += '?' + urlencode(all_qs_args)
  
      try:
          del all_qs_args['page[number]']
      except KeyError:
          pass
  
      # compute first link
      if all_qs_args:
          links['first'] += '?' + urlencode(all_qs_args)
  
      # compute last link
      page_size = int(querystring.pagination.get('size', 0)) or DEFAULT_PAGE_SIZE
      last_page = int(ceil(item_count / page_size))
      all_qs_args.update({'page[number]': last_page})
      links['last'] += '?' + urlencode(all_qs_args)
  
      # compute previous and next link
      current_page = int(querystring.pagination.get('number', 0)) or 1
      if current_page > 1:
          all_qs_args.update({'page[number]': current_page - 1})
          links['prev'] = '?'.join((base_url, urlencode(all_qs_args)))
      if current_page < last_page:
          all_qs_args.update({'page[number]': current_page + 1})
          links['next'] = '?'.join((base_url, urlencode(all_qs_args)))
  
      data['links'] = links
  
subject: update import to manage python 2 and 3