1
2
3
4 """
5 This file is part of the web2py Web Framework
6 Developed by Massimo Di Pierro <mdipierro@cs.depaul.edu>,
7 limodou <limodou@gmail.com> and srackham <srackham@gmail.com>.
8 License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
9
10 """
11
12 import logging
13 import os
14 import pdb
15 import Queue
16 import sys
17
18 logger = logging.getLogger("web2py")
19
20
21 -class Pipe(Queue.Queue):
22 - def __init__(self, name, mode='r', *args, **kwargs):
23 self.__name = name
24 Queue.Queue.__init__(self, *args, **kwargs)
25
27 logger.debug("debug %s writting %s" % (self.__name, data))
28 self.put(data)
29
31
32 logger.debug("debug %s flushing..." % self.__name)
33 self.put(None)
34
35 self.join()
36 logger.debug("debug %s flush done" % self.__name)
37
38 - def read(self, count=None, timeout=None):
39 logger.debug("debug %s reading..." % (self.__name, ))
40 data = self.get(block=True, timeout=timeout)
41
42 self.task_done()
43 logger.debug("debug %s read %s" % (self.__name, data))
44 return data
45
47 logger.debug("debug %s readline..." % (self.__name, ))
48 return self.read()
49
50
51 pipe_in = Pipe('in')
52 pipe_out = Pipe('out')
53
54 debugger = pdb.Pdb(completekey=None, stdin=pipe_in, stdout=pipe_out,)
58 "breakpoint shortcut (like pdb)"
59 logger.info("DEBUG: set_trace!")
60 debugger.set_trace(sys._getframe().f_back)
61
70
74 "send command to debbuger, wait result"
75 if command is not None:
76 logger.info("DEBUG: sending command %s" % command)
77 pipe_in.write(command)
78
79 result = []
80 while True:
81 data = pipe_out.read()
82 if data is None:
83 break
84 result.append(data)
85 logger.info("DEBUG: result %s" % repr(result))
86 return ''.join(result)
87
88
89
90
91 import gluon.contrib.qdb as qdb
92 from threading import RLock
93
94 interact_lock = RLock()
95 run_lock = RLock()
108 return check_fn
109
112 "Qdb web2py interface"
113
114 - def __init__(self, pipe, completekey='tab', stdin=None, stdout=None):
117
119 self.filename = None
120 self.lineno = None
121 self.exception_info = None
122 self.context = None
123
124
125
133
134 - def interaction(self, filename, lineno, line, **context):
143
144 - def exception(self, title, extype, exvalue, trace, request):
145 self.exception_info = {'title': title,
146 'extype': extype, 'exvalue': exvalue,
147 'trace': trace, 'request': request}
148
149 @check_interaction
152
153 @check_interaction
156
157 @check_interaction
160
161 @check_interaction
164
165 @check_interaction
168
180
181
182
183 parent_queue, child_queue = Queue.Queue(), Queue.Queue()
184 front_conn = qdb.QueuePipe("parent", parent_queue, child_queue)
185 child_conn = qdb.QueuePipe("child", child_queue, parent_queue)
186
187 web_debugger = WebDebugger(front_conn)
188 qdb_debugger = qdb.Qdb(
189 pipe=child_conn, redirect_stdio=False, skip=None)
190 dbg = qdb_debugger
191
192
193 qdb_debugger.set_params(dict(call_stack=True, environment=True))
194
195 import gluon.main
196 gluon.main.global_settings.debugging = True
197