Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _as_unicode(source, encoding):
if encoding != 'utf-8':
# if a source and a different encoding is given, try to decode the the source into a
# unicode string
try:
source = cast_unicode(source, encoding=encoding)
except (UnicodeDecodeError, UnicodeEncodeError):
pass
return source