Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8bb305e

Browse files
committed
Merge pull request MAECProject#57 from MAECProject/output_options
Output Options
2 parents 8e43f15 + 18fe8c7 commit 8bb305e

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

maec/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,21 @@ def to_xml_file(self, filename, namespace_dict=None, custom_header=None):
4646
elif not namespace_dict and hasattr(self, '__input_namespaces__'):
4747
namespace_dict = self.__input_namespaces__
4848
out_file = open(filename, 'w')
49-
if custom_header:
49+
out_file.write("<?xml version='1.0' encoding='UTF-8'?>\n")
50+
# Write out the custom header, if included
51+
if isinstance(custom_header, list):
5052
for line in custom_header:
5153
out_file.write[line]
52-
else:
53-
out_file.write("<?xml version='1.0' encoding='UTF-8'?>\n")
54+
elif isinstance(custom_header, dict):
55+
out_file.write("<!--\n")
56+
for key, value in custom_header.iteritems():
57+
sanitized_key = str(key).replace("-->", "\\-\\->")
58+
sanitized_value = str(value).replace("-->", "\\-\\->")
59+
out_file.write(sanitized_key + ": " + sanitized_value + "\n")
60+
out_file.write("-->\n")
61+
elif isinstance(custom_header, basestring):
62+
out_file.write(custom_header)
63+
5464
self.to_obj().export(out_file.write, 0, namespacedef_ = self._get_namespace_def(namespace_dict))
5565
out_file.close()
5666

maec/misc/options.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ class ScriptOptions(object):
1919
def __init__(self):
2020
self.deduplicate_bundles = False
2121
self.dereference_bundles = False
22-
self.normalize_bundles = False
22+
self.normalize_bundles = False
23+
24+
def to_dict(self):
25+
return {
26+
"deduplicate_bundles": self.deduplicate_bundles,
27+
"dereference_bundles": self.dereference_bundles,
28+
"normalize_bundles": self.normalize_bundles
29+
}

0 commit comments

Comments
 (0)