cel-python
cel-python copied to clipboard
Support for RE2
It looks like the implementation of CEL matches, just calls Python re.search but Python re is not the same as RE2 as an example \z in RE2 should match the end of text, but \z in Python re is an invalid escape. The equivalent in Python re is \Z but that maps to an unsupported escape in RE2.
Example
echo '""' | python -m celpy 'string(this).matches("^\\z")'
# Should output true, but instead emits the error "re.error: bad escape \z at position 1"
echo '""' | python -m celpy 'string(this).matches("^\\Z")'
# Should be an error as \Z is not supported in RE2, but instead outputs true
Example of another CEL evaluator rejecting \Z but accepting \z
A pull request to replace re with https://pypi.org/project/re2/ would be welcome.
A pull request to replace re with https://pypi.org/project/re2/ would be welcome.
Done.
Please let me know what your style and testing preference is. I just made a quick scan of the repo before making my PR.
Also, re2 is a pretty old and looks unmaintained. I opted to use google-re2 instead.
There's a tox.ini to run a complete test suite.
The style is generally done by black.
You can also look at the GitHub workflows to see how the tox.ini runs.