-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updated pagination for jmespath result_key
s.
#232
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
|
||
from .exceptions import InvalidExpressionError | ||
|
||
|
||
def normalize_url_path(path): | ||
if not path: | ||
|
@@ -57,3 +59,35 @@ def remove_dot_segments(url): | |
output.append(url[:next_slash]) | ||
url = url[next_slash:] | ||
return ''.join(output) | ||
|
||
|
||
def exp_set(source, expression, value, is_first=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this to something more descriptive? It's hard to tell what this does based on the name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will rename. |
||
# This takes a (limited) jmespath-like expression & can set a value based | ||
# on it. | ||
# Limitations: | ||
# * Only handles dotted lookups | ||
# * No offsets/wildcards/slices/etc. | ||
if is_first: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I'm pulling it out & shuffling tests now. |
||
for invalid in ['[', ']', '*']: | ||
if invalid in expression: | ||
raise InvalidExpressionError(expression=expression) | ||
|
||
exp_bits = expression.split('.') | ||
current_key = exp_bits[0] | ||
remainder = '.'.join(exp_bits[1:]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aren't these three lines the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, same. Will change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm. Actually, not quite. |
||
|
||
if not current_key: | ||
raise InvalidExpressionError(expression=expression) | ||
|
||
if len(exp_bits) > 1: | ||
if not current_key in source: | ||
# We've got something in the expression that's not present in the | ||
# source (new key). If there's any more bits, we'll set the key with | ||
# an empty dictionary. | ||
source[current_key] = {} | ||
|
||
return exp_set(source[current_key], remainder, value, is_first=False) | ||
|
||
# If we're down to a single key, set it. | ||
source[current_key] = value | ||
return True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, what's the significance of the return value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly habit. In implementing things in the past, having a meaningful return value is nice to have, especially as complexity changes over time (i.e. more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, this was a miss on my part, we should not be setting any key names to
k.expression
, we should be usingset_value_from_jmespath
. For example if you runaws rds describe-engine-default-parameters --db-parameter-group-family mysql5.1
you'll see that the result is:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah, sorry. :( I could get to this over the weekend, if that helps. The test I added is probably wrong too.