1
# Copyright 2014-2015 Canonical Limited.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
15
"""Remote Python Debugger (pdb wrapper)."""
21
__author__ = "Bertrand Janin <b@janin.com>"
27
def __init__(self, addr="127.0.0.1", port=4444):
28
"""Initialize the socket and initialize pdb."""
30
# Backup stdin and stdout before replacing them by the socket handle
31
self.old_stdout = sys.stdout
32
self.old_stdin = sys.stdin
34
# Open a 'reusable' socket to let the webapp reload on the same port
35
self.skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
36
self.skt.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
37
self.skt.bind((addr, port))
39
(clientsocket, address) = self.skt.accept()
40
handle = clientsocket.makefile('rw')
41
pdb.Pdb.__init__(self, completekey='tab', stdin=handle, stdout=handle)
42
sys.stdout = sys.stdin = handle
45
"""Revert stdin and stdout, close the socket."""
46
sys.stdout = self.old_stdout
47
sys.stdin = self.old_stdin
51
def do_continue(self, arg):
52
"""Stop all operation on ``continue``."""
56
do_EOF = do_quit = do_exit = do_c = do_cont = do_continue