-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parsing tests and line start matching #132
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,11 @@ def __init__(self, telegram_specification, apply_checksum_validation=True): | |
self.telegram_specification = telegram_specification | ||
# Regexes are compiled once to improve performance | ||
self.telegram_specification_regexes = { | ||
signature: re.compile(signature, re.DOTALL) | ||
signature: re.compile(signature, re.DOTALL | re.MULTILINE) | ||
for signature in self.telegram_specification['objects'].keys() | ||
} | ||
|
||
def parse(self, telegram_data, encryption_key="", authentication_key=""): # noqa: C901 | ||
def parse(self, telegram_data, encryption_key="", authentication_key="", throw_ex=False): # noqa: C901 | ||
""" | ||
Parse telegram from string to dict. | ||
The telegram str type makes python 2.x integration easier. | ||
|
@@ -93,9 +93,14 @@ def parse(self, telegram_data, encryption_key="", authentication_key=""): # noq | |
for match in matches: | ||
try: | ||
dsmr_object = parser.parse(match) | ||
except Exception: | ||
except ParseError: | ||
logger.error("ignore line with signature {}, because parsing failed.".format(signature), | ||
exc_info=True) | ||
if throw_ex: | ||
raise | ||
except Exception as err: | ||
logger.error("Unexpected {}: {}".format(type(err), err)) | ||
raise | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is ok, but only if all the clients that use the TelegramParser will handle the error and keep working after encountering an error. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this a reaction to my comment? |
||
else: | ||
telegram.add(obis_reference=signature, dsmr_object=dsmr_object) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change, but in general when using the logging module i pass the variables as arguments:
Here is a nice blogpost about it https://www.palkeo.com/en/blog/python-logging.html#use-a-format-string-with-arguments
In short: when doing things with the logs (for example Sentry), it allows for better grouping etc