def loadFromFile(filePath:str, scmgr = None, structureTypeName:str = None) -> FlexObject: assert isinstance(filePath, str) if bJSONCfgHelperAvailable: if scmgr or structureTypeName: Assert.isIn(scmgr.__class__.__name__, [ "StructureCheckerManager", "jk_jsoncfghelper2.StructureCheckerManager" ]) Assert.isInstance(structureTypeName, str) with open(filePath, "r") as f: data = json.load(f) assert isinstance(data, dict) if scmgr or structureTypeName: checker = scmgr.getE(structureTypeName) if checker.checkB(scmgr, data): return FlexObject(data) else: raise Exception("Data does not match type " + repr(structureTypeName)) # TODO else: return FlexObject(data) else: if (scmgr is not None) or (structureTypeName is not None): raise Exception("As module jk_jsoncfghelper2 is not installed, scmgr and structureTypeName must noe None!") with open(filePath, "r") as f: data = json.load(f) assert isinstance(data, dict) return FlexObject(data)
def _compile_int(scmgr: StructureCheckerManager, x: JDef): Assert.isIn(x.dataType, ["int", "integer"]) #assert x.dataType in [ "int", "integer" ] return IntValueChecker(scmgr, minValue=x.minValue, maxValue=x.maxValue, required=x.required, nullable=x.nullable)
def _compile_anydict(scmgr: StructureCheckerManager, x: JDef): Assert.isIn(x.dataType, ["dict", "dictionary"]) #assert x.dataType in [ "dict", "dictionary" ] return AnyDictionaryValueChecker( scmgr, required=x.required, allowedElementTypes=__compile_allowedElements(scmgr, x.elementTypes), nullable=x.nullable)
def _compile_str(scmgr: StructureCheckerManager, x: JDef): Assert.isIn(x.dataType, ["str", "string"]) #assert x.dataType in [ "str", "string" ] return StringValueChecker(scmgr, minLength=x.minLength, maxLength=x.maxLength, allowedValues=x.allowedValues, required=x.required, nullable=x.nullable)
]], ["|c|*|d", None, []], ["|a|b", None, []], ] for p in PATTERNS: print("NOW PROCESSING:", p) if len(p) == 3: spath, result = FlexDataSelector(p[0]).getOne(dataTree) print("\tspath = " + repr(spath)) print("\tresult = " + repr(result)) if p[1] is None: Assert.isNone(result) Assert.isNone(spath) else: Assert.isInstance(result, p[1]) Assert.isInstance(spath, str) Assert.isIn(spath, p[2]) elif len(p) == 4: spath, result = FlexDataSelector(p[0]).getOne(dataTree) if p[1] is None: Assert.isNone(spath) Assert.isNone(result) else: Assert.isInstance(result, p[1]) Assert.isEqual(result, p[2]) Assert.isInstance(spath, str) Assert.isIn(spath, p[3]) else: raise Exception()
def _compile_bool(scmgr: StructureCheckerManager, x: JDef): Assert.isIn(x.dataType, ["bool", "boolean"]) #assert x.dataType in [ "bool", "boolean" ] return BooleanValueChecker(scmgr, required=x.required, nullable=x.nullable)