Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Pynspect
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
713
Mentat
Pynspect
Commits
3af1c01a
Commit
3af1c01a
authored
Mar 20, 2023
by
Radko Krkoš
Browse files
Options
Downloads
Patches
Plain Diff
jpath: Use `x not in y` instead of `not x in y`
parent
36a6055b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pynspect/jpath.py
+9
-9
9 additions, 9 deletions
pynspect/jpath.py
with
9 additions
and
9 deletions
pynspect/jpath.py
+
9
−
9
View file @
3af1c01a
...
...
@@ -242,7 +242,7 @@ def jpath_parse_c(jpath):
references to internal cache. Treat the returned values as read only, or
suffer the consequences.
"""
if
not
jpath
in
_JPATH_CACHE
:
if
jpath
not
in
_JPATH_CACHE
:
_JPATH_CACHE
[
jpath
]
=
jpath_parse
(
jpath
)
return
_JPATH_CACHE
[
jpath
]
...
...
@@ -294,7 +294,7 @@ def jpath_values(structure, jpath):
# Process unindexed nodes.
else
:
# Skip the node, if the key does not exist.
if
not
key
in
node
:
if
key
not
in
node
:
continue
# Handle list values - expand them.
...
...
@@ -338,7 +338,7 @@ def jpath_exists(structure, jpath):
:rtype: bool
"""
result
=
jpath_value
(
structure
,
jpath
)
if
not
result
is
None
:
if
result
is
not
None
:
return
True
return
False
...
...
@@ -375,7 +375,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
idx
=
chnk
[
'
i
'
]
# Automatically create nodes for non-existent keys.
if
not
key
in
current
:
if
key
not
in
current
:
current
[
key
]
=
[]
if
not
isinstance
(
current
[
key
],
list
)
and
not
isinstance
(
current
[
key
],
MutableSequence
):
raise
JPathException
(
"
Expected list-like object under structure key
'
{}
'"
.
format
(
key
))
...
...
@@ -412,7 +412,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
except
(
IndexError
,
TypeError
):
# At this point only deal with unique, overwrite does not make
# sense, because we would not be here otherwise.
if
not
unique
or
not
value
in
current
[
key
]:
if
not
unique
or
value
not
in
current
[
key
]:
current
[
key
].
append
(
value
)
else
:
return
RC_VALUE_DUPLICATE
...
...
@@ -422,7 +422,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
# Detection of the last JPath chunk - node somewhere in the middle.
if
i
!=
size
:
# Automatically create nodes for non-existent keys.
if
not
key
in
current
:
if
key
not
in
current
:
current
[
key
]
=
{}
if
not
isinstance
(
current
[
key
],
dict
)
and
not
isinstance
(
current
[
key
],
Mapping
):
raise
JPathException
(
"
Expected dict-like object under structure key
'
{}
'"
.
format
(
key
))
...
...
@@ -431,7 +431,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
# Detection of the last JPath chunk - node at the end.
else
:
if
overwrite
or
not
key
in
current
:
if
overwrite
or
key
not
in
current
:
current
[
key
]
=
value
else
:
return
RC_VALUE_EXISTS
...
...
@@ -471,7 +471,7 @@ def jpath_unset(structure, jpath):
idx
=
chnk
[
'
i
'
]
# Skip nodes for non-existent keys.
if
not
key
in
node
:
if
key
not
in
node
:
continue
if
not
isinstance
(
node
[
key
],
list
)
and
not
isinstance
(
node
[
key
],
MutableSequence
):
raise
JPathException
(
"
Expected list-like object under structure key
'
{}
'"
.
format
(
key
))
...
...
@@ -507,7 +507,7 @@ def jpath_unset(structure, jpath):
# Detection of the last JPath chunk - node somewhere in the middle.
if
i
!=
size
:
# Skip nodes for non-existent keys.
if
not
key
in
node
:
if
key
not
in
node
:
continue
if
isinstance
(
node
[
key
],
list
):
nodes_b
.
extend
(
node
[
key
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment