code: def do_autopaginate(parser, token):
      
      split = token.split_contents()
      as_index = None
      context_var = None
      for i, bit in enumerate(split):
          if bit == 'as':
              as_index = i
              break
      if as_index is not None:
          try:
              context_var = split[as_index + 1]
          except IndexError:
              raise template.TemplateSyntaxError("Context variable assignment " +
                  "must take the form of {%% %r object.example_set.all ... as " +
                  "context_var_name %%}" % split[0])
          del split[as_index:as_index + 2]
      if len(split) == 2:
          return AutoPaginateNode(split[1])
      elif len(split) == 3:
          return AutoPaginateNode(split[1], paginate_by=split[2], 
              context_var=context_var)
      elif len(split) == 4:
          try:
              orphans = int(split[3])
          except ValueError:
              raise template.TemplateSyntaxError(u'Got %s, but expected integer.'
                  % split[3])
          return AutoPaginateNode(split[1], paginate_by=split[2], orphans=orphans,
              context_var=context_var)
      else:
          raise template.TemplateSyntaxError('%r tag takes one required ' +
              'argument and one optional argument' % split[0])
docs: Splits the arguments to the autopaginate tag and formats them correctly.