[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 04/06: grc: clean-up ParseXML
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 04/06: grc: clean-up ParseXML |
Date: |
Sun, 14 Jun 2015 16:34:14 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch maint
in repository gnuradio.
commit 6c34b527cb4e083b4806c1e34e5503639591f8b7
Author: Sebastian Koslowski <address@hidden>
Date: Tue Jun 2 16:13:36 2015 +0200
grc: clean-up ParseXML
---
grc/base/ParseXML.py | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/grc/base/ParseXML.py b/grc/base/ParseXML.py
index a2cede1..c9dbccf 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,16 @@ 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())
+ '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)
+ with open(xml_file, 'w') as fp:
+ fp.write(xml_data)
def _to_file(nested_data):
@@ -139,12 +141,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 = value
+ else:
+ node.extend(_to_file(value))
nodes.append(node)
return nodes
- [Commit-gnuradio] [gnuradio] branch maint updated (e8165e7 -> 1ff0e74), git, 2015/06/14
- [Commit-gnuradio] [gnuradio] 03/06: grc: better Popen argument handling for CLI based apps, git, 2015/06/14
- [Commit-gnuradio] [gnuradio] 05/06: grc: save grc files utf-8 encoded (#792), git, 2015/06/14
- [Commit-gnuradio] [gnuradio] 01/06: grc: stop using gtk forall() (#793), git, 2015/06/14
- [Commit-gnuradio] [gnuradio] 02/06: grc: fix file load error when connections are not unique (#794), git, 2015/06/14
- [Commit-gnuradio] [gnuradio] 06/06: Merge remote-tracking branch 'gnuradio-wg-grc/maint_grcwg' into maint, git, 2015/06/14
- [Commit-gnuradio] [gnuradio] 04/06: grc: clean-up ParseXML,
git <=