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 -class Pipe(Queue.Queue):
20 - def __init__(self, name, mode='r', *args, **kwargs):
21 self.__name = name
22 Queue.Queue.__init__(self, *args, **kwargs)
23
25 logger.debug("debug %s writting %s" % (self.__name, data))
26 self.put(data)
27
29
30 logger.debug("debug %s flushing..." % self.__name)
31 self.put(None)
32
33 self.join()
34 logger.debug("debug %s flush done" % self.__name)
35
36 - def read(self, count=None, timeout=None):
37 logger.debug("debug %s reading..." % (self.__name, ))
38 data = self.get(block=True, timeout=timeout)
39
40 self.task_done()
41 logger.debug("debug %s read %s" % (self.__name, data))
42 return data
43
45 logger.debug("debug %s readline..." % (self.__name, ))
46 return self.read()
47
48
49 pipe_in = Pipe('in')
50 pipe_out = Pipe('out')
51
52 debugger = pdb.Pdb(completekey=None, stdin=pipe_in, stdout=pipe_out,)
53
55 "breakpoint shortcut (like pdb)"
56 logger.info("DEBUG: set_trace!")
57 debugger.set_trace(sys._getframe().f_back)
58
59
67
68
70 "send command to debbuger, wait result"
71 if command is not None:
72 logger.info("DEBUG: sending command %s" % command)
73 pipe_in.write(command)
74
75 result = []
76 while True:
77 data = pipe_out.read()
78 if data is None:
79 break
80 result.append(data)
81 logger.info("DEBUG: result %s" % repr(result))
82 return ''.join(result)
83