Skip to content

Commit

Permalink
Remove deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelboulton committed Jan 27, 2024
1 parent beec56e commit bb542b7
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions tavern/_core/dict_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import contextlib
import functools
import logging
import os
Expand Down Expand Up @@ -194,72 +193,11 @@ def recurse_access_key(data: dict | list[str] | Mapping, query: str):
try:
from_jmespath = jmespath.search(query, data)
except jmespath.exceptions.ParseError as e:
logger.error("Error parsing JMES query")

try:
_deprecated_recurse_access_key(data, query.split(".")) # type:ignore
except (IndexError, KeyError):
logger.debug("Nothing found searching using old method")
else:
# If we found a key using 'old' style searching
logger.warning(
"Something was found using 'old style' searching in the response - please change the query to use jmespath instead - see http://jmespath.org/ for more information"
)

raise exceptions.JMESError("Invalid JMES query") from e

return from_jmespath


def _deprecated_recurse_access_key(current_val: Mapping | list, keys: list[str]):
"""Given a list of keys and a dictionary, recursively access the dicionary
using the keys until we find the key its looking for
If a key is an integer, it will convert it and use it as a list index
Example:
>>> _deprecated_recurse_access_key({"a": "b"}, ["a"])
'b'
>>> _deprecated_recurse_access_key({"a": {"b": ["c", "d"]}}, ["a", "b", "0"])
'c'
Args:
current_val: current dictionary we have recursed into
keys: list of str/int of subkeys
Raises:
IndexError: list index not found in data
KeyError: dict key not found in data
Returns:
value of subkey in dict
"""
logger.debug("Recursively searching for '%s' in '%s'", keys, current_val)

if not keys:
return current_val
else:
current_key: str | int = keys.pop(0)

with contextlib.suppress(ValueError):
current_key = int(current_key)

try:
return _deprecated_recurse_access_key(
current_val[current_key], # type:ignore
keys,
)
except (IndexError, KeyError, TypeError) as e:
logger.error(
"%s accessing data - looking for '%s' in '%s'",
type(e).__name__,
current_key,
current_val,
)
raise


def deep_dict_merge(initial_dct: dict, merge_dct: Mapping) -> dict:
"""Recursive dict merge. Instead of updating only top-level keys,
dict_merge recurses down into dicts nested to an arbitrary depth
Expand Down

0 comments on commit bb542b7

Please sign in to comment.