userParser.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from connection.parser import Parser
  2. class UserParser(Parser):
  3. def __init__(self,user):
  4. self.user = user
  5. print("createt User Parser")
  6. def parser(self,data,addr,Connection):
  7. try:
  8. if data["type"] == "responseUserBroadcast":
  9. self.responseUserBroadcast(data,addr)
  10. except:
  11. print("\33[41mAn exception occurred DATA\33[0m" )
  12. # Broadcast Parser
  13. def requestOracleBroadcast(self, id):
  14. try:
  15. data = {}
  16. self.add(data,"type","requestOracleBroadcast")
  17. self.add(data,"id",id)
  18. return self.toSEND(data)
  19. except:
  20. print("\33[41mAn exception occurred requestOracleBroadcast\33[0m" )
  21. def responseUserBroadcast(self, data,addr):
  22. try:
  23. self.user.onlineOracles.append((addr[0],data["socket"]))
  24. except:
  25. print("\33[41mAn exception occurred responseUserBroadcast" )
  26. # Socket Parser
  27. def socketConnecting(self,oracleNumber):
  28. try:
  29. data = {}
  30. self.add(data,"type","socketConnecting")
  31. self.add(data,"oracle",oracleNumber)
  32. return self.toSEND(data)
  33. except:
  34. print("\33[41mAn exception occurred requestOracleBroadcast\33[0m" )
  35. # Socket Parser
  36. def oracleInitialConnector(self,server,cryptor,bearer):
  37. try:
  38. data = {}
  39. self.add(data,"type","oracleInitial")
  40. self.add(data,"server",server)
  41. self.add(data,"bearer",bearer)
  42. self.add(data,"cryptor",cryptor)
  43. return self.toSEND(data)
  44. except:
  45. print("\33[41mAn exception occurred oracleInitialConnector\33[0m" )
  46. def oracleInitialCryptor(self,connector,server):
  47. try:
  48. data = {}
  49. self.add(data,"type","oracleInitial")
  50. self.add(data,"connector",connector)
  51. self.add(data,"server",server)
  52. return self.toSEND(data)
  53. except:
  54. print("\33[41mAn exception occurred oracleInitialCryptor\33[0m" )
  55. def oracleInitialBearer(self,connector,d):
  56. try:
  57. data = {}
  58. self.add(data,"type","oracleInitial")
  59. self.add(data,"connector",connector)
  60. self.add(data,"data",d)
  61. return self.toSEND(data)
  62. except:
  63. print("\33[41mAn exception occurred oracleInitialBearer\33[0m" )