docs: def to_key_val_list(value, sort=False, insensitive=False):
      """
      Take an object and test to see if it can be represented as a
      dictionary. If it can be, return a list of tuples, e.g.,
      ::
          >>> to_key_val_list([('key', 'val')])
          [('key', 'val')]
          >>> to_key_val_list({'key': 'val'})
          [('key', 'val')]
          >>> to_key_val_list({'key': 'val'}, sort=True)
          [('key', 'val')]
          >>> to_key_val_list('string')
          ValueError: cannot encode objects that are not 2-tuples.
      """
      if value is None:
          return None
  
      if isinstance(value, (str, bytes, bool, int)):
          raise ValueError('cannot encode objects that are not 2-tuples')
  
      if isinstance(value, collections.Mapping):
          value = value.items()
  
      if sort and not insensitive:
          values = sorted(value)
      elif sort:
          values = sorted(value, key=lambda t: t[0].lower())
      else:
          values = value
      return list(values)