docs: def decode(data):
      """
      Decode data employing some charset detection and including unicode BOM
      stripping.
      """
  
      if isinstance(data, unicode):
          return data
  
      # Detect standard unicode BOMs.
      for bom, encoding in UNICODE_BOMS:
          if data.startswith(bom):
              return data[len(bom):].decode(encoding, errors='ignore')
  
      # Try straight UTF-8.
      try:
          return data.decode('utf-8')
      except UnicodeDecodeError:
          pass
  
      # Test for various common encodings.
      for encoding in COMMON_ENCODINGS:
          try:
              return data.decode(encoding)
          except UnicodeDecodeError:
              pass
  
      # Anything else gets filtered.
      return NON_ASCII_FILTER.sub('', data).decode('ascii', errors='replace')