[Python-checkins] r47066 - sandbox/trunk/pdb/README.txt sandbox/trunk/pdb/mconnection.py sandbox/trunk/pdb/mpdb.py

matt.fleming python-checkins at python.org
Thu Jun 22 14:54:44 CEST 2006


Author: matt.fleming
Date: Thu Jun 22 14:54:44 2006
New Revision: 47066
Modified:
 sandbox/trunk/pdb/README.txt
 sandbox/trunk/pdb/mconnection.py
 sandbox/trunk/pdb/mpdb.py
Log:
Added exceptions, no longer have the namespace corruption problem, imitate fileobject.close() method with disconnect().
Modified: sandbox/trunk/pdb/README.txt
==============================================================================
--- sandbox/trunk/pdb/README.txt	(original)
+++ sandbox/trunk/pdb/README.txt	Thu Jun 22 14:54:44 2006
@@ -10,13 +10,6 @@
 
 -=[TODO]=-
 * Write more unit tests, test the pdbserver and target commands.
-* sort out the namespace corruption - 
-	 """
- c:\soc\pdb\test.py(3)x()
-	 -> print c[i+1], i
-	 (MPdb)p i 
-	 *** NameError: <exceptions.NameError instance at 0x00BF6990>
-	 """
 * Write a signal handler that scripts can import from mpdb that, when
 the signal is received, start remote debugging.
 * info target,threads command needs to be written.
Modified: sandbox/trunk/pdb/mconnection.py
==============================================================================
--- sandbox/trunk/pdb/mconnection.py	(original)
+++ sandbox/trunk/pdb/mconnection.py	Thu Jun 22 14:54:44 2006
@@ -4,6 +4,11 @@
 
 NotImplementedMessage = "This method must be overriden in a subclass"
 
+### Exceptions
+class ConnectionRefused(Exception): pass
+class DroppedConnection(Exception): pass
+class ReadOnClose(Exception): pass
+
 class MServerConnectionInterface(object):
 """ This is an abstract class that specifies the interface a server
 connection class must implement. If a target is given, we'll
@@ -15,8 +20,8 @@
 raise NotImplementedError, NotImplementedMessage
 
 def disconnect(self):
-	""" This method is called to disconnect	connections."""
-	raise NotImplementedError, NotImplementedMessage
+	""" This method is called to disconnect connections."""
+ raise NotImplementedError, NotImplementedMessage
 
 def readline(self):
 """ This method reads a line of data of maximum length 'bufsize'
@@ -71,20 +76,29 @@
 (e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).
 """
 self._dev = device
- self.output = open(self._dev, 'w')
- self.input = open(self._dev, 'r')
+ try:
+ self.output = open(self._dev, 'w')
+ self.input = open(self._dev, 'r')
+ except IOError:
+ raise ConnectionRefused
 
 def disconnect(self):
 """ Close the serial device. """
+ if self.output is None and self.input is None:
+ return
 self.output.close()
 self.input.close()
 
+
 def readline(self, bufsize=2048):
 line = self.input.readline(bufsize)
 return line
 
 def write(self, msg):
+ if msg[-1] is not '\n':
+ msg += '\n'
 self.output.write(msg)
+ self.output.flush()
 
 MClientConnectionSerial = MServerConnectionSerial
 
@@ -97,7 +111,7 @@
 """
 def __init__(self):
 self.listening = False
- self.output = self.input = None
+ self._sock = self.output = self.input = None
 	MServerConnectionInterface.__init__(self)
 
 def connect(self, addr):
@@ -110,15 +124,22 @@
 if not self.listening:
 self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 self._sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- self._sock.bind((self.host, self.port))
+ try:
+ self._sock.bind((self.host, self.port))
+ except socket.error:
+ raise ConnectionRefused
 self._sock.listen(1)
 self.listening = True
 self.output, addr = self._sock.accept()
 self.input = self.output
 
 def disconnect(self):
+ # These two should either _both_ be None, or neither should be None
+ if self.output is None and self._sock is None:
+ return
 self.output.close()
 self._sock.close()
+ self._sock = None
 self.listening = False
 
 def readline(self, bufsize=2048):
@@ -139,6 +160,7 @@
 def __init__(self):
 """ Specify the address to connection to. """
 MClientConnectionInterface.__init__(self)
+ self._sock = self.output = self.input = None
 
 def connect(self, addr):
 """Connect to the server. 'input' reads data from the
@@ -163,4 +185,10 @@
 
 def disconnect(self):
 """ Close the socket to the server. """
- self._sock.close()
+ # We shouldn't bail if we haven't been connected yet
+ if self._sock is None:
+ return
+ else:
+ self._sock.close()
+
+
Modified: sandbox/trunk/pdb/mpdb.py
==============================================================================
--- sandbox/trunk/pdb/mpdb.py	(original)
+++ sandbox/trunk/pdb/mpdb.py	Thu Jun 22 14:54:44 2006
@@ -45,7 +45,6 @@
 self.prompt = '(MPdb)'
 self.target = 'local' # local connections by default
 self.connection = None
- print self._info_cmds
 
 def _rebind_input(self, new_input):
 """ This method rebinds the debugger's input to the object specified
@@ -160,8 +159,8 @@
 if '.' in target:
 if self.connection: self.connection.disconnect()
 # We dynamically load the class for the connection
- base = cls[:cls.rfind('.')]
- cls = cls[cls.rfind('.')+1:]
+ base = target[:target.rfind('.')]
+ cls = target[target.rfind('.')+1:]
 exec 'from ' + base + ' import ' + cls
 else:
 try:


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /