crs4 / hl7apy

Python library to parse, create and handle HL7 v2 messages.
http://crs4.github.io/hl7apy/
MIT License
215 stars 85 forks source link

fix: invalid escape sequence #112

Closed olemoign closed 5 months ago

olemoign commented 5 months ago

Normal strings regex produce "SyntaxWarning: invalid escape sequence" for special chars like "\&", "\d" and "\S". Transform those normal strings to raw strings to fix this.

svituz commented 5 months ago

Hi, I'm not sure I'm getting the problem you're trying to solve. Can you provide a snippet that replicates the bug?

olemoign commented 5 months ago

Hi, this is not a huge problem as those are warnings only, so I expect the regex to still work. I think those warnings appeared with python 3.12, as I don't remember seeing them before. I don't know if they appear again during a call to the respective functions, I see them during the start of my app, which imports hl7apy, so this happens during the parsing of the python code.

olemoign commented 5 months ago

The logs:

/usr/local/lib/python3.12/site-packages/hl7apy/exceptions.py:45: SyntaxWarning: invalid escape sequence '\&' """ /usr/local/lib/python3.12/site-packages/hl7apy/parser.py:40: SyntaxWarning: invalid escape sequence '\&' """ /usr/local/lib/python3.12/site-packages/hl7apy/parser.py:637: SyntaxWarning: invalid escape sequence '\S' m = re.match("^MSH(?P\S)", content) /usr/local/lib/python3.12/site-packages/hl7apy/core.py:117: SyntaxWarning: invalid escape sequence '\d' regex = '^z[a-z1-9]{2}_\d+$' /usr/local/lib/python3.12/site-packages/hl7apy/utils.py:116: SyntaxWarning: invalid escape sequence '\d' offset = re.search('\d*((+(1[0-4]|0[0-9])|(-(1[0-2]|0[0-9])))([0-5][0-9]))$', value)

olemoign commented 5 months ago

I think the first two logs are linked to DEFAULT_ENCODING_CHARS but I couldn't test it.

svituz commented 5 months ago

thanks