-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdescribe.wsgi
64 lines (55 loc) · 2.21 KB
/
describe.wsgi
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import string
import sys
import traceback
from webob import Request
from stacktraces import process_model, thread_analyzer
from stacktraces.analyze import httpd
from stacktraces.native import debugger
def application(environ, start_response):
req = Request(environ)
converting = False
debugger_output = req.body.split('\n')
try:
# Some gdb output from Mac OS X includes non-printable characters which cause json.dumps to die.
for i in range(len(debugger_output)):
try:
json.dumps({'line': debugger_output[i]})
except Exception:
# Fix it
for cindex in range(len(debugger_output[i])):
if not debugger_output[i][cindex] in string.printable:
debugger_output[i] = debugger_output[i][:cindex] + '.' + debugger_output[i][cindex + 1:]
p = process_model.Process(None)
dbg = debugger.Debugger(debuglog=debugger_output, proc=p)
dbg.parse()
thread_analyzer.cleanup(p, httpd.httpd_cleanups)
thread_analyzer.annotate(p, httpd.httpd_annotations)
p.group()
converting = True
output = json.dumps({"success": True, 'procinfo': p.description()})
converting = False
except Exception:
for info in sys.exc_info():
print >> sys.stderr, "DESCRIBE ERROR: %s" % str(info)
traceback.print_tb(sys.exc_info()[2])
if converting:
errmsg = (
'An error occurred converting the output to JSON. ' +
'The file uploaded may contain unexpected characters.'
)
linenum = 0
for l in debugger_output:
linenum += 1
try:
json.dumps({'line': l})
except Exception:
errmsg += '<br />The problem may be with line %d.' % linenum
break
else:
errmsg = 'An error occurred processing the data.'
output = json.dumps({"success": True, 'errmsg': errmsg})
status = '200 OK'
response_headers = [('Content-type', 'application/json')]
start_response(status, response_headers)
return [output]