From a9adba2f5aa4b6992eb2fd058bcea8dd15a3345d Mon Sep 17 00:00:00 2001 From: "Christian Tremblay, ing." Date: Fri, 29 Mar 2024 13:46:41 -0400 Subject: [PATCH] compiled the regex and made it a constant on Write module --- BAC0/core/io/Write.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/BAC0/core/io/Write.py b/BAC0/core/io/Write.py index a5644536..7562003c 100644 --- a/BAC0/core/io/Write.py +++ b/BAC0/core/io/Write.py @@ -54,7 +54,8 @@ def write() # some debugging _debug = 0 _LOG = ModuleLogger(globals()) - +WRITE_REGEX = r"(?P
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b|(\b\d+:\d+\b)) (?P(@obj_)?[-\w]*[: ]*\d*) (?P(@prop_)?\w*)[ ]?(?P-*\w*)?[ ]?(?P-|\d*)?[ ]?(?P(1[0-6]|[0-9]))?" +write_pattern = re.compile(WRITE_REGEX) @note_and_log class WriteProperty: @@ -132,8 +133,8 @@ def _parse_wp_args(cls, args): Utility to parse the string of the request. Supports @obj_ and @prop_ syntax for objest type and property id, useful with proprietary objects and properties. """ - pattern = r"(?P
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b|(\b\d+:\d+\b)) (?P(@obj_)?[-\w]*[: ]*\d*) (?P(@prop_)?\w*)[ ]?(?P-*\w*)?[ ]?(?P-|\d*)?[ ]?(?P(1[0-6]|[0-9]))?" - match = re.search(pattern, args) + global write_pattern + match = write_pattern.search(args) try: address = match.group("address") objId = match.group("objId")