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 -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,)
54
56 "breakpoint shortcut (like pdb)"
57 logger.info("DEBUG: set_trace!")
58 debugger.set_trace(sys._getframe().f_back)
59
60
68
69
71 "send command to debbuger, wait result"
72 if command is not None:
73 logger.info("DEBUG: sending command %s" % command)
74 pipe_in.write(command)
75
76 result = []
77 while True:
78 data = pipe_out.read()
79 if data is None:
80 break
81 result.append(data)
82 logger.info("DEBUG: result %s" % repr(result))
83 return ''.join(result)
84
85
86
87
88 import gluon.contrib.qdb as qdb
89 from threading import RLock
90
91 interact_lock = RLock()
92 run_lock = RLock()
93
104 return check_fn
105
106
108 "Qdb web2py interface"
109
110 - def __init__(self, pipe, completekey='tab', stdin=None, stdout=None):
113
115 self.filename = None
116 self.lineno = None
117 self.exception_info = None
118 self.context = None
119
120
121
129
130 - def interaction(self, filename, lineno, line, **context):
139
140 - def exception(self, title, extype, exvalue, trace, request):
141 self.exception_info = {'title': title,
142 'extype': extype, 'exvalue': exvalue,
143 'trace': trace, 'request': request}
144
145 @check_interaction
148
149 @check_interaction
152
153 @check_interaction
156
157 @check_interaction
160
161 @check_interaction
164
176
177
178
179 parent_queue, child_queue = Queue.Queue(), Queue.Queue()
180 front_conn = qdb.QueuePipe("parent", parent_queue, child_queue)
181 child_conn = qdb.QueuePipe("child", child_queue, parent_queue)
182
183 web_debugger = WebDebugger(front_conn)
184 qdb_debugger = qdb.Qdb(pipe=child_conn, redirect_stdio=False, skip=None)
185 dbg = qdb_debugger
186
187
188 qdb_debugger.set_params(dict(call_stack=True, environment=True))
189
190 import gluon.main
191 gluon.main.global_settings.debugging = True
192