code: def encode_for_locale(s):
      
      try:
          return s.encode(LOCALE_ENCODING, 'ignore')
      except (AttributeError, UnicodeDecodeError):
          return s.decode('ascii', 'ignore').encode(LOCALE_ENCODING)
docs: Encode text items for system locale. If encoding fails, fall back to ASCII.