code: def unicode_safe(text, encoding=UrlEncoding, errors='ignore'):
      
      try:
          text_type = unicode
      except NameError:
          text_type = str
      if isinstance(text, text_type):
          return text
      return text.decode(encoding, errors)
docs: Decode text to Unicode if not already done.