Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Source.decode_source(encoded)
else:
decoded = Source.decode_source(encoded)
if matches:
self.assertEqual(decoded, source)
else:
self.assertNotEqual(decoded, source)
check(u'# coding=utf8\né', 'utf8')
check(u'# coding=gbk\né', 'gbk')
check(u'# coding=utf8\né', 'gbk', exception=UnicodeDecodeError)
check(u'# coding=gbk\né', 'utf8', matches=False)
# In Python 3 the default encoding is assumed to be UTF8
if PY3:
check(u'é', 'utf8')
check(u'é', 'gbk', exception=SyntaxError)