-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
41 lines (35 loc) · 1.23 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
################################################################################
# #
# Exception Formatting #
# #
# Source: SO - question/666022 #
# #
################################################################################
r"""
import sys
import traceback
from HTMLParser import HTMLParseError
def formatExceptionInfo(maxTBlevel=5):
cla, exc, trbk = sys.exc_info()
excName = cla.__name__
try:
excArgs = exc.__dict__["args"]
except KeyError:
excArgs = "<no args>"
excTb = traceback.format_tb(trbk, maxTBlevel)
return (excName, excArgs, excTb)
from bs4 import BeautifulSoup
s = """
<html>
<script>
var pstr = "<li><font color='blue'>1</font></li>";
for(var lc=0;lc<o.length;lc++){}
</script>
</html>
"""
try:
p = BeautifulSoup(s)
except HTMLParseError:
print formatExceptionInfo()
"""
########################### END OF EXCEPTION TRACING ###########################