1__doc__ = u"""
2>>> import sys
3>>> if not IS_PY3: sys.exc_clear()
4
5>>> def test_py():
6...   old_exc = sys.exc_info()[0]
7...   try:
8...     raise AttributeError("test")
9...   except AttributeError:
10...     test_c(error=AttributeError)
11...     print(sys.exc_info()[0] is AttributeError or sys.exc_info()[0])
12...   print((IS_PY3 and sys.exc_info()[0] is old_exc) or
13...         (not IS_PY3 and sys.exc_info()[0] is AttributeError) or
14...         sys.exc_info()[0])
15
16>>> print(sys.exc_info()[0]) # 0
17None
18>>> test_py()
19True
20True
21True
22True
23
24>>> print(sys.exc_info()[0]) # test_py()
25None
26
27>>> test_c(test_py)
28True
29True
30True
31True
32True
33True
34
35>>> print(sys.exc_info()[0]) # test_c()
36None
37
38>>> def test_raise():
39...   raise TestException("test")
40>>> test_catch(test_raise, TestException)
41True
42None
43"""
44
45import sys
46IS_PY3 = sys.version_info[0] >= 3
47
48class TestException(Exception):
49    pass
50
51def test_c(func=None, error=None):
52    try:
53        raise TestException(u"test")
54    except TestException:
55        if func:
56            func()
57        print(sys.exc_info()[0] is TestException or sys.exc_info()[0])
58    print(sys.exc_info()[0] is error or sys.exc_info()[0])
59
60def test_catch(func, error):
61    try:
62        func()
63    except error:
64        print(sys.exc_info()[0] is error or sys.exc_info()[0])
65    print(sys.exc_info()[0] is error or sys.exc_info()[0])
66