Guest User

Untitled

a guest
May 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import time, re, timeit
  2. def dataReceived(data):
  3. """Parses the data into a dict named info"""
  4. blahbuffer = ""
  5. error = 0
  6. lines = data.replace("\r", "").split("\n")
  7. lines[0] = blahbuffer + lines[0]
  8. blahbuffer = lines[-1]
  9. for line in lines[:-1] :
  10. if line != "" :
  11. try:
  12. #blah = line.split(" ")
  13. #if blah == "PING" : self.rawsend("PONG %s\n" % (blah[1]))
  14. info = {}
  15. info["raw"] = line
  16. info["words"] = line[1:].split(" ")
  17. #if info["words"][1] == "001" :
  18. #self.rawsend("MODE %s +B\n" % (self.nick))
  19. #self.pm("NickServ", "IDENTIFY %s" % (self.password))
  20. #for i in self.channels :
  21. # self.rawsend("JOIN %s \n" % (i))
  22. #if self.host in conf.connectcommands :
  23. # for command in conf.connectcommands[self.host] :
  24. # exec(command)
  25. info["whois"] = info["words"][0]
  26. info["sender"] = info["whois"].split("!")[0]
  27. except : traceback.print_exc()
  28. try :
  29. info["hostname"] = info["whois"].split("@")[1]
  30. #self.hostnames[info["sender"]] = info["hostname"]
  31. except : info["hostname"] = "Unknown"
  32. try : info["mode"] = info["words"][1]
  33. except : info["mode"] = "Unknown"
  34. try :
  35. if info["words"][2] == self.nick :
  36. info["channel"] = info["sender"]
  37. else : info["channel"] = info["words"][2].replace(":", "").lower()
  38. except : info["channel"] = "Unknown"
  39. try :
  40. if info["mode"] == "PRIVMSG" or info["mode"] == "TOPIC" :
  41. if ":" in info["words"][3] : info["message"] = " ".join(info["words"][3:])[1:]
  42. else : info["message"] = " ".join(info["words"][3:])
  43. else : info["message"] = "Unknown"
  44. except : error = 1
  45. def regexdata(data, regex) :
  46. error = 0
  47. blahbuffer = ""
  48. lines = data.replace("\r", "").split("\n")
  49. lines[0] = blahbuffer + lines[0]
  50. blahbuffer = lines[-1]
  51. for line in lines[:-1] :
  52. if line != "" :
  53. x = regex.match(line).groups()
  54. info = {"raw":line, "line":line[1:], "whois":"%s!%s@%s" % (x[0],x[1],x[2]), "sender":x[0], "ident":x[1], "hostname":x[2], "mode":x[3], "channel":x[4], "message":x[5], "words":line[1:].split(" ")}
  55. rawin = ':sonicrules1234!~sonicrule@botters/sonicrules1234 PRIVMSG ##BrokenDream :;eval info["raw"]\r\n'
  56.  
  57. regex = re.compile("\:(.*)\!(.*)\@(.*) (.*) (.*) [\:]{0,1}(.*)")
  58.  
  59. print timeit.Timer('regexdata(rawin, regex)', """rawin = ':sonicrules1234!~sonicrule@botters/sonicrules1234 PRIVMSG ##BrokenDream :;eval info["raw"]\\r\\n'\n""" + 'from __main__ import regexdata\nimport re\nregex = re.compile("\:(.*)\!(.*)\@(.*) (.*) (.*) [\:]{0,1}(.*)")').timeit(100000)
  60.  
  61. print timeit.Timer('dataReceived(rawin)',"""rawin = ':sonicrules1234!~sonicrule@botters/sonicrules1234 PRIVMSG ##BrokenDream :;eval info["raw"]\\r\\n'\n""" + 'from __main__ import dataReceived').timeit(100000)
Add Comment
Please, Sign In to add comment