Permalink
Browse files

Some refactoring of artnez's connection interrupt code

Removed vim dependency from dbgp and created a new InputStream class
which is passed in to the Connection object. This is used to probe Vim's
input stream and check for keyboard interrupts.
  • Loading branch information...
1 parent f02ed6b commit 08b997cea1350e8774f3f94762e5ceb6c2381bab @joonty joonty committed Aug 31, 2012
Showing with 34 additions and 20 deletions.
  1. +1 −1 plugin/python/start_vdebug.py
  2. +15 −18 plugin/python/vdebug/dbgp.py
  3. +4 −1 plugin/python/vdebug/runner.py
  4. +14 −0 plugin/python/vdebug/util.py
@@ -203,7 +203,7 @@ def handle_exception(self,e):
"""
if isinstance(e,vdebug.dbgp.TimeoutError):
self.handle_timeout()
- elif isinstance(e,vdebug.dbgp.UserInterrupt):
+ elif isinstance(e,vdebug.util.UserInterrupt):
self.handle_interrupt()
elif isinstance(e,vdebug.event.EventError):
self.handle_readable_error(e)
@@ -3,7 +3,6 @@
import vdebug.log
import base64
import time
-import vim
""" Response objects for the DBGP module."""
@@ -363,18 +362,20 @@ class Connection:
address = None
isconned = 0
- def __init__(self, host = '', port = 9000, timeout = 30):
+ def __init__(self, host = '', port = 9000, timeout = 30, input_stream = None):
"""Create a new Connection.
The connection is not established until open() is called.
host -- host name where debugger is running (default '')
port -- port number which debugger is listening on (default 9000)
timeout -- time in seconds to wait for a debugger connection before giving up (default 30)
+ input_stream -- object for checking input stream and user interrupts (default None)
"""
self.port = port
self.host = host
self.timeout = timeout
+ self.input_stream = input_stream
def __del__(self):
"""Make sure the connection is closed."""
@@ -399,9 +400,9 @@ def open(self):
except socket.timeout:
serv.close()
raise TimeoutError,"Timeout waiting for connection"
- except UserInterrupt as e:
+ except:
serv.close()
- raise e
+ raise
self.isconned = 1
serv.close()
@@ -415,17 +416,16 @@ def listen(self, serv, timeout):
timeout -- Seconds before timeout.
"""
start = time.time()
- try:
- while True:
- if (time.time() - start) > timeout:
- raise socket.timeout
- try:
- vim.eval("getchar(0)")
- return serv.accept()
- except socket.error:
- pass
- except vim.error:
- raise UserInterrupt,"Connection cancelled by user"
+ while True:
+ if (time.time() - start) > timeout:
+ raise socket.timeout
+ try:
+ """Check for user interrupts"""
+ if self.input_stream is not None:
+ self.input_stream.probe()
+ return serv.accept()
+ except socket.error:
+ pass
def close(self):
"""Close the connection."""
@@ -670,6 +670,3 @@ class ResponseError(Exception):
"""An error caused by an unexpected response from the
debugger (e.g. invalid format XML)."""
pass
-
-class UserInterrupt(Exception):
- """Raised when a user interrupts connection wait."""
@@ -241,7 +241,10 @@ def listen(self,server,port,timeout):
check_ide_key = True
if len(ide_key) == 0:
check_ide_key = False
- connection = vdebug.dbgp.Connection(server,port,timeout)
+
+ connection = vdebug.dbgp.Connection(server,port,\
+ timeout,vdebug.util.InputStream())
+
self.api = vdebug.dbgp.Api(connection)
if check_ide_key and ide_key != self.api.idekey:
print "Ignoring debugger connection with IDE key '%s'" \
@@ -114,3 +114,17 @@ def __repr__(self):
class FilePathError(Exception):
pass
+
+class InputStream:
+ """Get a character from Vim's input stream.
+
+ Used to check for keyboard interrupts."""
+
+ def probe(self):
+ try:
+ vim.eval("getchar(0)")
+ except vim.error:
+ raise UserInterrupt
+
+class UserInterrupt(Exception):
+ """Raised when a user interrupts connection wait."""

0 comments on commit 08b997c

Please sign in to comment.