Skip to content

Commit

Permalink
compiled the regex and made it a constant on Write module
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTremblay committed Mar 29, 2024
1 parent 12cb4b1 commit a9adba2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions BAC0/core/io/Write.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def write()
# some debugging
_debug = 0
_LOG = ModuleLogger(globals())

WRITE_REGEX = r"(?P<address>\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<objId>(@obj_)?[-\w]*[: ]*\d*) (?P<propId>(@prop_)?\w*)[ ]?(?P<value>-*\w*)?[ ]?(?P<indx>-|\d*)?[ ]?(?P<priority>(1[0-6]|[0-9]))?"
write_pattern = re.compile(WRITE_REGEX)

@note_and_log
class WriteProperty:
Expand Down Expand Up @@ -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<address>\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<objId>(@obj_)?[-\w]*[: ]*\d*) (?P<propId>(@prop_)?\w*)[ ]?(?P<value>-*\w*)?[ ]?(?P<indx>-|\d*)?[ ]?(?P<priority>(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")
Expand Down

0 comments on commit a9adba2

Please sign in to comment.