1
# Copyright 2014-2015 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
17
"""Remote Python Debugger (pdb wrapper)."""
23
__author__ = "Bertrand Janin <b@janin.com>"
29
def __init__(self, addr="127.0.0.1", port=4444):
30
"""Initialize the socket and initialize pdb."""
32
# Backup stdin and stdout before replacing them by the socket handle
33
self.old_stdout = sys.stdout
34
self.old_stdin = sys.stdin
36
# Open a 'reusable' socket to let the webapp reload on the same port
37
self.skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
38
self.skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
39
self.skt.bind((addr, port))
41
(clientsocket, address) = self.skt.accept()
42
handle = clientsocket.makefile('rw')
43
pdb.Pdb.__init__(self, completekey='tab', stdin=handle, stdout=handle)
44
sys.stdout = sys.stdin = handle
47
"""Revert stdin and stdout, close the socket."""
48
sys.stdout = self.old_stdout
49
sys.stdin = self.old_stdin
53
def do_continue(self, arg):
54
"""Stop all operation on ``continue``."""
58
do_EOF = do_quit = do_exit = do_c = do_cont = do_continue