parser.py 684 B

12345678910111213141516171819202122232425262728293031
  1. import json
  2. import config as cfg
  3. LenFunc = cfg.LenFunc
  4. class Parser():
  5. def __init__(self):
  6. print("parser created")
  7. def toJSON(self, data):
  8. return json.loads(data)
  9. def toSTRING(self, data):
  10. return json.dumps(data)
  11. def toSEND(self, data):
  12. j = json.dumps(data)
  13. l = LenFunc - len(str(len(j)))
  14. return "00000"[0:l]+str(len(j))+j
  15. def add(self,data,k,v):
  16. try:
  17. data[k] = v
  18. return data
  19. except:
  20. print("\33[41m\33[41mAn exception occurred add\33[0m" )
  21. def parser(self,data,addr,id):
  22. data = self.toJSON(data)
  23. print("Simple parser ->",data)