mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Conversion of exceptions over from faked-up classes to new-style C types.
This commit is contained in:
		
							parent
							
								
									1fcdc232db
								
							
						
					
					
						commit
						7b9558d37d
					
				
					 16 changed files with 2316 additions and 2163 deletions
				
			
		|  | @ -18,30 +18,12 @@ def handle(self, exc): | |||
|             self.pos = len(exc.object) | ||||
|         return (u"<?>", oldpos) | ||||
| 
 | ||||
| # A UnicodeEncodeError object without a start attribute | ||||
| class NoStartUnicodeEncodeError(UnicodeEncodeError): | ||||
|     def __init__(self): | ||||
|         UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") | ||||
|         del self.start | ||||
| 
 | ||||
| # A UnicodeEncodeError object with a bad start attribute | ||||
| class BadStartUnicodeEncodeError(UnicodeEncodeError): | ||||
|     def __init__(self): | ||||
|         UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") | ||||
|         self.start = [] | ||||
| 
 | ||||
| # A UnicodeEncodeError object without an end attribute | ||||
| class NoEndUnicodeEncodeError(UnicodeEncodeError): | ||||
|     def __init__(self): | ||||
|         UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") | ||||
|         del self.end | ||||
| 
 | ||||
| # A UnicodeEncodeError object without an object attribute | ||||
| class NoObjectUnicodeEncodeError(UnicodeEncodeError): | ||||
|     def __init__(self): | ||||
|         UnicodeEncodeError.__init__(self, "ascii", u"", 0, 1, "bad") | ||||
|         del self.object | ||||
| 
 | ||||
| # A UnicodeEncodeError object with a bad object attribute | ||||
| class BadObjectUnicodeEncodeError(UnicodeEncodeError): | ||||
|     def __init__(self): | ||||
|  | @ -477,56 +459,16 @@ def test_badandgoodreplaceexceptions(self): | |||
|            codecs.replace_errors, | ||||
|            UnicodeError("ouch") | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoStartUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             TypeError, | ||||
|             codecs.replace_errors, | ||||
|             BadStartUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoEndUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoObjectUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             TypeError, | ||||
|             codecs.replace_errors, | ||||
|             BadObjectUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoEndUnicodeDecodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             TypeError, | ||||
|             codecs.replace_errors, | ||||
|             BadObjectUnicodeDecodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoStartUnicodeTranslateError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoEndUnicodeTranslateError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.replace_errors, | ||||
|             NoObjectUnicodeTranslateError() | ||||
|         ) | ||||
|         # With the correct exception, "replace" returns an "?" or u"\ufffd" replacement | ||||
|         self.assertEquals( | ||||
|             codecs.replace_errors(UnicodeEncodeError("ascii", u"\u3042", 0, 1, "ouch")), | ||||
|  | @ -565,21 +507,6 @@ def test_badandgoodxmlcharrefreplaceexceptions(self): | |||
|             codecs.xmlcharrefreplace_errors, | ||||
|             UnicodeTranslateError(u"\u3042", 0, 1, "ouch") | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.xmlcharrefreplace_errors, | ||||
|             NoStartUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.xmlcharrefreplace_errors, | ||||
|             NoEndUnicodeEncodeError() | ||||
|         ) | ||||
|         self.assertRaises( | ||||
|             AttributeError, | ||||
|             codecs.xmlcharrefreplace_errors, | ||||
|             NoObjectUnicodeEncodeError() | ||||
|         ) | ||||
|         # Use the correct exception | ||||
|         cs = (0, 1, 9, 10, 99, 100, 999, 1000, 9999, 10000, 0x3042) | ||||
|         s = "".join(unichr(c) for c in cs) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Richard Jones
						Richard Jones