Skip to content

Commit

Permalink
Allowance for WILDCARD anywhere within vocab check
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-hampton committed Nov 28, 2022
1 parent 67a0d6f commit 1d75c78
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions checksit/cvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@ def lookup(self, vocab_lookup):
vocab_lookup = re.sub(f"^{vocabs_prefix}:", "", vocab_lookup)

for i,key in enumerate(vocab_lookup.split(":")):
if key in WILDCARD:
if i+1 != len(vocab_lookup.split(":")):
raise ValueError(f"WILDCARD {key} only allowed as last argument")
if isinstance(obj, dict) or i == 0:
if key in WILDCARD:
if i+1 != len(vocab_lookup.split(":")):
obj = [ obj[key] for key in obj.keys() ]
else:
# WILDCARD used as last option, just get keys
obj = list(obj.keys())
else:
obj = list(obj.keys())
obj = obj[key]
else:
obj = obj[key]
if not isinstance(obj,list):
# sanity check
raise ValueError(f"Confused how we got here, obj = {obj}")
elif key in WILDCARD:
raise ValueError(f"Second WILDCARD ({WILDCARD}) in query {vocab_lookup} not allowed")
else:
# obj should be list of dicts, creating list of values or dicts
obj = [ d[key] for d in obj ]

return obj

Expand Down

0 comments on commit 1d75c78

Please sign in to comment.