Skip to content

Commit c6857d4

Browse files
committed
[tools/dict_parser] Add err/warn methods
1 parent c1a53ad commit c6857d4

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

odml/tools/dict_parser.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,30 @@ def is_valid_attribute(self, attr, fmt):
197197
return attr
198198

199199
msg = "Invalid element <%s> inside <%s> tag" % (attr, fmt.__class__.__name__)
200+
201+
def error(self, msg):
202+
"""
203+
If the parsers ignore_errors property is set to False, a ParserException
204+
will be raised. Otherwise the message is passed to the parsers warning
205+
method.
206+
207+
:param msg: Error message.
208+
"""
209+
if self.ignore_errors:
210+
return self.warn(msg)
211+
212+
raise ParserException(msg)
213+
214+
def warn(self, msg):
215+
"""
216+
Adds a message to the parsers warnings property. If the parsers show_warnings
217+
property is set to True, an additional error message will be written
218+
to sys.stderr.
219+
220+
:param msg: Warning message.
221+
"""
222+
msg = "warning: %s\n" % msg
223+
200224
self.warnings.append(msg)
201225
if self.show_warnings:
202226
print(msg)

0 commit comments

Comments
 (0)