Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions JsonPreprocessor/CJsonPreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CNameMangling(Enum):
DUPLICATEDKEY_01 = "__handleDuplicatedKey__"
DUPLICATEDKEY_02 = "__RecursiveInitialValue__"
STRINGCONVERT = "__ConvertParameterToString__"
LISTINDEX = "__IndexOfList__"

class CPythonJSONDecoder(json.JSONDecoder):
"""
Expand Down Expand Up @@ -367,19 +368,9 @@ def __referVarHandle(referVar : str, sInputStr : str) -> str:
sInputStr = re.sub('\$\${\s*([^\}]*)\s*}', sParam, sInputStr)
referVar = re.findall('(\$\${\s*.*?\s*})', sInputStr)[0]
tmpReferVar = re.sub("\$", "\\$", referVar)
pattern = '(' + tmpReferVar + '\s*\[+\s*.*?\s*\]+)'
variable = re.findall(pattern, sInputStr)
if variable == []:
return referVar
else:
fullVariable = variable[0]
while variable != []:
pattern = pattern[:-1] + '\[\s*.*?\s*\])'
variable = re.findall(pattern, sInputStr)
if variable != []:
fullVariable = variable[0]
referVar = fullVariable
return referVar
pattern = '(' + tmpReferVar + '\s*(\[+\s*.*?\s*\]+)*)'
variable = re.search(pattern, sInputStr)
return variable[0]

pattern = "\$\${\s*[0-9A-Za-z_]+[0-9A-Za-z\.\-_]*\s*}"
referVars = re.findall("(" + pattern + ")", sInputStr)
Expand Down Expand Up @@ -588,7 +579,8 @@ def __jsonUpdated(k, v, oJson, bNested, keyNested = ''):

def __loadNestedValue(initValue: str, sInputStr: str, bKey=False, key=''):
varPattern = "\${\s*[0-9A-Za-z_]+[0-9A-Za-z\.\-_]*\s*}"
dictPattern = "(\[+\s*'[^\$\[\]\(\)]+'\s*\]+|\[+\s*\d+\s*\]+|\[+\s*" + varPattern + ".*\]+)*"
indexPattern = "\[\s*-*\d*\s*:\s*-*\d*\s*\]"
dictPattern = "(\[+\s*'[^\$\[\]\(\)]+'\s*\]+|\[+\s*\d+\s*\]+|\[+\s*" + varPattern + ".*\]+)*|" + indexPattern
pattern = varPattern + dictPattern
bStringValue = False
bValueConvertString = False
Expand Down Expand Up @@ -649,16 +641,19 @@ def __loadNestedValue(initValue: str, sInputStr: str, bKey=False, key=''):
pattern = "\${\s*[0-9A-Za-z_]+[0-9A-Za-z\.\$\{\}\-_]*\s*}(\[+\s*'.+'\s*\]+|\[+\s*\d+\s*\]+)*"
for k, v in tmpJson.items():
keyNested = ''
bStrConvert = False
if CNameMangling.DUPLICATEDKEY_00.value in k:
del oJson[k]
k = k.replace(CNameMangling.DUPLICATEDKEY_00.value, '')
oJson[k] = v
if re.search("(str\(" + pattern + "\))", k.lower()):
bStrConvert = True
keyNested = k
bNested = True
while "${" in k:
k = __loadNestedValue(keyNested, k, bKey=True, key=keyNested)
elif CNameMangling.STRINGCONVERT.value in k:
bStrConvert = True
del oJson[k]
k = k.replace(CNameMangling.STRINGCONVERT.value, '')
oJson[k] = v
Expand Down Expand Up @@ -714,7 +709,7 @@ def __loadNestedValue(initValue: str, sInputStr: str, bKey=False, key=''):
v = __loadNestedValue(initValue, v)

__jsonUpdated(k, v, oJson, bNested, keyNested)
if keyNested != '':
if keyNested != '' and not bStrConvert:
self.dUpdatedParams.update({k:v})
del tmpJson
return oJson, bNested
Expand Down Expand Up @@ -755,15 +750,14 @@ def __recursiveNestedHandling(sInputStr: str, lNestedParam: list) -> str:
return sInputStr

variablePattern = "[0-9A-Za-z_]+[0-9A-Za-z\.\-_]*"
dictPattern = "\[+\s*'.+'\s*\]+|\[+\s*\d+\s*\]+|\[+\s*\${\s*" + variablePattern + "\s*}.*\]+"
indexPattern = "\[\s*-*\d*\s*:\s*-*\d*\s*\]"
dictPattern = "\[+\s*'.+'\s*\]+|\[+\s*\d+\s*\]+|\[+\s*\${\s*" + variablePattern + "\s*}.*\]+|" + indexPattern
nestedPattern = "\${\s*" + variablePattern + "(\${\s*" + variablePattern + "\s*})*" + "\s*}(" + dictPattern +")*"
valueStrPattern = "[\"|\']\s*[0-9A-Za-z_\-\s*]+[\"|\']"
valueNumberPattern = "[0-9\.]+"

if "${" in sInputStr:
if re.match("^\s*" + nestedPattern + "\s*,*\]*}*\s*$", sInputStr.lower()):
dictPattern = "\[+\s*'.+'\s*\]+|\[+\s*\d+\s*\]+|\[+\s*\${\s*" + variablePattern + "\s*}.*\]+"
nestedPattern = "\${\s*" + variablePattern + "(\${\s*" + variablePattern + "\s*})*" + "\s*}(" + dictPattern +")*"
sInputStr = re.sub("(" + nestedPattern + ")", "\"\\1\"", sInputStr)
nestedParam = re.sub("^\s*\"(.+)\"\s*.*$", "\\1", sInputStr)
self.lNestedParams.append(nestedParam)
Expand Down Expand Up @@ -1008,6 +1002,10 @@ def __removeDuplicatedKey(dInput : dict) -> dict:
raise Exception(f"Invalid parameter format in line: {line.strip()}")
tmpList = re.findall("(\"[^\"]+\")", line)
line = re.sub("(\"[^\"]+\")", CNameMangling.COLONS.value, line)
indexPattern = "\[\s*-*\d*\s*:\s*-*\d*\s*\]"
if re.search(indexPattern, line):
indexList = re.findall(indexPattern, line)
line = re.sub("(" + indexPattern + ")", CNameMangling.LISTINDEX.value, line)
items = re.split("\s*:\s*", line)
newLine = ""
i=0
Expand All @@ -1020,6 +1018,10 @@ def __removeDuplicatedKey(dInput : dict) -> dict:
while CNameMangling.COLONS.value in item:
item = re.sub(CNameMangling.COLONS.value, tmpList[0], item, count=1)
tmpList.pop(0)
elif CNameMangling.LISTINDEX.value in item:
while CNameMangling.LISTINDEX.value in item:
item = re.sub(CNameMangling.LISTINDEX.value, indexList[0], item, count=1)
indexList.pop(0)
i+=1
newSubItem = ""
if re.search("^\s*\[.+\]\s*,*\s*$", item) and item.count('[')==item.count(']'):
Expand Down
Binary file modified JsonPreprocessor/JsonPreprocessor.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion JsonPreprocessor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
# Version and date of JsonPreprocessor
#
VERSION = "0.3.1"
VERSION_DATE = "28.11.2023"
VERSION_DATE = "14.12.2023"

17 changes: 11 additions & 6 deletions config/robotframework_aio/release_items_JsonPreprocessor.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@

"RELEASES" : {
"0.9." : [
"JsonPreprocessor change 0.9 A",
"JsonPreprocessor change 0.9 B",
"JsonPreprocessor change 0.9 X"
"JsonPreprocessor change 0.9 Implicit creation of data structures",
"JsonPreprocessor change 0.9 Dotdict feature bug fixing",
"JsonPreprocessor change 0.9 Update nested parameters handling in key name and value",
"JsonPreprocessor change 0.9 Nested parameter feature bug fixing",
"JsonPreprocessor change 0.9 Nested parameters substitution and overwriting improvement",
"JsonPreprocessor change 0.9 Jsonp file path computation improvement"
],
"0.10." : [
"JsonPreprocessor change 0.10 A",
"JsonPreprocessor change 0.10 B",
"JsonPreprocessor change 0.10 X"
"JsonPreprocessor change 0.10 Add jsonDump method to write a file in JSON format",
"JsonPreprocessor change 0.10 Improve nested parameter format",
"JsonPreprocessor change 0.10 Improve error message log",
"JsonPreprocessor change 0.10 Fix bugs of data structures implicitly",
"JsonPreprocessor change 0.10 Improve index handling together with nested parameters"
]
}
}
5 changes: 3 additions & 2 deletions packagedoc/additional_docs/History.tex
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
- Nested parameters substitution and overwriting improvement\newline
- Jsonp file path computation improvement}

\historyversiondate{0.3.1}{11/2023}
\historyversiondate{0.3.1}{12/2023}
\historychange{- Add jsonDump method to write a file in JSON format\newline
- Improve nested parameter format\newline
- Improve error message log\newline
- Fix bugs of data structures implicitly}
- Fix bugs of data structures implicitly\newline
- Improve index handling together with nested parameters}

\end{packagehistory}