summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRichard Jones <richard@commonground.com.au>2006-05-27 12:29:24 (GMT)
committerRichard Jones <richard@commonground.com.au>2006-05-27 12:29:24 (GMT)
commit7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77 (patch)
tree70f313905c1ef84f4ba281cab615c32e06820460 /Lib
parent1fcdc232dbfbd05b92eaed42bf9f779d27c55a92 (diff)
downloadcpython-7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77.zip
cpython-7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77.tar.gz
cpython-7b9558d37dc7f2c6ae984cf25d16b9bf5e532b77.tar.bz2
Conversion of exceptions over from faked-up classes to new-style C types.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/codeop.py10
-rw-r--r--Lib/ctypes/test/test_structures.py8
-rw-r--r--Lib/test/exception_hierarchy.txt2
-rw-r--r--Lib/test/output/test_logging6
-rw-r--r--Lib/test/test_codeccallbacks.py73
-rw-r--r--Lib/test/test_exceptions.py93
-rw-r--r--Lib/warnings.py2
7 files changed, 94 insertions, 100 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py
index daa7eb8..5616d92 100644
--- a/Lib/codeop.py
+++ b/Lib/codeop.py
@@ -95,15 +95,7 @@ def _maybe_compile(compiler, source, filename, symbol):
if code:
return code
- try:
- e1 = err1.__dict__
- except AttributeError:
- e1 = err1
- try:
- e2 = err2.__dict__
- except AttributeError:
- e2 = err2
- if not code1 and e1 == e2:
+ if not code1 and repr(err1) == repr(err2):
raise SyntaxError, err1
def _compile(source, filename, symbol):
diff --git a/Lib/ctypes/test/test_structures.py b/Lib/ctypes/test/test_structures.py
index b6eaac4..5340f79 100644
--- a/Lib/ctypes/test/test_structures.py
+++ b/Lib/ctypes/test/test_structures.py
@@ -294,20 +294,20 @@ class StructureTestCase(unittest.TestCase):
# In Python 2.5, Exception is a new-style class, and the repr changed
if issubclass(Exception, object):
self.failUnlessEqual(msg,
- "(Phone) <class 'exceptions.TypeError'>: "
+ "(Phone) <type 'exceptions.TypeError'>: "
"expected string or Unicode object, int found")
else:
self.failUnlessEqual(msg,
- "(Phone) exceptions.TypeError: "
+ "(Phone) TypeError: "
"expected string or Unicode object, int found")
cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
self.failUnlessEqual(cls, RuntimeError)
if issubclass(Exception, object):
self.failUnlessEqual(msg,
- "(Phone) <class 'exceptions.ValueError'>: too many initializers")
+ "(Phone) <type 'exceptions.ValueError'>: too many initializers")
else:
- self.failUnlessEqual(msg, "(Phone) exceptions.ValueError: too many initializers")
+ self.failUnlessEqual(msg, "(Phone) ValueError: too many initializers")
def get_except(self, func, *args):
diff --git a/Lib/test/exception_hierarchy.txt b/Lib/test/exception_hierarchy.txt
index 5fff7d9..58131d7 100644
--- a/Lib/test/exception_hierarchy.txt
+++ b/Lib/test/exception_hierarchy.txt
@@ -15,6 +15,7 @@ BaseException
| | +-- IOError
| | +-- OSError
| | +-- WindowsError (Windows)
+ | | +-- VMSError (VMS)
| +-- EOFError
| +-- ImportError
| +-- LookupError
@@ -43,5 +44,4 @@ BaseException
+-- SyntaxWarning
+-- UserWarning
+-- FutureWarning
- +-- OverflowWarning [not generated by the interpreter]
+-- ImportWarning
diff --git a/Lib/test/output/test_logging b/Lib/test/output/test_logging
index 7be3a3e..c0d6e06 100644
--- a/Lib/test/output/test_logging
+++ b/Lib/test/output/test_logging
@@ -488,12 +488,12 @@ INFO:a.b.c.d:Info 5
-- log_test4 begin ---------------------------------------------------
config0: ok.
config1: ok.
-config2: <class 'exceptions.AttributeError'>
-config3: <class 'exceptions.KeyError'>
+config2: <type 'exceptions.AttributeError'>
+config3: <type 'exceptions.KeyError'>
-- log_test4 end ---------------------------------------------------
-- log_test5 begin ---------------------------------------------------
ERROR:root:just testing
-<class 'exceptions.KeyError'>... Don't panic!
+<type 'exceptions.KeyError'>... Don't panic!
-- log_test5 end ---------------------------------------------------
-- logrecv output begin ---------------------------------------------------
ERR -> CRITICAL: Message 0 (via logrecv.tcp.ERR)
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index c6e56c9..159c86d 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -18,30 +18,12 @@ class PosReturn:
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):
@@ -478,55 +460,15 @@ class CodecCallbackTest(unittest.TestCase):
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 @@ class CodecCallbackTest(unittest.TestCase):
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)
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index fdef876..076d84d 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -81,14 +81,6 @@ try: x = undefined_variable
except NameError: pass
r(OverflowError)
-# XXX
-# Obscure: in 2.2 and 2.3, this test relied on changing OverflowWarning
-# into an error, in order to trigger OverflowError. In 2.4, OverflowWarning
-# should no longer be generated, so the focus of the test shifts to showing
-# that OverflowError *isn't* generated. OverflowWarning should be gone
-# in Python 2.5, and then the filterwarnings() call, and this comment,
-# should go away.
-warnings.filterwarnings("error", "", OverflowWarning, __name__)
x = 1
for dummy in range(128):
x += x # this simply shouldn't blow up
@@ -206,3 +198,88 @@ if not sys.platform.startswith('java'):
test_capi2()
unlink(TESTFN)
+
+# test that exception attributes are happy.
+try: str(u'Hello \u00E1')
+except Exception, e: sampleUnicodeEncodeError = e
+try: unicode('\xff')
+except Exception, e: sampleUnicodeDecodeError = e
+exceptionList = [
+ ( BaseException, (), { 'message' : '', 'args' : () }),
+ ( BaseException, (1, ), { 'message' : 1, 'args' : ( 1, ) }),
+ ( BaseException, ('foo', ), { 'message' : 'foo', 'args' : ( 'foo', ) }),
+ ( BaseException, ('foo', 1), { 'message' : '', 'args' : ( 'foo', 1 ) }),
+ ( SystemExit, ('foo',), { 'message' : 'foo', 'args' : ( 'foo', ),
+ 'code' : 'foo' }),
+ ( IOError, ('foo',), { 'message' : 'foo', 'args' : ( 'foo', ), }),
+ ( IOError, ('foo', 'bar'), { 'message' : '',
+ 'args' : ('foo', 'bar'), }),
+ ( IOError, ('foo', 'bar', 'baz'),
+ { 'message' : '', 'args' : ('foo', 'bar'), }),
+ ( EnvironmentError, ('errnoStr', 'strErrorStr', 'filenameStr'),
+ { 'message' : '', 'args' : ('errnoStr', 'strErrorStr'),
+ 'strerror' : 'strErrorStr',
+ 'errno' : 'errnoStr', 'filename' : 'filenameStr' }),
+ ( EnvironmentError, (1, 'strErrorStr', 'filenameStr'),
+ { 'message' : '', 'args' : (1, 'strErrorStr'),
+ 'strerror' : 'strErrorStr', 'errno' : 1,
+ 'filename' : 'filenameStr' }),
+ ( SyntaxError, ('msgStr',),
+ { 'message' : 'msgStr', 'args' : ('msgStr', ),
+ 'print_file_and_line' : None, 'msg' : 'msgStr',
+ 'filename' : None, 'lineno' : None, 'offset' : None,
+ 'text' : None }),
+ ( SyntaxError, ('msgStr', ('filenameStr', 'linenoStr', 'offsetStr',
+ 'textStr')),
+ { 'message' : '', 'args' : ('msgStr', ('filenameStr',
+ 'linenoStr', 'offsetStr', 'textStr' )),
+ 'print_file_and_line' : None, 'msg' : 'msgStr',
+ 'filename' : 'filenameStr', 'lineno' : 'linenoStr',
+ 'offset' : 'offsetStr', 'text' : 'textStr' }),
+ ( SyntaxError, ('msgStr', 'filenameStr', 'linenoStr', 'offsetStr',
+ 'textStr', 'print_file_and_lineStr'),
+ { 'message' : '', 'args' : ('msgStr', 'filenameStr',
+ 'linenoStr', 'offsetStr', 'textStr',
+ 'print_file_and_lineStr'),
+ 'print_file_and_line' : None, 'msg' : 'msgStr',
+ 'filename' : None, 'lineno' : None, 'offset' : None,
+ 'text' : None }),
+ ( UnicodeError, (),
+ { 'message' : '', 'args' : (), }),
+ ( sampleUnicodeEncodeError,
+ { 'message' : '', 'args' : ('ascii', u'Hello \xe1', 6, 7,
+ 'ordinal not in range(128)'),
+ 'encoding' : 'ascii', 'object' : u'Hello \xe1',
+ 'start' : 6, 'reason' : 'ordinal not in range(128)' }),
+ ( sampleUnicodeDecodeError,
+ { 'message' : '', 'args' : ('ascii', '\xff', 0, 1,
+ 'ordinal not in range(128)'),
+ 'encoding' : 'ascii', 'object' : '\xff',
+ 'start' : 0, 'reason' : 'ordinal not in range(128)' }),
+ ( UnicodeTranslateError, (u"\u3042", 0, 1, "ouch"),
+ { 'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
+ 'object' : u'\u3042', 'reason' : 'ouch',
+ 'start' : 0, 'end' : 1 }),
+ ]
+try:
+ exceptionList.append(
+ ( WindowsError, (1, 'strErrorStr', 'filenameStr'),
+ { 'message' : '', 'args' : (1, 'strErrorStr'),
+ 'strerror' : 'strErrorStr',
+ 'errno' : 22, 'filename' : 'filenameStr',
+ 'winerror' : 1 }))
+except NameError: pass
+
+for args in exceptionList:
+ expected = args[-1]
+ try:
+ if len(args) == 2: raise args[0]
+ else: raise apply(args[0], args[1])
+ except BaseException, e:
+ for checkArgName in expected.keys():
+ if repr(getattr(e, checkArgName)) != repr(expected[checkArgName]):
+ raise TestFailed('Checking exception arguments, exception '
+ '"%s", attribute "%s" expected %s got %s.' %
+ ( repr(e), checkArgName,
+ repr(expected[checkArgName]),
+ repr(getattr(e, checkArgName)) ))
diff --git a/Lib/warnings.py b/Lib/warnings.py
index bc0b818..b5d75e4 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -261,6 +261,4 @@ def _getcategory(category):
# Module initialization
_processoptions(sys.warnoptions)
-# XXX OverflowWarning should go away for Python 2.5.
-simplefilter("ignore", category=OverflowWarning, append=1)
simplefilter("ignore", category=PendingDeprecationWarning, append=1)