Skip to content

Commit

Permalink
Fixes for TCL support, with XML namespaces
Browse files Browse the repository at this point in the history
Also, commands not implemented are raised as a specific error.
  • Loading branch information
joonty committed Dec 18, 2012
1 parent 38a3f09 commit d39ff68
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
40 changes: 29 additions & 11 deletions plugin/python/vdebug/dbgp.py
Expand Up @@ -24,17 +24,22 @@ def __parse_error(self):
in the response, then raise it as a DBGPError."""
xml = self.as_xml()
err_el = xml.find('%serror' % self.ns)
code = err_el.get("code")
if code is None:
raise ResponseError(
"Missing error code in response",
self.response)
msg_el = err_el.find('%smessage' % self.ns)
if msg_el is None:
raise ResponseError(
"Missing error message in response",
self.response)
raise DBGPError(msg_el.text,code)
if err_el is None:
raise DBGPError("Could not parse error from return XML",1)
else:
code = err_el.get("code")
if code is None:
raise ResponseError(
"Missing error code in response",
self.response)
elif int(code) == 4:
raise CmdNotImplementedError('Command not implemented')
msg_el = err_el.find('%smessage' % self.ns)
if msg_el is None:
raise ResponseError(
"Missing error message in response",
self.response)
raise DBGPError(msg_el.text,code)

def get_cmd(self):
"""Get the command that created this response."""
Expand All @@ -60,8 +65,17 @@ def as_xml(self):
"""
if self.xml == None:
self.xml = ET.fromstring(self.response)
self.__determine_ns()
return self.xml

def __determine_ns(self):
tag_repr = str(self.xml.tag)
if tag_repr[0] != '{':
raise DBGPError('Invalid or missing XML namespace',1)
else:
ns_parts = tag_repr.split('}')
self.ns = ns_parts[0] + '}'

def __str__(self):
return self.as_string()

Expand Down Expand Up @@ -665,6 +679,10 @@ class DBGPError(Exception):
"""Raised when the debugger returns an error message."""
pass

class CmdNotImplementedError(Exception):
"""Raised when the debugger returns an error message."""
pass

class EvalError(Exception):
"""Raised when some evaluated code is invalid."""
pass
Expand Down
5 changes: 5 additions & 0 deletions plugin/python/vdebug/opts.py
Expand Up @@ -31,6 +31,11 @@ def get(cls,name,as_type = str):
else:
raise OptionsError, "No option with key '%s'" % name

@classmethod
def overwrite(cls,name,value):
inst = cls.inst()
inst.options[name] = value

@classmethod
def isset(cls,name):
"""Checks whether the option exists and is set.
Expand Down
7 changes: 6 additions & 1 deletion plugin/python/vdebug/runner.py
Expand Up @@ -287,7 +287,12 @@ def close_connection(self,stop = True):
vdebug.log.Log("Closing the connection")
if stop:
if vdebug.opts.Options.get('on_close') == 'detach':
self.api.detach()
try:
self.api.detach()
except vdebug.dbgp.CmdNotImplementedError:
self.ui.error('Detach is not supported by the debugger, stopping instead')
vdebug.opts.Options.overwrite('on_close','stop')
self.api.stop()
else:
self.api.stop()
self.api.conn.close()
Expand Down

0 comments on commit d39ff68

Please sign in to comment.