Made app_sdk loop parser more stable. Still missing recursion.

This commit is contained in:
frikky
2020-06-27 08:02:29 +02:00
parent 366d14a3e8
commit dfc639c92b
2 changed files with 84 additions and 30 deletions
+10 -4
View File
@@ -386,18 +386,20 @@ class AppBase:
except json.decoder.JSONDecodeError as e:
return baseresult
# This whole thing should be recursive.
try:
cnt = 0
for value in parsersplit[1:]:
cnt += 1
print("VALUE: %s" % value)
if value == "#":
# FIXME - not recursive - should go deeper if there are more #
print("HANDLE RECURSIVE LOOP OF %s" % basejson)
returnlist = []
try:
for innervalue in basejson:
print("Value: %s" % value[parsersplit[cnt+1]])
print("Value: %s" % innervalue[parsersplit[cnt+1]])
returnlist.append(innervalue[parsersplit[cnt+1]])
except IndexError as e:
print("Indexerror inner: %s" % e)
@@ -410,8 +412,7 @@ class AppBase:
print("INDEXVAL: ", indexvalue)
return indexvalue
except TypeError as e:
print("Inner TypeError: %s" % e)
return basejson
print("TypeError inner: %s" % e)
# Example format: ${[]}$
parseditem = "${%s%s}$" % (parsersplit[cnt+1], json.dumps(returnlist))
@@ -419,6 +420,10 @@ class AppBase:
return parseditem
else:
print("BEFORE NORMAL VALUE: ", basejson, value)
if len(value) == 0:
return basejson
if isinstance(basejson[value], str):
print(f"LOADING STRING '%s' AS JSON" % basejson[value])
try:
@@ -436,13 +441,14 @@ class AppBase:
return basejson
def parse_params(action, fullexecution, parameter):
# Skip if it starts with $?
jsonparsevalue = "$."
# Matches with space in the first part, but not in subsequent parts.
# JSON / yaml etc shouldn't have spaces in their fields anyway.
match = ".*?([$]{1}([a-zA-Z0-9 _-]+\.?){1}([a-zA-Z0-9_-]+\.?){0,})"
match = ".*?([$]{1}([a-zA-Z0-9 _-]+\.?){1}([a-zA-Z0-9#_-]+\.?){0,})"
# Regex to find all the things
if parameter["variant"] == "STATIC_VALUE":
File diff suppressed because one or more lines are too long