Features: Attribute Chain Flattening, Assignment Support, Multiple Expression Support #165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
While working on an SPL command for a Splunk add-on that evaluates Python expressions to process event fields and create new ones, I ran into some limitations with
simpleeval. I made a few changes to support my needs:uri.params. I wanted to use dot notation (uri.params) instead oflog['uri.params']for convenience and readability.... | evalp parsed_url = urlparse(http.uri)... | evalp http.uri = extract_url(http.full_request); http.parsed_uri = parseurl(http.query)These features are off by default, so they won't affect existing behavior. They’re mostly useful for my use case, but feel free to include them if you think they’d be helpful.
Thanks!
Description
Assignment Support
If you want to allow modification of the names dictionary using assignment or augmented assignment (=, +=, etc.), set assign_modify_names=True.
When using the SimpleEval class, updated values are available in the .results attribute:
Note: Assignment to attributes (e.g., a.b = 1) or tuples (e.g., a, b = (1, 2)) is not supported.
Multiple Expressions
By default, only the first expression is evaluated. To evaluate multiple expressions separated by ; or newlines and return the last expression's result, set multiple_expression_support=True.
Combined with assignment:
Attribute Chain Flattening
If attr_chain_flattening=True, then attributes can be treated as flat keys in names.
If both a flat key and an actual attribute exist, the flat key takes precedence:
With assignment enabled, only flat keys are written, as attribute assignment is unsupported:
Pre-approval checklist (for submitter)
Please complete these steps