summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grc/base/Connection.py2
-rw-r--r--grc/base/ParseXML.py31
-rw-r--r--grc/gui/PropsDialog.py7
-rw-r--r--grc/python/Generator.py2
4 files changed, 25 insertions, 17 deletions
diff --git a/grc/base/Connection.py b/grc/base/Connection.py
index 3a2de5b9a5..bf3c75277c 100644
--- a/grc/base/Connection.py
+++ b/grc/base/Connection.py
@@ -51,7 +51,7 @@ class Connection(Element):
#ensure that this connection (source -> sink) is unique
for connection in self.get_parent().get_connections():
if connection.get_source() is source and connection.get_sink() is sink:
- raise Exception('This connection between source and sink is not unique.')
+ raise LookupError('This connection between source and sink is not unique.')
self._source = source
self._sink = sink
if source.get_type() == 'bus':
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py
index a2cede1c86..2d5fed0862 100644
--- a/grc/base/ParseXML.py
+++ b/grc/base/ParseXML.py
@@ -41,9 +41,9 @@ def validate_dtd(xml_file, dtd_file=None):
dtd_file: the optional dtd file
@throws Exception validation fails
"""
- #perform parsing, use dtd validation if dtd file is not specified
+ # perform parsing, use dtd validation if dtd file is not specified
+ parser = etree.XMLParser(dtd_validation=not dtd_file)
try:
- parser = etree.XMLParser(dtd_validation=not dtd_file)
xml = etree.parse(xml_file, parser=parser)
except etree.LxmlError:
pass
@@ -101,9 +101,10 @@ def _from_file(xml):
key, value = _from_file(elem).items()[0]
if nested_data.has_key(key): nested_data[key].append(value)
else: nested_data[key] = [value]
- #delistify if the length of values is 1
+ # delistify if the length of values is 1
for key, values in nested_data.iteritems():
- if len(values) == 1: nested_data[key] = values[0]
+ if len(values) == 1:
+ nested_data[key] = values[0]
return odict({tag: nested_data})
@@ -116,15 +117,17 @@ def to_file(nested_data, xml_file):
nested_data: the nested data
xml_file: the xml file path
"""
- # Create the processing instruction from the array
xml_data = ""
instructions = nested_data.pop('_instructions', None)
- if instructions:
+ if instructions: # create the processing instruction from the array
xml_data += etree.tostring(etree.ProcessingInstruction(
- 'grc', ' '.join("{0}='{1}'".format(*item) for item in instructions.iteritems())
- ), xml_declaration=True, pretty_print=True)
- xml_data += etree.tostring(_to_file(nested_data)[0], pretty_print=True)
- open(xml_file, 'w').write(xml_data)
+ 'grc', ' '.join(
+ "{0}='{1}'".format(*item) for item in instructions.iteritems())
+ ), xml_declaration=True, pretty_print=True, encoding='utf-8')
+ xml_data += etree.tostring(_to_file(nested_data)[0],
+ pretty_print=True, encoding='utf-8')
+ with open(xml_file, 'w') as fp:
+ fp.write(xml_data)
def _to_file(nested_data):
@@ -139,12 +142,14 @@ def _to_file(nested_data):
"""
nodes = list()
for key, values in nested_data.iteritems():
- #listify the values if not a list
+ # listify the values if not a list
if not isinstance(values, (list, set, tuple)):
values = [values]
for value in values:
node = etree.Element(key)
- if isinstance(value, (str, unicode)): node.text = value
- else: node.extend(_to_file(value))
+ if isinstance(value, (str, unicode)):
+ node.text = unicode(value)
+ else:
+ node.extend(_to_file(value))
nodes.append(node)
return nodes
diff --git a/grc/gui/PropsDialog.py b/grc/gui/PropsDialog.py
index d301a75dd1..91f7f4ffe9 100644
--- a/grc/gui/PropsDialog.py
+++ b/grc/gui/PropsDialog.py
@@ -161,7 +161,9 @@ class PropsDialog(gtk.Dialog):
for tab, label, vbox in self._params_boxes:
vbox.hide_all()
# empty the params box
- vbox.forall(lambda c: vbox.remove(c) or c.destroy())
+ for child in vbox.get_children():
+ vbox.remove(child)
+ child.destroy()
# repopulate the params box
box_all_valid = True
for param in filter(lambda p: p.get_tab_label() == tab, self._block.get_params()):
@@ -202,7 +204,8 @@ class PropsDialog(gtk.Dialog):
def _handle_response(self, widget, response):
if response in (gtk.RESPONSE_APPLY, gtk.RESPONSE_ACCEPT):
for tab, label, vbox in self._params_boxes:
- vbox.forall(lambda c: c.apply_pending_changes())
+ for child in vbox.get_children():
+ child.apply_pending_changes()
self.set_response_sensitive(gtk.RESPONSE_APPLY, False)
return True
return False
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index a3f9f10fc1..fc1dd56f50 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -129,7 +129,7 @@ class TopBlockGenerator(object):
# when in no gui mode on linux, use a graphical terminal (looks nice)
xterm_executable = find_executable(XTERM_EXECUTABLE)
if self._generate_options == 'no_gui' and xterm_executable:
- cmds = [xterm_executable, '-e'] + cmds
+ cmds = [xterm_executable, '-e'] + ' '.join(cmds)
p = subprocess.Popen(
args=cmds, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,