parser.py 713 B

1234567891011121314151617181920212223242526272829303132
  1. import json
  2. import config as cfg
  3. from Utils import *
  4. LenFunc = cfg.LenFunc
  5. class Parser:
  6. def __init__(self):
  7. gBackPrint("parser ", "created")
  8. def toJSON(self, data):
  9. return json.loads(data)
  10. def toSTRING(self, data):
  11. return json.dumps(data)
  12. def toSEND(self, data):
  13. j = json.dumps(data)
  14. l = LenFunc - len(str(len(j)))
  15. return "00000"[0:l] + str(len(j)) + j
  16. def add(self, data, k, v):
  17. try:
  18. data[k] = v
  19. return data
  20. except Exception as e:
  21. rBackPrint("An exception occurred add", e)
  22. def parser(self, data, addr, id):
  23. data = self.toJSON(data)
  24. gPrint("Simple parser", data)