def __performPOSTRequest(self, apiCmd:str, jData:dict):
		assert isinstance(apiCmd, str)
		assert isinstance(jData, dict)

		targetURL = self.__basUrl + apiCmd

		print("=" * 160)
		print("==== " + targetURL)

		if self.__sid:
			jData["sid"] = self.__sid

		for line in json.dumps(jData, indent="\t", sort_keys=True).split("\n"):
			print("¦>> " + line)

		r = requests.post(targetURL, json=jData)
		if r.status_code != 200:
			raise Exception("errResponse")

		jData = r.json()

		for line in jk_json.dumps(jData, indent="\t", sort_keys=True).split("\n"):
			print("<<¦ " + line)

		if not isinstance(jData, dict):
			raise Exception("errResponse")

		if "success" not in jData:
			jk_json.prettyPrint(jData)
			raise Exception("errResponse")

		return jData["data"]
Example #2
0
def test2():
    try:

        a = 0
        b = 5 / a

    except Exception as ee1:
        try:

            assert False

        except Exception as ee:
            etype_, value_, traceback_ = sys.exc_info()
            print(">>X>>>>X>>>>X>>>>X>>")
            #t = traceback.TracebackException(type(value_), value_, traceback_, limit=None)
            #print(traceback.format_exception(etype_, value_, traceback_))
            #print(t.exc_traceback)
            stackTraceList = traceback.extract_tb(traceback_)
            print(stackTraceList)
            print(">>X>>>>X>>>>X>>>>X>>")

            # store as JSON
            jsonData = parseException(ee).toJSON()
            # now let's output that JSON data
            jk_json.prettyPrint(jsonData)
            # now a test to parse JSON
            obj = ExceptionObject.fromJSON(jsonData)
Example #3
0
async def main(ipAddresses: typing.Union[list, tuple]):
    ret = await jk_trioping.multiPing(ipAddresses)
    if parsedArgs.optionData["output-format"] == "json":
        jk_json.prettyPrint(ret)
    else:
        table = jk_console.SimpleTable()
        table.addRow("IP Address", "Ping").hlineAfterRow = True
        for key in sorted(ret.keys()):
            value = ret[key]
            table.addRow(key, "-" if value is None else (str(value) + " ms"))
        table.print()
Example #4
0
#!/usr/bin/python3

import jk_pypiorgapi
import jk_json

api = jk_pypiorgapi.PyPiOrgAPI()

jData = api.getPackageInfoJSON("jk_pypiorgapi")

jk_json.prettyPrint(jData)
Example #5
0
#!/usr/bin/python3

import jk_sysinfo

import jk_json

#jk_sysinfo.enableDebugging()

result = jk_sysinfo.get_proc_load_avg()
print()
jk_json.prettyPrint(result)
print()
	sys.exit(0)
"""

if parsedArgs.optionData["color"]:
    log = jk_logging.ConsoleLogger.create(
        logMsgFormatter=jk_logging.COLOR_LOG_MESSAGE_FORMATTER,
        printToStdErr=True)
else:
    log = jk_logging.ConsoleLogger.create(printToStdErr=True)

bSuccess = True

ret = {}
for opt in ALL_SYSINFO_OPTIONS:
    if parsedArgs.optionData[opt.longOption]:
        try:
            ret[opt.longOption] = opt.run(None)
        except Exception as ee:
            # there has been an error
            ret[opt.longOption] = None
            # log.error("Failed to retrieve data for: " + opt.longOption)
            log.exception(ee)

if not ret:
    ap.showHelp()
    sys.exit(0)

jk_json.prettyPrint(ret)

sys.exit(0 if bSuccess else 1)
Example #7
0
#!/usr/bin/python3

import jk_etcpasswd

import jk_json

#
# If testing is enabled the objects will verify that the data reproduced from parsed data right after parsing matches the actual content of the files.
#
# Please note that these classes will order the groups a user is assigned to. If the order in the credential files is not alphabetical an error will
# occure as then the output generated will not match the input.
#
# As this test feature is only ment to verify correctness of the implementation and not ment to be used in real world scenarios no more
# sophisticated test logic has been implemented.
#

bTest = False

pwdFile = jk_etcpasswd.PwdFile(bTest=bTest)
jk_json.prettyPrint(pwdFile.toJSON())

print()
print()
print()

grpFile = jk_etcpasswd.GrpFile(bTest=bTest)
jk_json.prettyPrint(grpFile.toJSON())
#!/usr/bin/python3

import time
import threading

import jk_json

from jk_appmonitoring import *


def threadRun():
    time.sleep(1000)


#

#t = threading.Thread(target=threadRun)
#t.start()

x = AppCPUInfo()

jOwnProcessInfo, jChildProcessInfos = x.getData()

jk_json.prettyPrint(jOwnProcessInfo)

input()
#!/usr/bin/env python3

import os
import sys

import jk_mounting
import jk_json

mounter = jk_mounting.Mounter()

for mi in mounter.getMountInfos(isRegularDevice=True):
    print()
    print(mi)
    jk_json.prettyPrint(mi.toJSON())

print()
Example #10
0
                "pk": dictData.get("pk", False),
                "autoincr": dictData.get("autoincr", False)
            }
            retTable["columns"].append(col)
        else:
            raise jk_tokenizingparsing.ParserErrorException(
                ts.location, "P0002: Syntax error", "parse-5",
                ts.getTextPreview(20))

        m = TP("dbc").match(ts)
        if m:
            return retTable

        m = TP("dc").match(ts)
        if m:
            continue

        raise jk_tokenizingparsing.ParserErrorException(
            ts.location, "P0001: Syntax error", "parse-4",
            ts.getTextPreview(20))


#

try:
    ts = jk_tokenizingparsing.TokenStream(TOKENS)
    parsingReslt = parse(ts)
    jk_json.prettyPrint(parsingReslt)
except jk_tokenizingparsing.ParserErrorException as e:
    e.print()