コード例 #1
0
#!/usr/bin/python3

import jk_flexdata

x = jk_flexdata.FlexObject({"a": [{"b": "c"}]})

print("****************")

print(">>0")
print(x)
print(">>1")
print(x.a[0])
print(">>2")
print(x.a[0].b)
print(">>3")
print(x.b)
print(">>4")

print("****************")

print(">>4")
x.a[0] = 5
print(">>5")
print(x.a[0])
print(">>6")
print(x)
print(">>7")
x.b = 3
print(">>8")
print(x)
print(">>9")
コード例 #2
0
ファイル: PyPineXModuleInfo.py プロジェクト: jkpubsrc/PyPine
 def __init__(self, dirPath: str, jInfo: dict):
     self.name = os.path.basename(dirPath)
     self.pypiorgName = self.name.replace("_", "-")
     self.dirPath = dirPath
     self.meta = jk_flexdata.FlexObject(jInfo["meta"])
     self.compatibility = jk_flexdata.FlexObject(jInfo["compatibility"])
コード例 #3
0
def toV(value,
        dataType: str = None,
        defaultType: str = None) -> jk_flexdata.FlexObject:
    if dataType is None:
        # autodetect type
        if value is None:
            # try to accept the default type
            if defaultType is None:
                raise Exception("Value is None and default type is not set!")
            assert defaultType in [
                "int", "str", "bool", "float", "int[]", "str[]", "float[]",
                "tempc", "timestamputc", "timestamp", "duration", "bytes",
                "freq", "secsdiff"
            ]
            dataType = defaultType
        elif isinstance(value, bool):
            dataType = "bool"
        elif isinstance(value, int):
            dataType = "int"
        elif isinstance(value, float):
            dataType = "float"
        elif isinstance(value, str):
            dataType = "str"
        elif isinstance(value, list):
            nCountStr = 0
            nCountInt = 0
            nCountFloat = 0
            for item in value:
                if isinstance(item, float):
                    nCountFloat += 1
                elif isinstance(item, int):
                    nCountInt += 1
                elif isinstance(item, str):
                    nCountStr += 1
                else:
                    raise Exception("Unknown list item data type: " +
                                    repr(type(item)))
            if nCountInt == nCountFloat == nCountStr == 0:
                # assume it is a string lst
                dataType = "str[]"
            elif (nCountInt * nCountFloat !=
                  0) or (nCountInt * nCountStr !=
                         0) or (nCountFloat * nCountStr != 0):
                raise Exception("List with mixed item types!")
            else:
                if nCountFloat > 0:
                    dataType = "float[]"
                elif nCountInt > 0:
                    dataType = "int[]"
                else:
                    dataType = "str[]"
        else:
            raise Exception("Unknown data type: " + repr(type(value)))

    else:
        # type has been specified
        if value is None:
            # accept the type as it is
            pass
        elif dataType == "bool":
            Assert.isInstance(value, bool)
        elif dataType == "int":
            Assert.isInstance(value, int)
        elif dataType == "float":
            Assert.isInstance(value, float)
        elif dataType == "str":
            Assert.isInstance(value, str)
        elif dataType == "tempc":
            Assert.isInstance(value, (int, float))
        elif dataType == "timestamputc":
            if isinstance(value, datetime.datetime):
                value = value.timestamp()
            else:
                Assert.isInstance(value, (int, float))
        elif dataType == "timestamp":
            if isinstance(value, datetime.datetime):
                value = value.timestamp()
            else:
                Assert.isInstance(value, (int, float))
        elif dataType == "duration":
            Assert.isInstance(value, (int, float))
        elif dataType == "bytes":
            Assert.isInstance(value, int)
        elif dataType == "freq":
            Assert.isInstance(value, (int, float))
        elif dataType == "secsdiff":
            Assert.isInstance(value, (int, float))
        else:
            raise Exception("Invalid data type: " + repr(dataType))

    return jk_flexdata.FlexObject({"dt": dataType, "v": value})
コード例 #4
0
 def toFlexObj(self) -> jk_flexdata.FlexObject:
     return jk_flexdata.FlexObject(self.toJSON())
コード例 #5
0
#!/usr/bin/python3

import jk_flexdata
import jk_infodatatree

msg = jk_infodatatree.DictTextMessage("abc{{|asd}}def{{name}}ghi", None)

dataTree1 = jk_flexdata.FlexObject({
    "asd": {
        "dt": "int",
        "v": 123,
    },
})
dataTree2 = jk_flexdata.FlexObject({
    "asd": None,
})

result1 = msg.format(dataTree1, {})

print(repr(result1))
assert result1 == "abc123def???ghi"

result2 = msg.format(
    dataTree1, {
        "name": jk_infodatatree.DictValue({
            "dt": "str",
            "v": "FOO",
        }, None, None),
    })

print(repr(result2))
コード例 #6
0
        logMsgFormatter=jk_logging.COLOR_LOG_MESSAGE_FORMATTER,
        printToStdErr=True)
else:
    log = jk_logging.ConsoleLogger.create(printToStdErr=True)

bSuccess = True

if parsedArgs.optionData["stdin"]:
    line = sys.stdin.readline()
    jsonData = json.loads(line)
else:
    for filePath in parsedArgs.programArgs:
        jsonData = jk_json.loadFromFile(filePath)

extractionPath = parsedArgs.optionData.get("extractionPath")
if extractionPath:
    assert isinstance(extractionPath, jk_flexdata.FlexDataSelector)
    _, result = extractionPath.getOne(jk_flexdata.FlexObject(jsonData))
    jsonData = result
    if isinstance(jsonData, jk_flexdata.FlexObject):
        jsonData = jsonData._toDict()

if isinstance(jsonData, str):
    retLine = "-" * 160
    ret2 = jsonData.encode("utf-8").decode('unicode_escape')
    print("\n".join([retLine, ret2, retLine]))
else:
    jk_json.prettyPrint(jsonData)

sys.exit(0 if bSuccess else 1)
コード例 #7
0


print()

mgr = jk_typo3.Typo3InstallationMgr(TYPO3_DIR_PATH)

print("Installed version: " + str(mgr.getVersion()))

print()

print("Site name: " + repr(mgr.getSiteName()))

print()

typo3Settings = jk_flexdata.FlexObject(mgr.getLocalSettings())
dbSettings = typo3Settings.DB.Connections.Default
assert dbSettings.driver == "mysqli"

print("dbHost = " + repr(dbSettings.host))
print("dbPort = " + repr(dbSettings.port))
print("dbName = " + repr(dbSettings.dbname))
print("dbUser = "******"dbPassword = " + repr(dbSettings.password))

print()




コード例 #8
0
#!/usr/bin/python3

import jk_flexdata

#
# This test checks for a bug. It this program terminates and does not get into an endless loop, everything is okay.
#

x = jk_flexdata.FlexObject({"a": []})

print("****************")

print(type(x.a))
for a in x.a:
    print(a)

print("****************")

print(type(x.b))
for a in x.b:
    print(a)

print("****************")