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 pdb
14 import Queue
15 import sys
16
17 logger = logging.getLogger("web2py")
18
19
20 -class Pipe(Queue.Queue):
21 - def __init__(self, name, mode='r', *args, **kwargs):
22 self.__name = name
23 Queue.Queue.__init__(self, *args, **kwargs)
24
26 logger.debug("debug %s writting %s" % (self.__name, data))
27 self.put(data)
28
30
31 logger.debug("debug %s flushing..." % self.__name)
32 self.put(None)
33
34 self.join()
35 logger.debug("debug %s flush done" % self.__name)
36
37 - def read(self, count=None, timeout=None):
38 logger.debug("debug %s reading..." % (self.__name, ))
39 data = self.get(block=True, timeout=timeout)
40
41 self.task_done()
42 logger.debug("debug %s read %s" % (self.__name, data))
43 return data
44
46 logger.debug("debug %s readline..." % (self.__name, ))
47 return self.read()
48
49
50 pipe_in = Pipe('in')
51 pipe_out = Pipe('out')
52
53 debugger = pdb.Pdb(completekey=None, stdin=pipe_in, stdout=pipe_out,)
57 "breakpoint shortcut (like pdb)"
58 logger.info("DEBUG: set_trace!")
59 debugger.set_trace(sys._getframe().f_back)
60
69
73 "send command to debbuger, wait result"
74 if command is not None:
75 logger.info("DEBUG: sending command %s" % command)
76 pipe_in.write(command)
77
78 result = []
79 while True:
80 data = pipe_out.read()
81 if data is None:
82 break
83 result.append(data)
84 logger.info("DEBUG: result %s" % repr(result))
85 return ''.join(result)
86
87
88
89
90 import gluon.contrib.qdb as qdb
91 from threading import RLock
92
93 interact_lock = RLock()
94 run_lock = RLock()
107 return check_fn
108
111 "Qdb web2py interface"
112
113 - def __init__(self, pipe, completekey='tab', stdin=None, stdout=None):
116
118 self.filename = None
119 self.lineno = None
120 self.exception_info = None
121 self.context = None
122
123
124
132
133 - def interaction(self, filename, lineno, line, **context):
142
143 - def exception(self, title, extype, exvalue, trace, request):
144 self.exception_info = {'title': title,
145 'extype': extype, 'exvalue': exvalue,
146 'trace': trace, 'request': request}
147
148 @check_interaction
151
152 @check_interaction
155
156 @check_interaction
159
160 @check_interaction
163
164 @check_interaction
167
179
180
181
182 parent_queue, child_queue = Queue.Queue(), Queue.Queue()
183 front_conn = qdb.QueuePipe("parent", parent_queue, child_queue)
184 child_conn = qdb.QueuePipe("child", child_queue, parent_queue)
185
186 web_debugger = WebDebugger(front_conn)
187 qdb_debugger = qdb.Qdb(
188 pipe=child_conn, redirect_stdio=False, skip=None)
189 dbg = qdb_debugger
190
191
192 qdb_debugger.set_params(dict(call_stack=True, environment=True))
193
194 import gluon.main
195 gluon.main.global_settings.debugging = True
196