Skip to content
Snippets Groups Projects
Commit 3af1c01a authored by Radko Krkoš's avatar Radko Krkoš
Browse files

jpath: Use `x not in y` instead of `not x in y`

parent 36a6055b
No related branches found
No related tags found
No related merge requests found
...@@ -242,7 +242,7 @@ def jpath_parse_c(jpath): ...@@ -242,7 +242,7 @@ def jpath_parse_c(jpath):
references to internal cache. Treat the returned values as read only, or references to internal cache. Treat the returned values as read only, or
suffer the consequences. suffer the consequences.
""" """
if not jpath in _JPATH_CACHE: if jpath not in _JPATH_CACHE:
_JPATH_CACHE[jpath] = jpath_parse(jpath) _JPATH_CACHE[jpath] = jpath_parse(jpath)
return _JPATH_CACHE[jpath] return _JPATH_CACHE[jpath]
...@@ -294,7 +294,7 @@ def jpath_values(structure, jpath): ...@@ -294,7 +294,7 @@ def jpath_values(structure, jpath):
# Process unindexed nodes. # Process unindexed nodes.
else: else:
# Skip the node, if the key does not exist. # Skip the node, if the key does not exist.
if not key in node: if key not in node:
continue continue
# Handle list values - expand them. # Handle list values - expand them.
...@@ -338,7 +338,7 @@ def jpath_exists(structure, jpath): ...@@ -338,7 +338,7 @@ def jpath_exists(structure, jpath):
:rtype: bool :rtype: bool
""" """
result = jpath_value(structure, jpath) result = jpath_value(structure, jpath)
if not result is None: if result is not None:
return True return True
return False return False
...@@ -375,7 +375,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False): ...@@ -375,7 +375,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
idx = chnk['i'] idx = chnk['i']
# Automatically create nodes for non-existent keys. # Automatically create nodes for non-existent keys.
if not key in current: if key not in current:
current[key] = [] current[key] = []
if not isinstance(current[key], list) and not isinstance(current[key], MutableSequence): if not isinstance(current[key], list) and not isinstance(current[key], MutableSequence):
raise JPathException("Expected list-like object under structure key '{}'".format(key)) 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): ...@@ -412,7 +412,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
except (IndexError, TypeError): except (IndexError, TypeError):
# At this point only deal with unique, overwrite does not make # At this point only deal with unique, overwrite does not make
# sense, because we would not be here otherwise. # 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) current[key].append(value)
else: else:
return RC_VALUE_DUPLICATE return RC_VALUE_DUPLICATE
...@@ -422,7 +422,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False): ...@@ -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. # Detection of the last JPath chunk - node somewhere in the middle.
if i != size: if i != size:
# Automatically create nodes for non-existent keys. # Automatically create nodes for non-existent keys.
if not key in current: if key not in current:
current[key] = {} current[key] = {}
if not isinstance(current[key], dict) and not isinstance(current[key], Mapping): if not isinstance(current[key], dict) and not isinstance(current[key], Mapping):
raise JPathException("Expected dict-like object under structure key '{}'".format(key)) 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): ...@@ -431,7 +431,7 @@ def jpath_set(structure, jpath, value, overwrite=True, unique=False):
# Detection of the last JPath chunk - node at the end. # Detection of the last JPath chunk - node at the end.
else: else:
if overwrite or not key in current: if overwrite or key not in current:
current[key] = value current[key] = value
else: else:
return RC_VALUE_EXISTS return RC_VALUE_EXISTS
...@@ -471,7 +471,7 @@ def jpath_unset(structure, jpath): ...@@ -471,7 +471,7 @@ def jpath_unset(structure, jpath):
idx = chnk['i'] idx = chnk['i']
# Skip nodes for non-existent keys. # Skip nodes for non-existent keys.
if not key in node: if key not in node:
continue continue
if not isinstance(node[key], list) and not isinstance(node[key], MutableSequence): if not isinstance(node[key], list) and not isinstance(node[key], MutableSequence):
raise JPathException("Expected list-like object under structure key '{}'".format(key)) raise JPathException("Expected list-like object under structure key '{}'".format(key))
...@@ -507,7 +507,7 @@ def jpath_unset(structure, jpath): ...@@ -507,7 +507,7 @@ def jpath_unset(structure, jpath):
# Detection of the last JPath chunk - node somewhere in the middle. # Detection of the last JPath chunk - node somewhere in the middle.
if i != size: if i != size:
# Skip nodes for non-existent keys. # Skip nodes for non-existent keys.
if not key in node: if key not in node:
continue continue
if isinstance(node[key], list): if isinstance(node[key], list):
nodes_b.extend(node[key]) nodes_b.extend(node[key])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment