diff --git a/JsonPreprocessor/CJsonPreprocessor.py b/JsonPreprocessor/CJsonPreprocessor.py index 0f04adc0..6fe6e19b 100644 --- a/JsonPreprocessor/CJsonPreprocessor.py +++ b/JsonPreprocessor/CJsonPreprocessor.py @@ -198,7 +198,8 @@ def __init__(self, syntax: CSyntaxType = CSyntaxType.python , currentCfg : dict self.jsonCheck = {} self.JPGlobals = {} self.pythonTypeError = ["object is not subscriptable", \ - "string indices must be integers"] + "string indices must be integers", \ + "list indices must be integers"] def __getFailedJsonDoc(self, jsonDecodeError=None, areaBeforePosition=50, areaAfterPosition=20, oneLine=True): failedJsonDoc = None @@ -514,7 +515,8 @@ def __getNestedValue(sNestedParam : str): if errorType in str(error): errorMsg = f"Could not resolve expression '{sNestedParam.replace('$$', '$')}'." if errorMsg != '': - errorMsg = errorMsg + f" Reason: {error}" + errorMsg = errorMsg + f" Reason: {error}" if ' or slices' not in str(error) else \ + errorMsg + f" Reason: {str(error).replace(' or slices', '')}" else: errorMsg = f"The parameter '{sNestedParam.replace('$$', '$')}' is not available!" raise Exception(errorMsg) @@ -629,15 +631,7 @@ def __handleDotInNestedParam(sNestedParam : str) -> str: rootVar = re.search(pattern, var[0], re.UNICODE)[0] sRootVar = __handleDotInNestedParam(rootVar) if "." in rootVar else rootVar sVar = var[0].replace(rootVar, sRootVar) - if re.search(r"\[\s*'[\s\-]*\d+\s*'\s*\]", sVar): - try: - tmpValue = __getNestedValue(sVar) - except: - errorMsg = f"{rootVar.replace('$$', '$')} expects integer as index. Got string instead in {sNestedParam}" - self.__reset() - raise Exception(errorMsg) - else: - tmpValue = __getNestedValue(sVar) + tmpValue = __getNestedValue(sVar) if bConvertToStr and (isinstance(tmpValue, list) or isinstance(tmpValue, dict)): dataType = re.sub(r"^.+'([a-zA-Z]+)'.*$", "\\1", str(type(tmpValue))) self.__reset() diff --git a/JsonPreprocessor/JsonPreprocessor.pdf b/JsonPreprocessor/JsonPreprocessor.pdf index b3718102..dedf3330 100644 Binary files a/JsonPreprocessor/JsonPreprocessor.pdf and b/JsonPreprocessor/JsonPreprocessor.pdf differ diff --git a/packagedoc/additional_docs/The JSONP format.tex b/packagedoc/additional_docs/The JSONP format.tex index c33f334b..c5f74fd9 100644 --- a/packagedoc/additional_docs/The JSONP format.tex +++ b/packagedoc/additional_docs/The JSONP format.tex @@ -603,7 +603,7 @@ \section{Overwrite parameters}\label{overwrite-parameters} \vspace{2ex} -Using composite data types inside strings causes errors: +Using composite data types inside strings is not supported: \begin{pythoncode} "newparam6" : "prefix_${listval}_suffix" @@ -615,10 +615,18 @@ \section{Overwrite parameters}\label{overwrite-parameters} "newparam7" : "prefix_${dictval}_suffix" \end{pythoncode} -\textbf{TODO:} \href{https://github.com/test-fullautomation/python-jsonpreprocessor/issues/249}{Parameter substitution needs to be limited} +\vspace{2ex} + +Result for \pcode{"newparam6"}: \vspace{2ex} +\begin{pythonlog} +The substitution of parameter '${listval}' inside the string value 'prefix_${listval}_suffix' is not supported! Composite data types like lists and dictionaries cannot be substituted inside strings. +\end{pythonlog} + +\newpage + \textbf{Value of a single element of a parameter of nested data type} To access an element of a list and a key of a dictionary, we change the content of file \plog{componentB.2.jsonp} to: @@ -998,7 +1006,7 @@ \section{Dynamic key names} \end{pythoncode} The value of \pcode{newparam1} is defined by an expression that is encapsulated in quotes and contains - beneath hard coded parts - a dollar operator expression -that is the dynamic part. +(that is the dynamic part). The same is also possible on the left hand side of the colon. In this case the name of a parameter is created dynamically. @@ -1040,7 +1048,7 @@ \section{Dynamic key names} \vspace{2ex} -This will not work: +This will not work (because of a key with name \pcode{A_2} does not yet exist): \vspace{2ex} @@ -1054,7 +1062,7 @@ \section{Dynamic key names} \textbf{Outcome:} \begin{pythonlog} - +A substitution in key names is not allowed! Please update the key name "${strval}_2" \end{pythonlog}