code: def split_token(output):
      
  
      output = ensure_tuple(output)
  
      flags, i, len_output, data_allowed = set(), 0, len(output), True
      while i < len_output and isflag(output[i]):
          if output[i].must_be_first and i:
              raise ValueError("{} flag must be first.".format(output[i]))
          if i and output[i - 1].must_be_last:
              raise ValueError("{} flag must be last.".format(output[i - 1]))
          if output[i] in flags:
              raise ValueError("Duplicate flag {}.".format(output[i]))
          flags.add(output[i])
          data_allowed &= output[i].allows_data
          i += 1
  
      output = output[i:]
      if not data_allowed and len(output):
          raise ValueError("Output data provided after a flag that does not allow data.")
  
      return flags, output
docs: Split an output into token tuple, real output tuple.
  
      :param output:
      :return: tuple, tuple