Python codecs.ignore_errors() Examples
The following are 30
code examples of codecs.ignore_errors().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
codecs
, or try the search function
.
Example #1
Source File: test_codeccallbacks.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_fake_error_class(self): handlers = [ codecs.strict_errors, codecs.ignore_errors, codecs.replace_errors, codecs.backslashreplace_errors, codecs.xmlcharrefreplace_errors, ] for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: class FakeUnicodeError(str): __class__ = cls for handler in handlers: self.assertRaises(TypeError, handler, FakeUnicodeError()) class FakeUnicodeError(Exception): __class__ = cls for handler in handlers: with self.assertRaises((TypeError, FakeUnicodeError)): handler(FakeUnicodeError())
Example #2
Source File: test_codeccallbacks.py From android_universal with MIT License | 6 votes |
def test_fake_error_class(self): handlers = [ codecs.strict_errors, codecs.ignore_errors, codecs.replace_errors, codecs.backslashreplace_errors, codecs.namereplace_errors, codecs.xmlcharrefreplace_errors, codecs.lookup_error('surrogateescape'), codecs.lookup_error('surrogatepass'), ] for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: class FakeUnicodeError(str): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): self.assertRaises(TypeError, handler, FakeUnicodeError()) class FakeUnicodeError(Exception): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): with self.assertRaises((TypeError, FakeUnicodeError)): handler(FakeUnicodeError())
Example #3
Source File: test_codeccallbacks.py From android_universal with MIT License | 6 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") ) self.assertEqual( codecs.namereplace_errors, codecs.lookup_error("namereplace") )
Example #4
Source File: test_codeccallbacks.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_fake_error_class(self): handlers = [ codecs.strict_errors, codecs.ignore_errors, codecs.replace_errors, codecs.backslashreplace_errors, codecs.xmlcharrefreplace_errors, codecs.lookup_error('surrogateescape'), codecs.lookup_error('surrogatepass'), ] for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: class FakeUnicodeError(str): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): self.assertRaises(TypeError, handler, FakeUnicodeError()) class FakeUnicodeError(Exception): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): with self.assertRaises((TypeError, FakeUnicodeError)): handler(FakeUnicodeError())
Example #5
Source File: test_codeccallbacks.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") ) self.assertEqual( codecs.namereplace_errors, codecs.lookup_error("namereplace") )
Example #6
Source File: test_codeccallbacks.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_fake_error_class(self): handlers = [ codecs.strict_errors, codecs.ignore_errors, codecs.replace_errors, codecs.backslashreplace_errors, codecs.namereplace_errors, codecs.xmlcharrefreplace_errors, codecs.lookup_error('surrogateescape'), codecs.lookup_error('surrogatepass'), ] for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: class FakeUnicodeError(str): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): self.assertRaises(TypeError, handler, FakeUnicodeError()) class FakeUnicodeError(Exception): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): with self.assertRaises((TypeError, FakeUnicodeError)): handler(FakeUnicodeError())
Example #7
Source File: test_codeccallbacks.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") ) self.assertEqual( codecs.namereplace_errors, codecs.lookup_error("namereplace") )
Example #8
Source File: test_codeccallbacks.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_fake_error_class(self): handlers = [ codecs.strict_errors, codecs.ignore_errors, codecs.replace_errors, codecs.backslashreplace_errors, codecs.namereplace_errors, codecs.xmlcharrefreplace_errors, codecs.lookup_error('surrogateescape'), codecs.lookup_error('surrogatepass'), ] for cls in UnicodeEncodeError, UnicodeDecodeError, UnicodeTranslateError: class FakeUnicodeError(str): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): self.assertRaises(TypeError, handler, FakeUnicodeError()) class FakeUnicodeError(Exception): __class__ = cls for handler in handlers: with self.subTest(handler=handler, error_class=cls): with self.assertRaises((TypeError, FakeUnicodeError)): handler(FakeUnicodeError())
Example #9
Source File: test_codeccallbacks.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEquals( codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), (u"", 1) ) self.assertEquals( codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), (u"", 1) ) self.assertEquals( codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), (u"", 1) )
Example #10
Source File: test_codeccallbacks.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEqual( codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), (u"", 1) )
Example #11
Source File: test_codeccallbacks.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") )
Example #12
Source File: test_codecs.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_decode_callback(self): if sys.maxunicode > 0xffff: codecs.register_error("UnicodeInternalTest", codecs.ignore_errors) decoder = codecs.getdecoder("unicode_internal") ab = u"ab".encode("unicode_internal") ignored = decoder("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]), "UnicodeInternalTest") self.assertEqual((u"ab", 12), ignored)
Example #13
Source File: test_codeccallbacks.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEqual( codecs.ignore_errors( UnicodeEncodeError("ascii", "a\u3042b", 1, 2, "ouch")), ("", 2) ) self.assertEqual( codecs.ignore_errors( UnicodeDecodeError("ascii", bytearray(b"a\xffb"), 1, 2, "ouch")), ("", 2) ) self.assertEqual( codecs.ignore_errors( UnicodeTranslateError("a\u3042b", 1, 2, "ouch")), ("", 2) )
Example #14
Source File: test_multibytecodec.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_errorcallback_custom_ignore(self): # Issue #23215: MemoryError with custom error handlers and multibyte codecs data = 100 * "\udc00" codecs.register_error("test.ignore", codecs.ignore_errors) for enc in ALL_CJKENCODINGS: self.assertEqual(data.encode(enc, "test.ignore"), b'')
Example #15
Source File: test_codecs.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_decode_callback(self): codecs.register_error("UnicodeInternalTest", codecs.ignore_errors) decoder = codecs.getdecoder("unicode_internal") with support.check_warnings(('unicode_internal codec has been ' 'deprecated', DeprecationWarning)): ab = "ab".encode("unicode_internal").decode() ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]), "ascii"), "UnicodeInternalTest") self.assertEqual(("ab", 12), ignored)
Example #16
Source File: test_multibytecodec.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_errorcallback_custom_ignore(self): # Issue #23215: MemoryError with custom error handlers and multibyte codecs data = 100 * "\udc00" codecs.register_error("test.ignore", codecs.ignore_errors) for enc in ALL_CJKENCODINGS: self.assertEqual(data.encode(enc, "test.ignore"), b'')
Example #17
Source File: test_codeccallbacks.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_lookup(self): self.assertEquals(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEquals(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEquals(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEquals( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEquals( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") )
Example #18
Source File: test_codeccallbacks.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEqual( codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), (u"", 1) )
Example #19
Source File: test_codeccallbacks.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") )
Example #20
Source File: test_codecs.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_decode_callback(self): if sys.maxunicode > 0xffff: codecs.register_error("UnicodeInternalTest", codecs.ignore_errors) decoder = codecs.getdecoder("unicode_internal") ab = u"ab".encode("unicode_internal") ignored = decoder("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]), "UnicodeInternalTest") self.assertEqual((u"ab", 12), ignored)
Example #21
Source File: test_codeccallbacks.py From android_universal with MIT License | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEqual( codecs.ignore_errors( UnicodeEncodeError("ascii", "a\u3042b", 1, 2, "ouch")), ("", 2) ) self.assertEqual( codecs.ignore_errors( UnicodeDecodeError("ascii", bytearray(b"a\xffb"), 1, 2, "ouch")), ("", 2) ) self.assertEqual( codecs.ignore_errors( UnicodeTranslateError("a\u3042b", 1, 2, "ouch")), ("", 2) )
Example #22
Source File: test_codeccallbacks.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEqual( codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), (u"", 1) )
Example #23
Source File: test_codeccallbacks.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") )
Example #24
Source File: test_codecs.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_decode_callback(self): if sys.maxunicode > 0xffff: codecs.register_error("UnicodeInternalTest", codecs.ignore_errors) decoder = codecs.getdecoder("unicode_internal") ab = u"ab".encode("unicode_internal") ignored = decoder("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]), "UnicodeInternalTest") self.assertEqual((u"ab", 12), ignored)
Example #25
Source File: build.py From ParlAI with MIT License | 5 votes |
def create_fb_format(lines_file, convo_file, outpath): print('[building fbformat]') with open(os.path.join(outpath, 'train.txt'), 'w') as ftrain, open( os.path.join(outpath, 'valid.txt'), 'w' ) as fvalid, open(os.path.join(outpath, 'test.txt'), 'w') as ftest: lines = {} codecs.register_error('strict', codecs.ignore_errors) with codecs.open(lines_file, 'r') as f: for line in f: l = line.split(' +++$+++ ') lines[l[0]] = ' '.join(l[4:]).strip('\n').replace('\t', ' ') cnt = 0 with codecs.open(convo_file, 'r') as f: for line in f: l = line.split(' ') convo = ' '.join(l[6:]).strip('\n').strip('[').strip(']') c = convo.replace("'", '').replace(' ', '').split(',') # forward conversation s = '' index = 0 for i in range(0, len(c), 2): index += 1 s += str(index) + ' ' + lines[c[i]] if len(c) > i + 1: s += '\t' + lines[c[i + 1]] s += '\n' cnt = cnt + 1 handle = ftrain if (cnt % 10) == 0: handle = ftest if (cnt % 10) == 1: handle = fvalid handle.write(s + '\n')
Example #26
Source File: test_codeccallbacks.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") )
Example #27
Source File: test_multibytecodec.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_errorcallback_custom_ignore(self): # Issue #23215: MemoryError with custom error handlers and multibyte codecs data = 100 * unichr(0xdc00) codecs.register_error("test.ignore", codecs.ignore_errors) for enc in ALL_CJKENCODINGS: self.assertEqual(data.encode(enc, "test.ignore"), b'')
Example #28
Source File: test_codecs.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_decode_callback(self): if sys.maxunicode > 0xffff: codecs.register_error("UnicodeInternalTest", codecs.ignore_errors) decoder = codecs.getdecoder("unicode_internal") ab = u"ab".encode("unicode_internal") ignored = decoder("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]), "UnicodeInternalTest") self.assertEqual((u"ab", 12), ignored)
Example #29
Source File: test_codeccallbacks.py From BinderFilter with MIT License | 5 votes |
def test_badandgoodignoreexceptions(self): # "ignore" complains about a non-exception passed in self.assertRaises( TypeError, codecs.ignore_errors, 42 ) # "ignore" complains about the wrong exception type self.assertRaises( TypeError, codecs.ignore_errors, UnicodeError("ouch") ) # If the correct exception is passed in, "ignore" returns an empty replacement self.assertEqual( codecs.ignore_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeDecodeError("ascii", "\xff", 0, 1, "ouch")), (u"", 1) ) self.assertEqual( codecs.ignore_errors(UnicodeTranslateError(u"\u3042", 0, 1, "ouch")), (u"", 1) )
Example #30
Source File: test_codeccallbacks.py From BinderFilter with MIT License | 5 votes |
def test_lookup(self): self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual(codecs.ignore_errors, codecs.lookup_error("ignore")) self.assertEqual(codecs.strict_errors, codecs.lookup_error("strict")) self.assertEqual( codecs.xmlcharrefreplace_errors, codecs.lookup_error("xmlcharrefreplace") ) self.assertEqual( codecs.backslashreplace_errors, codecs.lookup_error("backslashreplace") )