Skip to content

Commit 9988ad1

Browse files
committed
[tools/dictparser] Add show_warnings on load
1 parent 617d24b commit 9988ad1

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

odml/tools/dict_parser.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ class DictReader:
104104
A reader to parse dictionaries with odML content into a proper odML document.
105105
"""
106106

107-
def __init__(self):
107+
def __init__(self, show_warnings=True):
108+
"""
109+
:param show_warnings: Toggle whether to print warnings to the command line.
110+
Any warnings can be accessed via the Reader's class
111+
warnings attribute after parsing is done.
112+
"""
108113
self.parsed_doc = None # Python dictionary object equivalent
114+
self.show_warnings = show_warnings
109115
self.warnings = []
110116

111117
def is_valid_attribute(self, attr, fmt):
@@ -116,8 +122,9 @@ def is_valid_attribute(self, attr, fmt):
116122
return attr
117123

118124
msg = "Invalid element <%s> inside <%s> tag" % (attr, fmt.__class__.__name__)
119-
print(msg)
120125
self.warnings.append(msg)
126+
if self.show_warnings:
127+
print(msg)
121128
return None
122129

123130
def to_odml(self, parsed_doc):

0 commit comments

Comments
 (0)